Search in sources :

Example 11 with FbBlob

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

the class TestV10OutputBlob method testDoubleOpen.

/**
 * Test double open is not allowed.
 */
@Test
public void testDoubleOpen() throws Exception {
    expectedException.expect(SQLNonTransientException.class);
    expectedException.expect(allOf(errorCodeEquals(ISCConstants.isc_no_segstr_close), fbMessageStartsWith(ISCConstants.isc_no_segstr_close)));
    try (FbWireDatabase db = createDatabaseConnection()) {
        final FbTransaction transaction = getTransaction(db);
        try {
            final FbBlob blob = db.createBlobForOutput(transaction, null);
            blob.open();
            blob.open();
        } finally {
            transaction.commit();
        }
    }
}
Also used : FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) FbTransaction(org.firebirdsql.gds.ng.FbTransaction) FbBlob(org.firebirdsql.gds.ng.FbBlob) Test(org.junit.Test)

Example 12 with FbBlob

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

the class FBBlobField method getBytesInternal.

public byte[] getBytesInternal() throws SQLException {
    final byte[] blobIdBuffer = getFieldData();
    if (blobIdBuffer == null)
        return null;
    final long blobId = getDatatypeCoder().decodeLong(blobIdBuffer);
    synchronized (((Synchronizable) getBlob()).getSynchronizationObject()) {
        try (FbBlob blobHandle = gdsHelper.openBlob(blobId, FBBlob.SEGMENTED)) {
            final int blobLength = (int) blobHandle.length();
            final int bufferLength = gdsHelper.getBlobBufferLength();
            final byte[] resultBuffer = new byte[blobLength];
            int offset = 0;
            while (offset < blobLength) {
                final byte[] segmentBuffer = blobHandle.getSegment(bufferLength);
                if (segmentBuffer.length == 0) {
                    // unexpected EOF
                    throw new TypeConversionException(BYTES_CONVERSION_ERROR);
                }
                System.arraycopy(segmentBuffer, 0, resultBuffer, offset, segmentBuffer.length);
                offset += segmentBuffer.length;
            }
            return resultBuffer;
        }
    }
}
Also used : Synchronizable(org.firebirdsql.jdbc.Synchronizable) FbBlob(org.firebirdsql.gds.ng.FbBlob)

Aggregations

FbBlob (org.firebirdsql.gds.ng.FbBlob)12 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)11 Test (org.junit.Test)11 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DatatypeCoder (org.firebirdsql.gds.ng.DatatypeCoder)1 FbStatement (org.firebirdsql.gds.ng.FbStatement)1 FieldValue (org.firebirdsql.gds.ng.fields.FieldValue)1 SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)1 Synchronizable (org.firebirdsql.jdbc.Synchronizable)1