use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.
the class SQLDataExceptionTests method test3.
/**
* Create SQLDataException with message, and SQLState
*/
@Test
public void test3() {
SQLDataException ex = new SQLDataException(reason, state);
assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && ex.getCause() == null && ex.getErrorCode() == 0);
}
use of java.sql.SQLDataException in project jdk8u_jdk by JetBrains.
the class SQLDataExceptionTests method test9.
/**
* Create SQLDataException with Throwable
*/
@Test
public void test9() {
SQLDataException ex = new SQLDataException(t);
assertTrue(ex.getMessage().equals(cause) && ex.getSQLState() == null && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
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 {
if (size != null) {
final int sizeInt;
try {
sizeInt = Integer.parseInt(size);
} catch (final NumberFormatException nfe) {
throw new SQLDataException("Size field could not be converted to integer", nfe);
}
// Make sure if the type is unsigned it's created correctly
final String baseType;
final String afterMagnitude;
final int unsignedIndex = StringUtils.indexOfIgnoreCase(type, UNSIGNED);
if (unsignedIndex != -1) {
baseType = StringUtils.trim(type.substring(0, unsignedIndex));
afterMagnitude = type.substring(unsignedIndex);
} else {
baseType = type;
afterMagnitude = null;
}
if (precision != null) {
final int precisionInt;
try {
precisionInt = Integer.parseInt(precision);
} catch (final NumberFormatException nfe) {
throw new SQLDataException("Precision field could not be converted to integer", nfe);
}
return baseType + LEFT_PAREN + sizeInt + COMMA_SPACE + precisionInt + RIGHT_PAREN + (afterMagnitude != null ? SPACE + afterMagnitude : EMPTY);
} else {
return baseType + LEFT_PAREN + sizeInt + RIGHT_PAREN + (afterMagnitude != null ? SPACE + afterMagnitude : EMPTY);
}
} else {
return type;
}
}
Aggregations