com.mysql.cj.exceptions.ExceptionInterceptor Java Examples

The following examples show how to use com.mysql.cj.exceptions.ExceptionInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XAsyncSocketConnection.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(String hostName, int portNumber, PropertySet propSet, ExceptionInterceptor excInterceptor, Log log, int loginTimeout) {
    this.port = portNumber;
    this.host = hostName;
    this.propertySet = propSet;
    this.socketFactory = new AsyncSocketFactory(); // TODO reuse PNAME_socketFactory

    try {
        this.channel = this.socketFactory.connect(hostName, portNumber, propSet.exposeAsProperties(), loginTimeout);

    } catch (CJCommunicationsException e) {
        throw e;
    } catch (IOException | RuntimeException ex) {
        throw new CJCommunicationsException(ex);
    }
}
 
Example #2
Source File: MemorySizePropertyDefinition.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Integer parseObject(String value, ExceptionInterceptor exceptionInterceptor) {
    this.multiplier = 1;

    if (value.endsWith("k") || value.endsWith("K") || value.endsWith("kb") || value.endsWith("Kb") || value.endsWith("kB") || value.endsWith("KB")) {
        this.multiplier = 1024;
        int indexOfK = StringUtils.indexOfIgnoreCase(value, "k");
        value = value.substring(0, indexOfK);
    } else if (value.endsWith("m") || value.endsWith("M") || value.endsWith("mb") || value.endsWith("Mb") || value.endsWith("mB") || value.endsWith("MB")) {
        this.multiplier = 1024 * 1024;
        int indexOfM = StringUtils.indexOfIgnoreCase(value, "m");
        value = value.substring(0, indexOfM);
    } else if (value.endsWith("g") || value.endsWith("G") || value.endsWith("gb") || value.endsWith("Gb") || value.endsWith("gB") || value.endsWith("GB")) {
        this.multiplier = 1024 * 1024 * 1024;
        int indexOfG = StringUtils.indexOfIgnoreCase(value, "g");
        value = value.substring(0, indexOfG);
    }

    return super.parseObject(value, exceptionInterceptor);
}
 
Example #3
Source File: ModifiableMemorySizeProperty.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
void setValue(int intValue, String valueAsString, ExceptionInterceptor exceptionInterceptor) {
    if (getPropertyDefinition().isRangeBased()) {
        if ((intValue < getPropertyDefinition().getLowerBound()) || (intValue > getPropertyDefinition().getUpperBound())) {
            throw ExceptionFactory.createException(WrongArgumentException.class,
                    "The connection property '" + getPropertyDefinition().getName() + "' only accepts integer values in the range of "
                            + getPropertyDefinition().getLowerBound() + " - " + getPropertyDefinition().getUpperBound() + ", the value '"
                            + (valueAsString == null ? intValue : valueAsString) + "' exceeds this range.",
                    exceptionInterceptor);
        }
    }

    this.value = Integer.valueOf(intValue);
    this.valueAsString = valueAsString == null ? String.valueOf(intValue) : valueAsString;
    this.wasExplicitlySet = true;
    invokeListeners();
}
 
Example #4
Source File: TimeUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the 'official' Java timezone name for the given timezone
 * 
 * @param timezoneStr
 *            the 'common' timezone name
 * @param exceptionInterceptor
 *            exception interceptor
 * 
 * @return the Java timezone name for the given timezone
 */
public static String getCanonicalTimezone(String timezoneStr, ExceptionInterceptor exceptionInterceptor) {
    if (timezoneStr == null) {
        return null;
    }

    timezoneStr = timezoneStr.trim();

    // handle '+/-hh:mm' form ...
    if (timezoneStr.length() > 2) {
        if ((timezoneStr.charAt(0) == '+' || timezoneStr.charAt(0) == '-') && Character.isDigit(timezoneStr.charAt(1))) {
            return "GMT" + timezoneStr;
        }
    }

    synchronized (TimeUtil.class) {
        if (timeZoneMappings == null) {
            loadTimeZoneMappings(exceptionInterceptor);
        }
    }

    String canonicalTz;
    if ((canonicalTz = timeZoneMappings.getProperty(timezoneStr)) != null) {
        return canonicalTz;
    }

    throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
            Messages.getString("TimeUtil.UnrecognizedTimezoneId", new Object[] { timezoneStr }), exceptionInterceptor);
}
 
Example #5
Source File: TimeUtil.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads a properties file that contains all kinds of time zone mappings.
 * 
 * @param exceptionInterceptor
 *            exception interceptor
 */
private static void loadTimeZoneMappings(ExceptionInterceptor exceptionInterceptor) {
    timeZoneMappings = new Properties();
    try {
        timeZoneMappings.load(TimeUtil.class.getResourceAsStream(TIME_ZONE_MAPPINGS_RESOURCE));
    } catch (IOException e) {
        throw ExceptionFactory.createException(Messages.getString("TimeUtil.LoadTimeZoneMappingError"), exceptionInterceptor);
    }
    // bridge all Time Zone ids known by Java
    for (String tz : TimeZone.getAvailableIDs()) {
        if (!timeZoneMappings.containsKey(tz)) {
            timeZoneMappings.put(tz, tz);
        }
    }
}
 
Example #6
Source File: ModifiableIntegerProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void setValue(int intValue, String valueAsString, ExceptionInterceptor exceptionInterceptor) {
    if (getPropertyDefinition().isRangeBased()) {
        if ((intValue < getPropertyDefinition().getLowerBound()) || (intValue > getPropertyDefinition().getUpperBound())) {
            throw ExceptionFactory.createException(WrongArgumentException.class,
                    "The connection property '" + getPropertyDefinition().getName() + "' only accepts integer values in the range of "
                            + getPropertyDefinition().getLowerBound() + " - " + getPropertyDefinition().getUpperBound() + ", the value '"
                            + (valueAsString == null ? intValue : valueAsString) + "' exceeds this range.",
                    exceptionInterceptor);
        }
    }

    this.value = Integer.valueOf(intValue);
    this.wasExplicitlySet = true;
    invokeListeners();
}
 
Example #7
Source File: ModifiableLongProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
void setValue(long longValue, String valueAsString, ExceptionInterceptor exceptionInterceptor) {
    if (getPropertyDefinition().isRangeBased()) {
        if ((longValue < getPropertyDefinition().getLowerBound()) || (longValue > getPropertyDefinition().getUpperBound())) {
            throw ExceptionFactory.createException(WrongArgumentException.class,
                    "The connection property '" + getPropertyDefinition().getName() + "' only accepts long integer values in the range of "
                            + getPropertyDefinition().getLowerBound() + " - " + getPropertyDefinition().getUpperBound() + ", the value '"
                            + (valueAsString == null ? longValue : valueAsString) + "' exceeds this range.",
                    exceptionInterceptor);
        }
    }
    this.value = Long.valueOf(longValue);
    this.wasExplicitlySet = true;
    invokeListeners();
}
 
Example #8
Source File: BooleanPropertyDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean parseObject(String value, ExceptionInterceptor exceptionInterceptor) {
    try {
        return AllowableValues.valueOf(value.toUpperCase()).asBoolean();
    } catch (Exception e) {
        throw ExceptionFactory.createException(
                Messages.getString("PropertyDefinition.1",
                        new Object[] { getName(), StringUtils.stringArrayToString(getAllowableValues(), "'", "', '", "' or '", "'"), value }),
                e, exceptionInterceptor);
    }
}
 
Example #9
Source File: ExportControlled.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Configure the {@link SSLContext} based on the supplier property set.
 */
public static SSLContext getSSLContext(String clientCertificateKeyStoreUrl, String clientCertificateKeyStoreType, String clientCertificateKeyStorePassword,
        String trustCertificateKeyStoreUrl, String trustCertificateKeyStoreType, String trustCertificateKeyStorePassword, boolean verifyServerCert,
        String hostName, ExceptionInterceptor exceptionInterceptor) throws SSLParamsException {
    return getSSLContext(clientCertificateKeyStoreUrl, clientCertificateKeyStoreType, clientCertificateKeyStorePassword, trustCertificateKeyStoreUrl,
            trustCertificateKeyStoreType, trustCertificateKeyStorePassword, true, verifyServerCert, hostName, exceptionInterceptor);
}
 
Example #10
Source File: AbstractRuntimeProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void initializeFrom(Reference ref, ExceptionInterceptor exceptionInterceptor) {
    RefAddr refAddr = ref.get(getPropertyDefinition().getName());

    if (refAddr != null) {
        String refContentAsString = (String) refAddr.getContent();

        initializeFrom(refContentAsString, exceptionInterceptor);
    }
}
 
Example #11
Source File: EscapeProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static void processTimestampToken(TimeZone tz, StringBuilder newSql, String token, boolean serverSupportsFractionalSecond,
        ExceptionInterceptor exceptionInterceptor) throws SQLException {
    int startPos = token.indexOf('\'') + 1;
    int endPos = token.lastIndexOf('\''); // no }

    if ((startPos == -1) || (endPos == -1)) {
        newSql.append(token); // it's just part of the query, push possible syntax errors onto server's shoulders
    } else {

        String argument = token.substring(startPos, endPos);

        try {
            Timestamp ts = Timestamp.valueOf(argument);
            SimpleDateFormat tsdf = new SimpleDateFormat("''yyyy-MM-dd HH:mm:ss", Locale.US);

            tsdf.setTimeZone(tz);

            newSql.append(tsdf.format(ts));

            if (serverSupportsFractionalSecond && ts.getNanos() > 0) {
                newSql.append('.');
                newSql.append(TimeUtil.formatNanos(ts.getNanos(), true));
            }

            newSql.append('\'');
        } catch (IllegalArgumentException illegalArgumentException) {
            SQLException sqlEx = SQLError.createSQLException(Messages.getString("EscapeProcessor.2", new Object[] { argument }),
                    MysqlErrorNumbers.SQL_STATE_SYNTAX_ERROR, exceptionInterceptor);
            sqlEx.initCause(illegalArgumentException);

            throw sqlEx;
        }
    }
}
 
Example #12
Source File: TextBufferRow.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public TextBufferRow(NativePacketPayload buf, ColumnDefinition cd, ExceptionInterceptor exceptionInterceptor, ValueDecoder valueDecoder) {
    super(exceptionInterceptor);

    this.rowFromServer = buf;
    this.homePosition = this.rowFromServer.getPosition();
    this.valueDecoder = valueDecoder;

    if (cd.getFields() != null) {
        setMetadata(cd);
    }
}
 
Example #13
Source File: Util.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static Object getInstance(String className, Class<?>[] argTypes, Object[] args, ExceptionInterceptor exceptionInterceptor, String errorMessage) {

        try {
            return handleNewInstance(Class.forName(className).getConstructor(argTypes), args, exceptionInterceptor);
        } catch (SecurityException | NoSuchMethodException | ClassNotFoundException e) {
            throw ExceptionFactory.createException(WrongArgumentException.class, errorMessage, e, exceptionInterceptor);
        }
    }
 
Example #14
Source File: ResultSetMetaData.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize for a result with a tuple set and a field descriptor set
 * 
 * @param fields
 *            the array of field descriptors
 */
public ResultSetMetaData(Session session, Field[] fields, boolean useOldAliasBehavior, boolean treatYearAsDate, ExceptionInterceptor exceptionInterceptor) {
    this.session = session;
    this.fields = fields;
    this.useOldAliasBehavior = useOldAliasBehavior;
    this.treatYearAsDate = treatYearAsDate;
    this.exceptionInterceptor = exceptionInterceptor;
}
 
Example #15
Source File: SQLError.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static SQLException createSQLException(String message, String sqlState, Throwable cause, ExceptionInterceptor interceptor) {
    SQLException sqlEx = createSQLException(message, sqlState, null);

    if (sqlEx.getCause() == null) {
        if (cause != null) {
            try {
                sqlEx.initCause(cause);
            } catch (Throwable t) {
                // we're not going to muck with that here, since it's an error condition anyway!
            }
        }
    }
    // Run through the exception interceptor after setting the init cause.
    return runThroughExceptionInterceptor(interceptor, sqlEx);
}
 
Example #16
Source File: MysqlSavepoint.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a named savepoint
 * 
 * @param name
 *            the name of the savepoint.
 * 
 * @throws SQLException
 *             if name == null or is empty.
 */
MysqlSavepoint(String name, ExceptionInterceptor exceptionInterceptor) throws SQLException {
    if (name == null || name.length() == 0) {
        throw SQLError.createSQLException(Messages.getString("MysqlSavepoint.0"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
    }

    this.savepointName = name;

    this.exceptionInterceptor = exceptionInterceptor;
}
 
Example #17
Source File: SQLError.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static SQLException createCommunicationsException(JdbcConnection conn, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs,
        Exception underlyingException, ExceptionInterceptor interceptor) {

    SQLException exToReturn = new CommunicationsException(conn, lastPacketSentTimeMs, lastPacketReceivedTimeMs, underlyingException);

    if (underlyingException != null) {
        try {
            exToReturn.initCause(underlyingException);
        } catch (Throwable t) {
            // we're not going to muck with that here, since it's an error condition anyway!
        }
    }

    return runThroughExceptionInterceptor(interceptor, exToReturn);
}
 
Example #18
Source File: LongPropertyDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Long parseObject(String value, ExceptionInterceptor exceptionInterceptor) {
    try {
        // Parse decimals, too
        return Double.valueOf(value).longValue();

    } catch (NumberFormatException nfe) {
        throw ExceptionFactory.createException(WrongArgumentException.class, "The connection property '" + getName()
                + "' only accepts long integer values. The value '" + value + "' can not be converted to a long integer.", exceptionInterceptor);
    }
}
 
Example #19
Source File: SQLError.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Run exception through an ExceptionInterceptor chain.
 * 
 * @param exInterceptor
 * @param sqlEx
 * @param conn
 * @return
 */
private static SQLException runThroughExceptionInterceptor(ExceptionInterceptor exInterceptor, SQLException sqlEx) {
    if (exInterceptor != null) {
        SQLException interceptedEx = (SQLException) exInterceptor.interceptException(sqlEx);

        if (interceptedEx != null) {
            return interceptedEx;
        }
    }
    return sqlEx;
}
 
Example #20
Source File: ServerPreparedStatement.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static SQLException appendMessageToException(SQLException sqlEx, String messageToAppend, ExceptionInterceptor interceptor) {
    String sqlState = sqlEx.getSQLState();
    int vendorErrorCode = sqlEx.getErrorCode();

    SQLException sqlExceptionWithNewMessage = SQLError.createSQLException(sqlEx.getMessage() + messageToAppend, sqlState, vendorErrorCode, interceptor);
    sqlExceptionWithNewMessage.setStackTrace(sqlEx.getStackTrace());

    return sqlExceptionWithNewMessage;
}
 
Example #21
Source File: EscapeProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static void processTimeToken(StringBuilder newSql, String token, boolean serverSupportsFractionalSecond, ExceptionInterceptor exceptionInterceptor)
        throws SQLException {
    int startPos = token.indexOf('\'') + 1;
    int endPos = token.lastIndexOf('\''); // no }

    if ((startPos == -1) || (endPos == -1)) {
        newSql.append(token); // it's just part of the query, push possible syntax errors onto server's shoulders
    } else {

        String argument = token.substring(startPos, endPos);

        try {
            StringTokenizer st = new StringTokenizer(argument, " :.");
            String hour = st.nextToken();
            String minute = st.nextToken();
            String second = st.nextToken();

            String fractionalSecond = "";

            if (serverSupportsFractionalSecond && st.hasMoreTokens()) {
                fractionalSecond = "." + st.nextToken();
            }

            newSql.append("'");
            newSql.append(hour);
            newSql.append(":");
            newSql.append(minute);
            newSql.append(":");
            newSql.append(second);
            if (serverSupportsFractionalSecond) {
                newSql.append(fractionalSecond);
            }
            newSql.append("'");
        } catch (java.util.NoSuchElementException e) {
            throw SQLError.createSQLException(Messages.getString("EscapeProcessor.3", new Object[] { argument }), MysqlErrorNumbers.SQL_STATE_SYNTAX_ERROR,
                    exceptionInterceptor);
        }
    }
}
 
Example #22
Source File: EnumPropertyDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T parseObject(String value, ExceptionInterceptor exceptionInterceptor) {
    try {
        return Enum.valueOf(this.enumType, value.toUpperCase());
    } catch (Exception e) {
        throw ExceptionFactory.createException(
                Messages.getString("PropertyDefinition.1",
                        new Object[] { getName(), StringUtils.stringArrayToString(getAllowableValues(), "'", "', '", "' or '", "'"), value }),
                e, exceptionInterceptor);
    }
}
 
Example #23
Source File: ModifiableIntegerProperty.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void initializeFrom(String extractedValue, ExceptionInterceptor exceptionInterceptor) {
    super.initializeFrom(extractedValue, exceptionInterceptor);
    this.initialValue = this.value;
}
 
Example #24
Source File: AbstractRuntimeProperty.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected void initializeFrom(String extractedValue, ExceptionInterceptor exceptionInterceptor) {
    if (extractedValue != null) {
        setFromString(extractedValue, exceptionInterceptor);
    }
}
 
Example #25
Source File: MysqlParameterMetadata.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
MysqlParameterMetadata(Session session, Field[] fieldInfo, int parameterCount, ExceptionInterceptor exceptionInterceptor) {
    this.metadata = new ResultSetMetaData(session, fieldInfo, false, true, exceptionInterceptor);

    this.parameterCount = parameterCount;
    this.exceptionInterceptor = exceptionInterceptor;
}
 
Example #26
Source File: ModifiableMemorySizeProperty.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setValue(Integer value, ExceptionInterceptor exceptionInterceptor) {
    setValue(value, null, exceptionInterceptor);
}
 
Example #27
Source File: NClob.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public NClob(String charDataInit, ExceptionInterceptor exceptionInterceptor) {
    super(charDataInit, exceptionInterceptor);
}
 
Example #28
Source File: ModifiableStringProperty.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setValue(String value, ExceptionInterceptor exceptionInterceptor) {
    setFromString(value, exceptionInterceptor);
    invokeListeners();
}
 
Example #29
Source File: AbstractRuntimeProperty.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void initializeFrom(Properties extractFrom, ExceptionInterceptor exceptionInterceptor) {
    String extractedValue = extractFrom.getProperty(getPropertyDefinition().getName());
    extractFrom.remove(getPropertyDefinition().getName());
    initializeFrom(extractedValue, exceptionInterceptor);
}
 
Example #30
Source File: XAsyncSocketConnection.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ExceptionInterceptor getExceptionInterceptor() {
    // TODO not supported ?
    throw ExceptionFactory.createException(CJOperationNotSupportedException.class, "Not supported");
}