com.mysql.cj.exceptions.NumberOutOfRange Java Examples

The following examples show how to use com.mysql.cj.exceptions.NumberOutOfRange. 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: IntegerBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromBigInteger(BigInteger i) {
    if (i.compareTo(BigInteger.valueOf(this.min)) < 0 || i.compareTo(BigInteger.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { i, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigInteger(i);
}
 
Example #2
Source File: MysqlTextValueDecoderTest.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testIntValues() {
    ValueFactory<String> vf = new StringValueFactory();
    assertEquals(String.valueOf(Integer.MIN_VALUE), this.valueDecoder.decodeInt4(String.valueOf(Integer.MIN_VALUE).getBytes(), 0, 11, vf));
    assertEquals(String.valueOf(Integer.MAX_VALUE), this.valueDecoder.decodeInt4(String.valueOf(Integer.MAX_VALUE).getBytes(), 0, 10, vf));

    assertEquals(String.valueOf(Integer.MAX_VALUE), this.valueDecoder.decodeUInt4(String.valueOf(Integer.MAX_VALUE).getBytes(), 0, 10, vf));
    assertEquals("2147483648",
            this.valueDecoder.decodeUInt4(BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.valueOf(1)).toString().getBytes(), 0, 10, vf));
    try {
        this.valueDecoder.decodeInt4(BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.valueOf(1)).toString().getBytes(), 0, 10, vf);
        fail("Exception should be thrown for decodeInt4(Integer.MAX_VALUE + 1)");
    } catch (NumberOutOfRange ex) {
        // expected
    }

    byte[] uint8LessThanMaxLong = "8223372036854775807".getBytes();
    ValueFactory<String> fromLongOnly = new DefaultValueFactory<String>() {
        @Override
        public String createFromLong(long l) {
            return Long.valueOf(l).toString();
        }

        public String getTargetTypeName() {
            return null;
        }
    };
    assertEquals("8223372036854775807", this.valueDecoder.decodeUInt8(uint8LessThanMaxLong, 0, uint8LessThanMaxLong.length, fromLongOnly));
    byte[] uint8MoreThanMaxLong1 = "9223372036854775807".getBytes();
    byte[] uint8MoreThanMaxLong2 = "18223372036854775807".getBytes();
    assertEquals("9223372036854775807", this.valueDecoder.decodeUInt8(uint8MoreThanMaxLong1, 0, uint8MoreThanMaxLong1.length, vf));
    assertEquals("18223372036854775807", this.valueDecoder.decodeUInt8(uint8MoreThanMaxLong2, 0, uint8MoreThanMaxLong2.length, vf));
}
 
Example #3
Source File: IntegerBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromBigDecimal(BigDecimal d) {
    if (d.compareTo(BigDecimal.valueOf(this.min)) < 0 || d.compareTo(BigDecimal.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigDecimal(d);
}
 
Example #4
Source File: IntegerBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromDouble(double d) {
    if (d < this.min || d > this.max) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromDouble(d);
}
 
Example #5
Source File: MySQLJDBCReflections.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void registerExceptionsForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJCommunicationsException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, CJConnectionFeatureNotAvailableException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJOperationNotSupportedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJTimeoutException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJPacketTooBigException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, AssertionFailedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJOperationNotSupportedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ClosedOnExpiredPasswordException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ConnectionIsClosedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataConversionException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataReadException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataTruncationException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DeadlockTimeoutRollbackMarker.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, FeatureNotAvailableException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, InvalidConnectionAttributeException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, NumberOutOfRange.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, OperationCancelledException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, PasswordExpiredException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, PropertyNotModifiableException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, RSAException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, SSLParamsException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StatementIsClosedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StreamingNotifiable.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, UnableToConnectException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, UnsupportedConnectionStringException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, WrongArgumentException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.mysql.cj.jdbc.MysqlXAException"));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, StandardLoadBalanceExceptionChecker.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, NdbLoadBalanceExceptionChecker.class.getName()));
}
 
Example #6
Source File: IntegerBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromLong(long l) {
    if (l < this.min || l > this.max) {
        throw new NumberOutOfRange(
                Messages.getString("ResultSet.NumberOutOfRange", new Object[] { Long.valueOf(l).toString(), this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromLong(l);
}
 
Example #7
Source File: FloatingPointBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromBigDecimal(BigDecimal d) {
    if (d.compareTo(BigDecimal.valueOf(this.min)) < 0 || d.compareTo(BigDecimal.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigDecimal(d);
}
 
Example #8
Source File: FloatingPointBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromDouble(double d) {
    if (d < this.min || d > this.max) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromDouble(d);
}
 
Example #9
Source File: FloatingPointBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromBigInteger(BigInteger i) {
    if (new BigDecimal(i).compareTo(BigDecimal.valueOf(this.min)) < 0 || new BigDecimal(i).compareTo(BigDecimal.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { i, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigInteger(i);
}
 
Example #10
Source File: FloatingPointBoundsEnforcer.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public T createFromLong(long l) {
    if (l < this.min || l > this.max) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { l, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromLong(l);
}
 
Example #11
Source File: StringUtils.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
public static int getInt(byte[] buf, int offset, int endpos) throws NumberFormatException {
    long l = getLong(buf, offset, endpos);
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
        throw new NumberOutOfRange(Messages.getString("StringUtils.badIntFormat", new Object[] { StringUtils.toString(buf, offset, endpos - offset) }));
    }
    return (int) l;
}
 
Example #12
Source File: IntegerBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromDouble(double d) {
    if (d < this.min || d > this.max) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromDouble(d);
}
 
Example #13
Source File: IntegerBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromBigInteger(BigInteger i) {
    if (i.compareTo(BigInteger.valueOf(this.min)) < 0 || i.compareTo(BigInteger.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { i, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigInteger(i);
}
 
Example #14
Source File: IntegerBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromLong(long l) {
    if (l < this.min || l > this.max) {
        throw new NumberOutOfRange(
                Messages.getString("ResultSet.NumberOutOfRange", new Object[] { Long.valueOf(l).toString(), this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromLong(l);
}
 
Example #15
Source File: FloatingPointBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromBigDecimal(BigDecimal d) {
    if (d.compareTo(BigDecimal.valueOf(this.min)) < 0 || d.compareTo(BigDecimal.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigDecimal(d);
}
 
Example #16
Source File: FloatingPointBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromDouble(double d) {
    if (d < this.min || d > this.max) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromDouble(d);
}
 
Example #17
Source File: FloatingPointBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromBigInteger(BigInteger i) {
    if (new BigDecimal(i).compareTo(BigDecimal.valueOf(this.min)) < 0 || new BigDecimal(i).compareTo(BigDecimal.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { i, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigInteger(i);
}
 
Example #18
Source File: FloatingPointBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromLong(long l) {
    if (l < this.min || l > this.max) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { l, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromLong(l);
}
 
Example #19
Source File: StringUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static int getInt(byte[] buf, int offset, int endpos) throws NumberFormatException {
    long l = getLong(buf, offset, endpos);
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
        throw new NumberOutOfRange(Messages.getString("StringUtils.badIntFormat", new Object[] { StringUtils.toString(buf, offset, endpos - offset) }));
    }
    return (int) l;
}
 
Example #20
Source File: IntegerBoundsEnforcer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T createFromBigDecimal(BigDecimal d) {
    if (d.compareTo(BigDecimal.valueOf(this.min)) < 0 || d.compareTo(BigDecimal.valueOf(this.max)) > 0) {
        throw new NumberOutOfRange(Messages.getString("ResultSet.NumberOutOfRange", new Object[] { d, this.targetVf.getTargetTypeName() }));
    }
    return this.targetVf.createFromBigDecimal(d);
}
 
Example #21
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMaxBoundsLong() {
    this.enforcing100Vf.createFromLong(101);
}
 
Example #22
Source File: IntegerBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMaxBoundsDouble() {
    this.enforcing100Vf.createFromDouble(100.5);
}
 
Example #23
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMaxBoundsBigInteger() {
    this.enforcing100Vf.createFromBigInteger(BigInteger.valueOf(101));
}
 
Example #24
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMaxBoundsDouble() {
    this.enforcing100Vf.createFromDouble(100.5);
}
 
Example #25
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMaxBoundsBigDecimal() {
    this.enforcing100Vf.createFromBigDecimal(BigDecimal.valueOf(101));
}
 
Example #26
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMinBoundsLong() {
    this.enforcing100Vf.createFromLong(-101);
}
 
Example #27
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMinBoundsBigInteger() {
    this.enforcing100Vf.createFromBigInteger(BigInteger.valueOf(-101));
}
 
Example #28
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMinBoundsDouble() {
    this.enforcing100Vf.createFromDouble(-100.5);
}
 
Example #29
Source File: FloatingPointBoundsEnforcerTest.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = NumberOutOfRange.class)
public void testOutsideMinBoundsBigDecimal() {
    this.enforcing100Vf.createFromBigDecimal(BigDecimal.valueOf(-101));
}
 
Example #30
Source File: SQLExceptionsMapping.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static SQLException translateException(Throwable ex, ExceptionInterceptor interceptor) {
    if (ex instanceof SQLException) {
        return (SQLException) ex;

    } else if (ex.getCause() != null && ex.getCause() instanceof SQLException) {
        return (SQLException) ex.getCause();

    } else if (ex instanceof CJCommunicationsException) {
        return SQLError.createCommunicationsException(ex.getMessage(), ex, interceptor);

    } else if (ex instanceof CJConnectionFeatureNotAvailableException) {
        return new ConnectionFeatureNotAvailableException(ex.getMessage(), ex);

    } else if (ex instanceof SSLParamsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_BAD_SSL_PARAMS, 0, false, ex, interceptor);

    } else if (ex instanceof ConnectionIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN, ex, interceptor);

    } else if (ex instanceof InvalidConnectionAttributeException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, ex, interceptor);

    } else if (ex instanceof UnableToConnectException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, ex, interceptor);

    } else if (ex instanceof StatementIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof WrongArgumentException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof StringIndexOutOfBoundsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof NumberOutOfRange) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE, ex, interceptor);

    } else if (ex instanceof DataConversionException) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST, ex, interceptor);

    } else if (ex instanceof DataReadException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof DataTruncationException) {
        return new MysqlDataTruncation(((DataTruncationException) ex).getMessage(), ((DataTruncationException) ex).getIndex(),
                ((DataTruncationException) ex).isParameter(), ((DataTruncationException) ex).isRead(), ((DataTruncationException) ex).getDataSize(),
                ((DataTruncationException) ex).getTransferSize(), ((DataTruncationException) ex).getVendorCode());

    } else if (ex instanceof CJPacketTooBigException) {
        return new PacketTooBigException(ex.getMessage());

    } else if (ex instanceof OperationCancelledException) {
        return new MySQLStatementCancelledException(ex.getMessage());

    } else if (ex instanceof CJTimeoutException) {
        return new MySQLTimeoutException(ex.getMessage());

    } else if (ex instanceof CJOperationNotSupportedException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof UnsupportedOperationException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof CJException) {
        return SQLError.createSQLException(ex.getMessage(), ((CJException) ex).getSQLState(), ((CJException) ex).getVendorCode(),
                ((CJException) ex).isTransient(), interceptor);

    } else {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, ex, interceptor);
    }
}