Search in sources :

Example 6 with FbTransaction

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

the class TestFBMaintenanceManager method createLimboTransaction.

private void createLimboTransaction(int count) throws Exception {
    try (FBConnection conn = (FBConnection) getConnectionViaDriverManager()) {
        final FbDatabase fbDatabase = conn.getFbDatabase();
        for (int i = 0; i < count; i++) {
            TransactionParameterBuffer tpBuf = conn.createTransactionParameterBuffer();
            FbTransaction transaction = fbDatabase.startTransaction(tpBuf);
            transaction.prepare(null);
        }
    }
}
Also used : FBConnection(org.firebirdsql.jdbc.FBConnection) TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) FbTransaction(org.firebirdsql.gds.ng.FbTransaction)

Example 7 with FbTransaction

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

the class TestV10OutputBlob method testReopen.

/**
 * Test reopen is not allowed.
 */
@Test
public void testReopen() throws Exception {
    expectedException.expect(SQLNonTransientException.class);
    expectedException.expect(allOf(errorCodeEquals(ISCConstants.isc_segstr_no_op), fbMessageStartsWith(ISCConstants.isc_segstr_no_op)));
    final byte[] baseContent = generateBaseContent();
    final int requiredSize = 256;
    final byte[] testBytes = generateBlobContent(baseContent, requiredSize);
    try (FbWireDatabase db = createDatabaseConnection()) {
        final FbTransaction transaction = getTransaction(db);
        try {
            final FbBlob blob = db.createBlobForOutput(transaction, null);
            blob.open();
            int bytesWritten = 0;
            while (bytesWritten < testBytes.length) {
                // TODO the interface for writing blobs should be simpler
                byte[] buffer = new byte[Math.min(blob.getMaximumSegmentSize(), testBytes.length - bytesWritten)];
                System.arraycopy(testBytes, bytesWritten, buffer, 0, buffer.length);
                blob.putSegment(buffer);
                bytesWritten += buffer.length;
            }
            blob.close();
            // Reopen
            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 8 with FbTransaction

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

the class TestV10OutputBlob method testIsEof_afterClose.

/**
 * Test if blob is eof after close.
 */
@Test
public void testIsEof_afterClose() throws Exception {
    try (FbWireDatabase db = createDatabaseConnection()) {
        final FbTransaction transaction = getTransaction(db);
        try {
            FbBlob blob = db.createBlobForOutput(transaction, null);
            assumeTrue("Output blob before open should be eof", blob.isEof());
            blob.open();
            blob.close();
            assertTrue("Output blob after close should be eof", blob.isEof());
        } 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 9 with FbTransaction

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

Aggregations

FbTransaction (org.firebirdsql.gds.ng.FbTransaction)9 Test (org.junit.Test)7 FbBlob (org.firebirdsql.gds.ng.FbBlob)6 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)6 FbDatabase (org.firebirdsql.gds.ng.FbDatabase)2 FbStatement (org.firebirdsql.gds.ng.FbStatement)2 SQLException (java.sql.SQLException)1 ResourceException (javax.resource.ResourceException)1 TransactionParameterBuffer (org.firebirdsql.gds.TransactionParameterBuffer)1 GDSHelper (org.firebirdsql.gds.impl.GDSHelper)1 DatatypeCoder (org.firebirdsql.gds.ng.DatatypeCoder)1 FieldValue (org.firebirdsql.gds.ng.fields.FieldValue)1 SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)1 FBConnection (org.firebirdsql.jdbc.FBConnection)1 FBManager (org.firebirdsql.management.FBManager)1