Search in sources :

Example 1 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class JnaService method attach.

@Override
public void attach() throws SQLException {
    try {
        if (isAttached()) {
            throw new SQLException("Already attached to a service");
        }
        final ServiceParameterBuffer spb = PARAMETER_CONVERTER.toServiceParameterBuffer(connection);
        final byte[] serviceName = getEncoding().encodeToCharset(connection.getAttachUrl());
        final byte[] spbArray = spb.toBytesWithType();
        synchronized (getSynchronizationObject()) {
            try {
                clientLibrary.isc_service_attach(statusVector, (short) serviceName.length, serviceName, handle, (short) spbArray.length, spbArray);
                processStatusVector();
            } catch (SQLException ex) {
                safelyDetach();
                throw ex;
            } catch (Exception ex) {
                safelyDetach();
                // TODO Replace with specific error (eg native client error)
                throw new FbExceptionBuilder().exception(ISCConstants.isc_network_error).messageParameter(connection.getAttachUrl()).cause(ex).toSQLException();
            }
            setAttached();
            afterAttachActions();
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) ServiceParameterBuffer(org.firebirdsql.gds.ServiceParameterBuffer) FBDriverNotCapableException(org.firebirdsql.jdbc.FBDriverNotCapableException) SQLException(java.sql.SQLException)

Example 2 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class ChaChaEncryptionPlugin method createCipher.

private Cipher createCipher(int mode, ChaChaIV iv, byte[] key) throws SQLException {
    try {
        Cipher chaChaCipher = Cipher.getInstance(CHA_CHA_20_CIPHER_NAME);
        SecretKeySpec chaChaKey = new SecretKeySpec(key, CHA_CHA_20_CIPHER_NAME);
        chaChaCipher.init(mode, chaChaKey, iv.toParameterSpec());
        return chaChaCipher;
    } catch (NoSuchPaddingException | NoSuchAlgorithmException e) {
        throw new FbExceptionBuilder().nonTransientException(jb_cryptAlgorithmNotAvailable).messageParameter(getEncryptionIdentifier().toString()).cause(e).toFlatSQLException();
    } catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
        throw new FbExceptionBuilder().nonTransientException(jb_cryptInvalidKey).messageParameter(getEncryptionIdentifier().toString()).cause(e).toFlatSQLException();
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 3 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class AbstractFbWireBlob method getBlobInfo.

// NOTE If we need to override some of the blob operations below in the future, consider introducing a separate
// object that is injected by the ProtocolDescriptor so that we don't need to override separately for input and output.
@Override
public byte[] getBlobInfo(final byte[] requestItems, final int bufferLength) throws SQLException {
    try {
        synchronized (getSynchronizationObject()) {
            try {
                final XdrOutputStream xdrOut = getDatabase().getXdrStreamAccess().getXdrOut();
                xdrOut.writeInt(WireProtocolConstants.op_info_blob);
                xdrOut.writeInt(getHandle());
                // incarnation
                xdrOut.writeInt(0);
                xdrOut.writeBuffer(requestItems);
                xdrOut.writeInt(bufferLength);
                xdrOut.flush();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
            try {
                // TODO: Blob warning callback or just database default?
                GenericResponse response = getDatabase().readGenericResponse(null);
                return response.getData();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
            }
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Example 4 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class V15WireOperations method readCryptKeyCallback.

@Override
protected DbCryptData readCryptKeyCallback() throws IOException, SQLException {
    final XdrInputStream xdrIn = getXdrIn();
    // p_cc_data
    final byte[] pluginData = xdrIn.readBuffer();
    // p_cc_reply
    final int replySize = xdrIn.readInt();
    try {
        return new DbCryptData(pluginData, replySize);
    } catch (RuntimeException e) {
        throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_dbCryptDataError).cause(e).toSQLException();
    }
}
Also used : XdrInputStream(org.firebirdsql.gds.impl.wire.XdrInputStream) DbCryptData(org.firebirdsql.gds.ng.dbcrypt.DbCryptData) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder)

Example 5 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class DbAttachInfo method parseLegacyConnectString.

private static DbAttachInfo parseLegacyConnectString(String connectString) throws SQLException {
    // NOTE: This method does not support IPv6 addresses enclosed in []
    String server = null;
    String fileName;
    Integer port = null;
    int sep = connectString.indexOf(':');
    if (sep == 0) {
        throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_invalidConnectionString).messageParameter(connectString).messageParameter("Path separator ':' at beginning").toFlatSQLException();
    } else if (sep == 1 && !isLikelyWindowsAbsolutePath(connectString) || sep > 1) {
        server = connectString.substring(0, sep);
        fileName = connectString.substring(sep + 1);
        int portSep = server.indexOf('/');
        if (portSep == 0 || portSep == server.length() - 1) {
            throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_invalidConnectionString).messageParameter(connectString).messageParameter("Port separator '/' at beginning or end").toFlatSQLException();
        } else if (portSep > 0) {
            String portString = server.substring(portSep + 1);
            port = parsePortNumber(connectString, portString);
            server = server.substring(0, portSep);
        }
    } else {
        fileName = connectString;
    }
    return new DbAttachInfo(server, port, fileName);
}
Also used : FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder)

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