Java Code Examples for com.mysql.cj.exceptions.ExceptionInterceptor

The following examples show how to use com.mysql.cj.exceptions.ExceptionInterceptor. These examples are extracted from open source projects. 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 Project: lams   Source File: XAsyncSocketConnection.java    License: 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
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 3
@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 4
Source Project: lams   Source File: ExportControlled.java    License: 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 5
Source Project: lams   Source File: TextBufferRow.java    License: 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 6
Source Project: lams   Source File: ServerPreparedStatement.java    License: 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 7
Source Project: lams   Source File: SQLError.java    License: 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 8
Source Project: lams   Source File: SQLError.java    License: 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 9
Source Project: lams   Source File: LongPropertyDefinition.java    License: 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 10
Source Project: lams   Source File: SQLError.java    License: 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 11
Source Project: lams   Source File: EnumPropertyDefinition.java    License: 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 12
Source Project: lams   Source File: EscapeProcessor.java    License: 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 13
Source Project: lams   Source File: EscapeProcessor.java    License: 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 14
Source Project: lams   Source File: MysqlSavepoint.java    License: 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 15
Source Project: lams   Source File: ResultSetMetaData.java    License: 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 16
Source Project: lams   Source File: Util.java    License: 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 17
Source Project: lams   Source File: TimeUtil.java    License: 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 18
Source Project: lams   Source File: TimeUtil.java    License: 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 19
Source Project: lams   Source File: AbstractRuntimeProperty.java    License: 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 20
Source Project: lams   Source File: ModifiableLongProperty.java    License: 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 21
@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 22
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 23
Source Project: lams   Source File: XAsyncSocketConnection.java    License: 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");
}
 
Example 24
Source Project: lams   Source File: XAuthenticationProvider.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void init(Protocol<XMessage> prot, PropertySet propertySet, ExceptionInterceptor exceptionInterceptor) {
    this.protocol = (XProtocol) prot;
}
 
Example 25
Source Project: lams   Source File: XProtocol.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public ExceptionInterceptor getExceptionInterceptor() {
    throw ExceptionFactory.createException(CJOperationNotSupportedException.class, "Not supported");
}
 
Example 26
Source Project: lams   Source File: AbstractProtocol.java    License: GNU General Public License v2.0 4 votes vote down vote up
public ExceptionInterceptor getExceptionInterceptor() {
    return this.exceptionInterceptor;
}
 
Example 27
public ExceptionInterceptor getExceptionInterceptor() {
    return this.exceptionInterceptor;
}
 
Example 28
Source Project: lams   Source File: AbstractResultsetRow.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected AbstractResultsetRow(ExceptionInterceptor exceptionInterceptor) {
    this.exceptionInterceptor = exceptionInterceptor;
}
 
Example 29
@Override
public void init(Protocol<NativePacketPayload> prot, PropertySet propSet, ExceptionInterceptor excInterceptor) {
    this.protocol = prot;
    this.propertySet = propSet;
    this.exceptionInterceptor = excInterceptor;
}
 
Example 30
public ExceptionInterceptor getExceptionInterceptor() {
    return this.exceptionInterceptor;
}