use of org.firebirdsql.jdbc.FBConnection in project jaybird by FirebirdSQL.
the class TestFBResultSet method testUsePreparedStatementAcrossTransactions.
@Test
public void testUsePreparedStatementAcrossTransactions() throws Exception {
FBManagedConnectionFactory mcf = initMcf();
DataSource ds = (DataSource) mcf.createConnectionFactory();
FBConnection c = (FBConnection) ds.getConnection();
Statement s = c.createStatement();
LocalTransaction t = c.getLocalTransaction();
Exception ex = null;
t.begin();
try {
s.execute("DROP TABLE T1");
} catch (Exception e) {
}
t.commit();
t.begin();
try {
s.execute("CREATE TABLE T1 ( C1 INTEGER not null primary key, C2 SMALLINT, C3 DECIMAL(18,0), C4 FLOAT, C5 DOUBLE PRECISION, C6 CHAR(10), C7 VARCHAR(20))");
} catch (Exception e) {
ex = e;
}
t.commit();
t.begin();
PreparedStatement p = c.prepareStatement("insert into T1 values (?, ?, ?, ?, ?, ?, ?)");
p.setInt(1, 1);
p.setShort(2, (short) 1);
p.setLong(3, 1);
p.setFloat(4, (float) 1.0);
p.setDouble(5, 1.0);
p.setString(6, "one");
p.setString(7, "one");
assertFalse("execute returned true for insert statement", p.execute());
p.setInt(1, 2);
p.setShort(2, (short) 2);
p.setLong(3, 2);
p.setFloat(4, (float) 2.0);
p.setDouble(5, 2.0);
p.setString(6, "two");
p.setString(7, "two");
assertEquals("executeUpdate count != 1", 1, p.executeUpdate());
p.close();
p = c.prepareStatement("select * from T1 where C1 = ?");
p.setInt(1, 1);
ResultSet rs = p.executeQuery();
while (rs.next()) {
if (log != null)
log.info("C1: " + rs.getInt(1) + " C2: " + rs.getShort(2) + " C3: " + rs.getLong(3) + " C4: " + rs.getFloat(4) + " C5: " + rs.getDouble(5) + " C6: " + rs.getString(6) + " C7: " + rs.getString(7));
if (log != null)
log.info("C1: " + rs.getInt("C1") + " C2: " + rs.getShort("C2") + " C3: " + rs.getLong("C3") + " C4: " + rs.getFloat("C4") + " C5: " + rs.getDouble("C5") + " C6: " + rs.getString("C6") + " C7: " + rs.getString("C7"));
}
t.commit();
// does prepared statement persist across transactions?
t.begin();
p.setInt(1, 2);
rs = p.executeQuery();
while (rs.next()) {
if (log != null)
log.info("C1: " + rs.getInt(1) + " C2: " + rs.getShort(2) + " C3: " + rs.getLong(3) + " C4: " + rs.getFloat(4) + " C5: " + rs.getDouble(5) + " C6: " + rs.getString(6) + " C7: " + rs.getString(7));
if (log != null)
log.info("C1: " + rs.getInt("C1") + " C2: " + rs.getShort("C2") + " C3: " + rs.getLong("C3") + " C4: " + rs.getFloat("C4") + " C5: " + rs.getDouble("C5") + " C6: " + rs.getString("C6") + " C7: " + rs.getString("C7"));
}
p.close();
t.commit();
t.begin();
s.execute("DROP TABLE T1");
s.close();
t.commit();
c.close();
if (ex != null) {
throw ex;
}
}
use of org.firebirdsql.jdbc.FBConnection in project jaybird by FirebirdSQL.
the class TestFBStandAloneConnectionManager method testUseStatement.
@Test
public void testUseStatement() throws Exception {
FBManagedConnectionFactory mcf = initMcf();
DataSource ds = (DataSource) mcf.createConnectionFactory();
FBConnection c = (FBConnection) ds.getConnection();
Statement s = c.createStatement();
FirebirdLocalTransaction t = c.getLocalTransaction();
assertNotNull("Could not get LocalTransaction", t);
Exception ex = null;
t.begin();
try {
s.execute("CREATE TABLE T1 ( C1 SMALLINT, C2 SMALLINT)");
} catch (Exception e) {
ex = e;
}
t.commit();
t.begin();
s.execute("DROP TABLE T1");
s.close();
t.commit();
c.close();
if (ex != null) {
throw ex;
}
}
use of org.firebirdsql.jdbc.FBConnection 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);
}
}
use of org.firebirdsql.jdbc.FBConnection 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();
}
}
use of org.firebirdsql.jdbc.FBConnection 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();
}
}
Aggregations