Search in sources :

Example 41 with FbExceptionBuilder

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

the class V10InputBlob method open.

// TODO Need blob specific warning callback?
@Override
public void open() throws SQLException {
    try {
        synchronized (getSynchronizationObject()) {
            checkDatabaseAttached();
            checkTransactionActive();
            checkBlobClosed();
            final FbWireDatabase database = getDatabase();
            try {
                final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
                final BlobParameterBuffer blobParameterBuffer = getBlobParameterBuffer();
                if (blobParameterBuffer == null) {
                    xdrOut.writeInt(op_open_blob);
                } else {
                    xdrOut.writeInt(op_open_blob2);
                    xdrOut.writeTyped(blobParameterBuffer);
                }
                xdrOut.writeInt(getTransaction().getHandle());
                xdrOut.writeLong(getBlobId());
                xdrOut.flush();
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
            }
            try {
                final GenericResponse genericResponse = database.readGenericResponse(null);
                setHandle(genericResponse.getObjectHandle());
                setOpen(true);
                resetEof();
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
            }
        // TODO Request information on the blob?
        }
    } 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) BlobParameterBuffer(org.firebirdsql.gds.BlobParameterBuffer)

Example 42 with FbExceptionBuilder

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

the class V10InputBlob method seek.

@Override
public void seek(int offset, SeekMode seekMode) throws SQLException {
    try {
        synchronized (getSynchronizationObject()) {
            checkDatabaseAttached();
            checkTransactionActive();
            final FbWireDatabase database = getDatabase();
            try {
                final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
                xdrOut.writeInt(op_seek_blob);
                xdrOut.writeInt(getHandle());
                xdrOut.writeInt(seekMode.getSeekModeId());
                xdrOut.writeInt(offset);
                xdrOut.flush();
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
            }
            try {
                database.readResponse(null);
            // object handle in response is the current position in the blob (see .NET provider source)
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).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 43 with FbExceptionBuilder

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

the class V10OutputBlob method open.

// TODO Need blob specific warning callback?
@Override
public void open() throws SQLException {
    try {
        synchronized (getSynchronizationObject()) {
            checkDatabaseAttached();
            checkTransactionActive();
            checkBlobClosed();
            if (getBlobId() != FbBlob.NO_BLOB_ID) {
                throw new FbExceptionBuilder().nonTransientException(ISCConstants.isc_segstr_no_op).toSQLException();
            }
            final FbWireDatabase database = getDatabase();
            try {
                final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
                final BlobParameterBuffer blobParameterBuffer = getBlobParameterBuffer();
                if (blobParameterBuffer == null) {
                    xdrOut.writeInt(op_create_blob);
                } else {
                    xdrOut.writeInt(op_create_blob2);
                    xdrOut.writeTyped(blobParameterBuffer);
                }
                xdrOut.writeInt(getTransaction().getHandle());
                xdrOut.writeLong(FbBlob.NO_BLOB_ID);
                xdrOut.flush();
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
            }
            try {
                final GenericResponse genericResponse = database.readGenericResponse(null);
                setHandle(genericResponse.getObjectHandle());
                setBlobId(genericResponse.getBlobId());
                setOpen(true);
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
            }
        // TODO Request information on the blob?
        }
    } 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) BlobParameterBuffer(org.firebirdsql.gds.BlobParameterBuffer)

Example 44 with FbExceptionBuilder

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

the class V10Service method internalDetach.

@Override
protected void internalDetach() throws SQLException {
    synchronized (getSynchronizationObject()) {
        try {
            try {
                final XdrOutputStream xdrOut = getXdrOut();
                if (isAttached()) {
                    xdrOut.writeInt(op_service_detach);
                    xdrOut.writeInt(getHandle());
                }
                xdrOut.writeInt(op_disconnect);
                xdrOut.flush();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
            if (isAttached()) {
                try {
                    // Consume op_detach response
                    wireOperations.readResponse(null);
                } catch (IOException ex) {
                    throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
                }
            }
            try {
                closeConnection();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
        } catch (SQLException ex) {
            try {
                closeConnection();
            } catch (Exception ex2) {
            // ignore
            }
            throw ex;
        } finally {
            setDetached();
        }
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 45 with FbExceptionBuilder

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

the class V10Service method getServiceInfo.

@Override
public byte[] getServiceInfo(ServiceParameterBuffer serviceParameterBuffer, ServiceRequestBuffer serviceRequestBuffer, int maxBufferLength) throws SQLException {
    try {
        checkAttached();
        synchronized (getSynchronizationObject()) {
            try {
                final XdrOutputStream xdrOut = getXdrOut();
                xdrOut.writeInt(op_service_info);
                xdrOut.writeInt(getHandle());
                // incarnation
                xdrOut.writeInt(0);
                xdrOut.writeBuffer(serviceParameterBuffer != null ? serviceParameterBuffer.toBytes() : null);
                xdrOut.writeBuffer(serviceRequestBuffer.toBytes());
                xdrOut.writeInt(maxBufferLength);
                xdrOut.flush();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
            try {
                GenericResponse genericResponse = readGenericResponse(null);
                return genericResponse.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)

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