Search in sources :

Example 26 with FbExceptionBuilder

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();
        }
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) FBDriverNotCapableException(org.firebirdsql.jdbc.FBDriverNotCapableException) SQLException(java.sql.SQLException)

Example 27 with FbExceptionBuilder

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;
    }
}
Also used : FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) ResultSet(java.sql.ResultSet)

Example 28 with FbExceptionBuilder

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());
}
Also used : SQLWarning(java.sql.SQLWarning) AbstractWireOperations(org.firebirdsql.gds.ng.wire.AbstractWireOperations) SQLException(java.sql.SQLException) GenericResponse(org.firebirdsql.gds.ng.wire.GenericResponse) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) Test(org.junit.Test)

Example 29 with FbExceptionBuilder

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);
}
Also used : SQLWarning(java.sql.SQLWarning) AbstractWireOperations(org.firebirdsql.gds.ng.wire.AbstractWireOperations) GenericResponse(org.firebirdsql.gds.ng.wire.GenericResponse) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) Test(org.junit.Test)

Example 30 with FbExceptionBuilder

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);
}
Also used : AbstractWireOperations(org.firebirdsql.gds.ng.wire.AbstractWireOperations) SQLException(java.sql.SQLException) GenericResponse(org.firebirdsql.gds.ng.wire.GenericResponse) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) Test(org.junit.Test)

Aggregations

FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)51 SQLException (java.sql.SQLException)31 IOException (java.io.IOException)27 XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)22 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)6 GenericResponse (org.firebirdsql.gds.ng.wire.GenericResponse)6 SQLNonTransientException (java.sql.SQLNonTransientException)4 AbstractWireOperations (org.firebirdsql.gds.ng.wire.AbstractWireOperations)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)3 BigInteger (java.math.BigInteger)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)2 SQLWarning (java.sql.SQLWarning)2 Cipher (javax.crypto.Cipher)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 Encoding (org.firebirdsql.encodings.Encoding)2