Search in sources :

Example 1 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestV10Database method testBasicAttach.

/**
 * Tests if attaching to an existing database works.
 */
@Test
public void testBasicAttach() throws Exception {
    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();
            System.out.println(db.getHandle());
            assertTrue("Expected isAttached() to return true", db.isAttached());
            assertNotNull("Expected version string to be not null", db.getServerVersion());
            assertNotEquals("Expected version should not be invalid", GDSServerVersion.INVALID_VERSION, db.getServerVersion());
        }
    } 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 2 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestV10Database method testBasicDetach.

@Test
public void testBasicDetach() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        try {
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            db.close();
            assertFalse("Expected database not attached", db.isAttached());
            assertFalse("Expected connection closed", gdsConnection.isConnected());
        } finally {
            safelyClose(db);
        }
    } 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 3 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestV10Database method testCancelOperation_abortSupported.

@Test
public void testCancelOperation_abortSupported() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        try {
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            assumeTrue("expected database attached", db.isAttached());
            db.cancelOperation(ISCConstants.fb_cancel_abort);
            assertFalse("Expected database not attached after abort", db.isAttached());
            assertFalse("Expected connection closed after abort", gdsConnection.isConnected());
        } finally {
            safelyClose(db);
        }
    } 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 4 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestV10Database method testDrop_NotAttached.

@Test
public void testDrop_NotAttached() throws Exception {
    expectedException.expect(SQLException.class);
    expectedException.expectMessage(startsWith("The connection is not attached to a database"));
    expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_CONNECTION_ERROR));
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
        db.dropDatabase();
    } 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 5 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestV10Database method testDetach_openTransactions.

@Test
public void testDetach_openTransactions() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        try (FbWireDatabase db = gdsConnection.identify()) {
            FbTransaction transaction = null;
            try {
                SimpleDatabaseListener callback = new SimpleDatabaseListener();
                db.addDatabaseListener(callback);
                assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
                db.attach();
                // Starting an active transaction
                transaction = getTransaction(db);
                expectedException.expect(allOf(errorCodeEquals(ISCConstants.isc_open_trans), message(startsWith(getFbMessage(ISCConstants.isc_open_trans, "1")))));
                // Triggers exception
                db.close();
            } finally {
                if (transaction != null && transaction.getState() == TransactionState.ACTIVE) {
                    transaction.commit();
                }
            }
        }
    } 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)

Aggregations

FBManager (org.firebirdsql.management.FBManager)26 Test (org.junit.Test)17 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)9 WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)9 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)8 Connection (java.sql.Connection)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 FBTestProperties (org.firebirdsql.common.FBTestProperties)2 ServiceRequestBuffer (org.firebirdsql.gds.ServiceRequestBuffer)2 FbConnectionProperties (org.firebirdsql.gds.ng.FbConnectionProperties)2 FBDriver (org.firebirdsql.jdbc.FBDriver)2 GDSType (org.firebirdsql.gds.impl.GDSType)1 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)1 AbstractFbWireService (org.firebirdsql.gds.ng.wire.AbstractFbWireService)1 FbWireService (org.firebirdsql.gds.ng.wire.FbWireService)1 WireServiceConnection (org.firebirdsql.gds.ng.wire.WireServiceConnection)1