Search in sources :

Example 6 with BlobParameterBuffer

use of org.firebirdsql.gds.BlobParameterBuffer 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)

Aggregations

BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)6 SQLException (java.sql.SQLException)3 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)3 IOException (java.io.IOException)2 XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)2 Test (org.junit.Test)2 RowValue (org.firebirdsql.gds.ng.fields.RowValue)1 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)1 SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)1