Search in sources :

Example 16 with FbWireDatabase

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

the class TestV10Database method testExecuteImmediate_createDatabase.

// TODO Investigate why this doesn't work in wire protocol, but works in native
@Ignore("Test not working")
@Test
public void testExecuteImmediate_createDatabase() throws Exception {
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
        String createDb = String.format("CREATE DATABASE '%s' USER '%s' PASSWORD '%s'", getDatabasePath(), DB_USER, DB_PASSWORD);
        db.executeImmediate(createDb, null);
        assertTrue("Expected to be attached after create database", db.isAttached());
        db.dropDatabase();
    } finally {
        new File(getDatabasePath()).delete();
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with FbWireDatabase

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

the class TestV10Database method testAttach_DoubleAttach.

@Test
public void testAttach_DoubleAttach() throws Exception {
    expectedException.expect(SQLException.class);
    expectedException.expectMessage(equalTo("Already attached to a database"));
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        try (FbWireDatabase db = gdsConnection.identify()) {
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            // Second attach should throw exception
            db.attach();
        }
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 18 with FbWireDatabase

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

the class TestV10Database method testDetach_NotAttached.

@Test
public void testDetach_NotAttached() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
        // Detach for connected but not attached should work
        db.close();
        assertFalse("Expected connection closed after detach", gdsConnection.isConnected());
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 19 with FbWireDatabase

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

the class TestV10InputBlob method testDoubleOpen.

/**
 * Tests double open 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)));
    final int testId = 1;
    final byte[] baseContent = generateBaseContent();
    final int requiredSize = 256;
    populateBlob(testId, baseContent, requiredSize);
    try (FbWireDatabase db = createDatabaseConnection()) {
        try {
            long blobId = getBlobId(testId, db);
            final FbBlob blob = db.createBlobForInput(transaction, null, blobId);
            blob.open();
            // Double open
            blob.open();
        } finally {
            if (transaction != null)
                transaction.commit();
        }
    }
}
Also used : FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) FbBlob(org.firebirdsql.gds.ng.FbBlob) Test(org.junit.Test)

Example 20 with FbWireDatabase

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

the class TestV10InputBlob method testBlobSeek_segmented.

/**
 * Tests absolute seek on a segmented blob. Expectation: fails with an exception
 */
@Test
public void testBlobSeek_segmented() throws Exception {
    final int testId = 1;
    final byte[] baseContent = generateBaseContent();
    // Use sufficiently large value so that multiple segments are used
    final int requiredSize = 4 * Short.MAX_VALUE;
    populateBlob(testId, baseContent, requiredSize);
    try (FbWireDatabase db = createDatabaseConnection()) {
        try {
            long blobId = getBlobId(testId, db);
            // NOTE: What matters is if the blob on the server is stream or segment
            final FbBlob blob = db.createBlobForInput(transaction, null, blobId);
            blob.open();
            int offset = baseContent.length / 2;
            expectedException.expect(SQLException.class);
            expectedException.expect(allOf(errorCodeEquals(ISCConstants.isc_bad_segstr_type), message(startsWith(getFbMessage(ISCConstants.isc_bad_segstr_type)))));
            blob.seek(offset, FbBlob.SeekMode.ABSOLUTE);
        } finally {
            if (transaction != null)
                transaction.commit();
        }
    }
}
Also used : FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) FbBlob(org.firebirdsql.gds.ng.FbBlob) Test(org.junit.Test)

Aggregations

FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)27 Test (org.junit.Test)23 WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)13 FbBlob (org.firebirdsql.gds.ng.FbBlob)11 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)11 FBManager (org.firebirdsql.management.FBManager)9 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 IOException (java.io.IOException)1 SQLNonTransientException (java.sql.SQLNonTransientException)1 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)1 DatatypeCoder (org.firebirdsql.gds.ng.DatatypeCoder)1 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)1 FbStatement (org.firebirdsql.gds.ng.FbStatement)1 StatementState (org.firebirdsql.gds.ng.StatementState)1 FieldValue (org.firebirdsql.gds.ng.fields.FieldValue)1 SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)1 Ignore (org.junit.Ignore)1