Search in sources :

Example 11 with WireDatabaseConnection

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

the class TestV10Database method testBasicCreateAndDrop.

/**
 * Tests creating and subsequently dropping a database
 */
@Test
public void testBasicCreateAndDrop() throws Exception {
    IConnectionProperties connectionProperties = getConnectionInfo();
    connectionProperties.getExtraDatabaseParameters().addArgument(ISCConstants.isc_dpb_sql_dialect, 3);
    File dbFile = new File(connectionProperties.getAttachObjectName());
    try (WireDatabaseConnection gdsConnection = new WireDatabaseConnection(connectionProperties, EncodingFactory.getPlatformDefault(), getProtocolCollection())) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
        db.createDatabase();
        assertTrue("Database should be attached after create", db.isAttached());
        assertTrue("Connection should be connected after create", gdsConnection.isConnected());
        assertTrue("Expected database file to exist (NOTE: only works on localhost)", dbFile.exists() || !FBTestProperties.DB_SERVER_URL.equalsIgnoreCase("localhost"));
        db.dropDatabase();
        assertFalse(gdsConnection.isConnected());
        assertFalse(dbFile.exists());
    } finally {
        if (dbFile.exists()) {
            dbFile.delete();
        }
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) File(java.io.File) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 12 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection 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 13 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection 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 14 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection 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 15 with WireDatabaseConnection

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

the class TestV10Statement method createDatabase.

@Override
protected final FbDatabase createDatabase() throws SQLException {
    WireDatabaseConnection gdsConnection = new WireDatabaseConnection(connectionInfo, EncodingFactory.getPlatformDefault(), getProtocolCollection());
    gdsConnection.socketConnect();
    return gdsConnection.identify();
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection)

Aggregations

WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)15 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)13 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)11 Test (org.junit.Test)10 FBManager (org.firebirdsql.management.FBManager)9 File (java.io.File)2 SQLException (java.sql.SQLException)1 Ignore (org.junit.Ignore)1