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;
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations