Search in sources :

Example 1 with FbDatabase

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

the class TestBackupManager method testRestorePageSize32768.

/**
 * Test if restoring a database to page size 32768 works.
 */
@Test
public void testRestorePageSize32768() throws Exception {
    assumeTrue("Test requires 32K page size support", getDefaultSupportInfo().supportsPageSize(PageSizeConstants.SIZE_32K));
    usesDatabase.createDefaultDatabase();
    backupManager.backupDatabase();
    backupManager.setRestoreReplace(true);
    backupManager.setRestorePageSize(PageSizeConstants.SIZE_32K);
    backupManager.restoreDatabase();
    try (Connection con = getConnectionViaDriverManager()) {
        GDSHelper gdsHelper = ((FBConnection) con).getGDSHelper();
        final FbDatabase currentDatabase = gdsHelper.getCurrentDatabase();
        final byte[] databaseInfo = currentDatabase.getDatabaseInfo(new byte[] { ISCConstants.isc_info_page_size }, 10);
        assertEquals("Unexpected info item", ISCConstants.isc_info_page_size, databaseInfo[0]);
        int length = iscVaxInteger2(databaseInfo, 1);
        int pageSize = iscVaxInteger(databaseInfo, 3, length);
        assertEquals("Unexpected page size", 32768, pageSize);
    }
}
Also used : FBConnection(org.firebirdsql.jdbc.FBConnection) Connection(java.sql.Connection) FBConnection(org.firebirdsql.jdbc.FBConnection) GDSHelper(org.firebirdsql.gds.impl.GDSHelper) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) Test(org.junit.Test)

Example 2 with FbDatabase

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

the class TestFBManager method testSetPageSize_createdDatabaseHasSize.

@Test
public void testSetPageSize_createdDatabaseHasSize() throws Exception {
    FBManager m = createFBManager();
    m.setServer(DB_SERVER_URL);
    m.setPort(DB_SERVER_PORT);
    m.start();
    try {
        // Adding .fdb suffix to prevent conflicts with other tests if drop fails
        final String databasePath = getDatabasePath() + ".fdb";
        m.setPageSize(16384);
        // check create
        m.createDatabase(databasePath, DB_USER, DB_PASSWORD);
        try {
            FBConnection connection = (FBConnection) DriverManager.getConnection(getUrl() + ".fdb", getDefaultPropertiesForConnection());
            try {
                final FbDatabase currentDatabase = connection.getGDSHelper().getCurrentDatabase();
                final byte[] databaseInfo = currentDatabase.getDatabaseInfo(new byte[] { ISCConstants.isc_info_page_size }, 10);
                assertEquals("Unexpected info item", ISCConstants.isc_info_page_size, databaseInfo[0]);
                int length = iscVaxInteger2(databaseInfo, 1);
                int pageSize = iscVaxInteger(databaseInfo, 3, length);
                assertEquals("Unexpected page size", 16384, pageSize);
            } finally {
                connection.close();
            }
        } finally {
            m.dropDatabase(databasePath, DB_USER, DB_PASSWORD);
        }
    } finally {
        m.stop();
    }
}
Also used : FBConnection(org.firebirdsql.jdbc.FBConnection) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) Test(org.junit.Test)

Example 3 with FbDatabase

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

the class TestFBManager method testDialect3_dbCreatedWithRightDialect.

@Test
public void testDialect3_dbCreatedWithRightDialect() throws Exception {
    FBManager m = createFBManager();
    m.setServer(DB_SERVER_URL);
    m.setPort(DB_SERVER_PORT);
    m.start();
    try {
        // Adding .fdb suffix to prevent conflicts with other tests if drop fails
        final String databasePath = getDatabasePath() + ".fdb";
        m.setDialect(3);
        // check create
        m.createDatabase(databasePath, DB_USER, DB_PASSWORD);
        try {
            FBConnection connection = (FBConnection) DriverManager.getConnection(getUrl() + ".fdb", getDefaultPropertiesForConnection());
            try {
                final FbDatabase currentDatabase = connection.getGDSHelper().getCurrentDatabase();
                assertEquals("Unexpected database dialect", 3, currentDatabase.getDatabaseDialect());
            } finally {
                connection.close();
            }
        } finally {
            m.dropDatabase(databasePath, DB_USER, DB_PASSWORD);
        }
    } finally {
        m.stop();
    }
}
Also used : FBConnection(org.firebirdsql.jdbc.FBConnection) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) Test(org.junit.Test)

Example 4 with FbDatabase

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

the class TestFBManager method testDialect1_dbCreatedWithRightDialect.

@Test
public void testDialect1_dbCreatedWithRightDialect() throws Exception {
    FBManager m = createFBManager();
    m.setServer(DB_SERVER_URL);
    m.setPort(DB_SERVER_PORT);
    m.start();
    try {
        // Adding .fdb suffix to prevent conflicts with other tests if drop fails
        final String databasePath = getDatabasePath() + ".fdb";
        m.setDialect(1);
        // check create
        m.createDatabase(databasePath, DB_USER, DB_PASSWORD);
        try {
            FBConnection connection = (FBConnection) DriverManager.getConnection(getUrl() + ".fdb", getDefaultPropertiesForConnection());
            try {
                final FbDatabase currentDatabase = connection.getGDSHelper().getCurrentDatabase();
                assertEquals("Unexpected database dialect", 1, currentDatabase.getDatabaseDialect());
            } finally {
                connection.close();
            }
        } finally {
            m.dropDatabase(databasePath, DB_USER, DB_PASSWORD);
        }
    } finally {
        m.stop();
    }
}
Also used : FBConnection(org.firebirdsql.jdbc.FBConnection) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) Test(org.junit.Test)

Example 5 with FbDatabase

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

the class FBConnectionTest method testGetAttachments.

@Test
public void testGetAttachments() throws Exception {
    try (FBConnection connection = (FBConnection) getConnectionViaDriverManager()) {
        FbDatabase database = connection.getFbDatabase();
        byte[] infoRequest = new byte[] { ISCConstants.isc_info_user_names, ISCConstants.isc_info_end };
        byte[] reply = database.getDatabaseInfo(infoRequest, 1024);
        int i = 0;
        while (reply[i] != ISCConstants.isc_info_end) {
            switch(reply[i++]) {
                case ISCConstants.isc_info_user_names:
                    // iscVaxInteger2(reply, i); // can be ignored
                    i += 2;
                    int strLen = reply[i] & 0xff;
                    i += 1;
                    String userName = new String(reply, i, strLen);
                    i += strLen;
                    System.out.println(userName);
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : FbDatabase(org.firebirdsql.gds.ng.FbDatabase) Test(org.junit.Test)

Aggregations

FbDatabase (org.firebirdsql.gds.ng.FbDatabase)12 Test (org.junit.Test)7 FBConnection (org.firebirdsql.jdbc.FBConnection)6 SQLException (java.sql.SQLException)4 GDSHelper (org.firebirdsql.gds.impl.GDSHelper)3 IConnectionProperties (org.firebirdsql.gds.ng.IConnectionProperties)3 Connection (java.sql.Connection)2 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)2 ResourceException (javax.resource.ResourceException)1 TransactionParameterBuffer (org.firebirdsql.gds.TransactionParameterBuffer)1 FbStatement (org.firebirdsql.gds.ng.FbStatement)1