use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class JnaService method internalDetach.
@Override
protected void internalDetach() throws SQLException {
synchronized (getSynchronizationObject()) {
try {
clientLibrary.isc_service_detach(statusVector, handle);
processStatusVector();
} catch (SQLException ex) {
throw ex;
} catch (Exception ex) {
// TODO Replace with specific error (eg native client error)
throw new FbExceptionBuilder().exception(ISCConstants.isc_network_error).messageParameter(connection.getAttachUrl()).cause(ex).toSQLException();
} finally {
setDetached();
}
}
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class GeneratedKeysQueryBuilder method mapColumnNamesByIndex.
private Map<Integer, String> mapColumnNamesByIndex(String tableName, int[] columnIndexes, FirebirdDatabaseMetaData databaseMetaData) throws SQLException {
try (ResultSet rs = databaseMetaData.getColumns(null, null, normalizeObjectName(tableName), null)) {
if (!rs.next()) {
throw new FbExceptionBuilder().nonTransientException(JaybirdErrorCodes.jb_generatedKeysNoColumnsFound).messageParameter(tableName).toFlatSQLException();
}
Map<Integer, String> columnByIndex = new HashMap<>();
int[] sortedIndexes = columnIndexes.clone();
Arrays.sort(sortedIndexes);
do {
int columnPosition = rs.getInt(IDX_ORDINAL_POSITION);
if (Arrays.binarySearch(sortedIndexes, columnPosition) >= 0) {
columnByIndex.put(columnPosition, rs.getString(IDX_COLUMN_NAME));
}
} while (rs.next());
return columnByIndex;
}
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class TestV10WireOperations method testProcessResponseWarnings_exception.
/**
* Test if no warning is registered with the callback if the response
* contains an exception that is not a warning.
*/
@Test
public void testProcessResponseWarnings_exception() throws Exception {
AbstractWireOperations wire = createDummyWireOperations();
SQLException exception = new FbExceptionBuilder().exception(ISCConstants.isc_numeric_out_of_range).toSQLException();
GenericResponse genericResponse = new GenericResponse(-1, -1, null, exception);
wire.processResponseWarnings(genericResponse, null);
List<SQLWarning> warnings = warningCallback.getWarnings();
assertEquals("Expected no warnings to be registered", 0, warnings.size());
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class TestV10WireOperations method testProcessResponseWarnings_warning.
/**
* Test if a warning is registered with the callback if the response
* contains an exception that is a warning.
*/
@Test
public void testProcessResponseWarnings_warning() throws Exception {
AbstractWireOperations wire = createDummyWireOperations();
SQLWarning warning = new FbExceptionBuilder().warning(ISCConstants.isc_numeric_out_of_range).toSQLException(SQLWarning.class);
GenericResponse genericResponse = new GenericResponse(-1, -1, null, warning);
wire.processResponseWarnings(genericResponse, null);
List<SQLWarning> warnings = warningCallback.getWarnings();
assertEquals("Unexpected warnings registered or no warnings registered", Collections.singletonList(warning), warnings);
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class TestV10WireOperations method testProcessResponse_exception.
/**
* Test if processResponse throws the exception in the response if the
* exception is not a warning.
*/
@Test
public void testProcessResponse_exception() throws Exception {
AbstractWireOperations wire = createDummyWireOperations();
SQLException exception = new FbExceptionBuilder().exception(ISCConstants.isc_numeric_out_of_range).toSQLException();
expectedException.expect(sameInstance(exception));
GenericResponse genericResponse = new GenericResponse(-1, -1, null, exception);
wire.processResponse(genericResponse);
}
Aggregations