Search in sources :

Example 11 with SQLDataException

use of java.sql.SQLDataException in project metacat by Netflix.

the class JdbcConnectorTableService method buildSourceType.

/**
     * Rebuild a source type definition.
     *
     * @param type      The base type e.g. VARCHAR
     * @param size      The size if applicable to the {@code type}
     * @param precision The precision if applicable to the {@code type} e.g. DECIMAL's
     * @return The representation of source type e.g. INTEGER, VARCHAR(50) or DECIMAL(20, 10)
     * @throws SQLDataException When size or precision can't be parsed to integers if non null
     */
protected String buildSourceType(@Nonnull @NonNull final String type, @Nullable final String size, @Nullable final String precision) throws SQLDataException {
    Integer sizeInt;
    Integer precisionInt;
    try {
        sizeInt = size != null ? Integer.parseInt(size) : null;
        if (sizeInt != null && sizeInt < 1) {
            sizeInt = null;
        }
    } catch (final NumberFormatException nfe) {
        throw new SQLDataException("Size field could not be converted to integer", nfe);
    }
    try {
        precisionInt = precision != null ? Integer.parseInt(precision) : null;
        if (precisionInt != null && precisionInt < 1) {
            precisionInt = null;
        }
    } catch (final NumberFormatException nfe) {
        throw new SQLDataException("Precision field could not be converted to integer", nfe);
    }
    if (sizeInt != null && precisionInt != null) {
        return type + "(" + sizeInt + ", " + precisionInt + ")";
    } else if (sizeInt != null) {
        return type + "(" + sizeInt + ")";
    } else {
        return type;
    }
}
Also used : SQLDataException(java.sql.SQLDataException)

Example 12 with SQLDataException

use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.

the class SQLDataExceptionTests method test2.

/**
     * Create SQLDataException with message
     */
@Test
public void test2() {
    SQLDataException ex = new SQLDataException(reason);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0);
}
Also used : SQLDataException(java.sql.SQLDataException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 13 with SQLDataException

use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.

the class SQLDataExceptionTests method test13.

/**
     * Create SQLDataException and validate it is an instance of
     * SQLNonTransientException
     */
@Test
public void test13() {
    Exception ex = new SQLDataException();
    assertTrue(ex instanceof SQLNonTransientException);
}
Also used : SQLNonTransientException(java.sql.SQLNonTransientException) SQLDataException(java.sql.SQLDataException) SQLException(java.sql.SQLException) SQLNonTransientException(java.sql.SQLNonTransientException) SQLDataException(java.sql.SQLDataException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 14 with SQLDataException

use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.

the class SQLDataExceptionTests method test.

/**
     * Create SQLDataException and setting all objects to null
     */
@Test
public void test() {
    SQLDataException e = new SQLDataException(null, null, errorCode, null);
    assertTrue(e.getMessage() == null && e.getSQLState() == null && e.getCause() == null && e.getErrorCode() == errorCode);
}
Also used : SQLDataException(java.sql.SQLDataException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 15 with SQLDataException

use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.

the class SQLDataExceptionTests method test4.

/**
     * Create SQLDataException with message, SQLState, and error code
     */
@Test
public void test4() {
    SQLDataException ex = new SQLDataException(reason, state, errorCode);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && ex.getCause() == null && ex.getErrorCode() == errorCode);
}
Also used : SQLDataException(java.sql.SQLDataException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Aggregations

SQLDataException (java.sql.SQLDataException)18 Test (org.testng.annotations.Test)14 BaseTest (util.BaseTest)14 SQLException (java.sql.SQLException)4 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 SQLNonTransientException (java.sql.SQLNonTransientException)1 Map (java.util.Map)1 BeanPropertyRowMapper (org.springframework.jdbc.core.BeanPropertyRowMapper)1 ColumnMapRowMapper (org.springframework.jdbc.core.ColumnMapRowMapper)1 RowMapper (org.springframework.jdbc.core.RowMapper)1 RowMapperResultSetExtractor (org.springframework.jdbc.core.RowMapperResultSetExtractor)1