// // Examine BLOBs and CLOBs. // private void vetLargeObjects( Connection conn, HashSet<String> unsupportedList, HashSet<String> notUnderstoodList) throws Exception { Statement stmt = conn.createStatement(); stmt.execute("CREATE TABLE t (id INT PRIMARY KEY, " + "b BLOB(10), c CLOB(10))"); stmt.execute( "INSERT INTO t (id, b, c) VALUES (1, " + "CAST (" + TestUtil.stringToHexLiteral("101010001101") + "AS BLOB(10)), CAST ('hello' AS CLOB(10)))"); ResultSet rs = stmt.executeQuery("SELECT id, b, c FROM t"); rs.next(); Blob blob = rs.getBlob(2); Clob clob = rs.getClob(3); vetObject(blob, unsupportedList, notUnderstoodList); vetObject(clob, unsupportedList, notUnderstoodList); stmt.close(); conn.rollback(); }
/** * Shutdown the datbase * * @param dbName Name of the database to shutdown. */ void shutdown(String dbName) { try { // shutdown TestUtil.getConnection(dbName, "shutdown=true"); } catch (SQLException se) { if (se.getSQLState() != null && se.getSQLState().equals("08006")) System.out.println("database shutdown properly"); else dumpSQLException(se); } }
/** * Run some consistency checks. * * @param dbName consistency checks are performed on this database. */ void runConsistencyChecker(String dbName) throws SQLException { Connection conn = TestUtil.getConnection(dbName, null); Statement stmt = conn.createStatement(); stmt.execute("values SYSCS_UTIL.SYSCS_CHECK_TABLE('APP', 'EMP')"); // check the data in the EMP table. DatabaseActions dbActions = new DatabaseActions(conn); dbActions.select(TEST_TABLE_NAME); dbActions.select(TEST_TABLE_NAME_1); dbActions.select(TEST_TABLE_NAME_2); conn.close(); }
/** Shutdown the datbase */ void shutdown() { if (verbose) logMessage("Shutdown " + currentTestDatabase); try { // shutdown TestUtil.getConnection(currentTestDatabase, "shutdown=true"); } catch (SQLException se) { if (se.getSQLState() == null || !(se.getSQLState().equals("08006"))) { // database was not shutdown properly dumpSQLException(se); } } }
/** * Encrypt an un-encrypted atabase. * * @param password boot password of the database. * @exception SQLException if any database exception occurs. */ private Connection encryptDatabase() throws SQLException { String connAttrs = ""; if (encryptionType == USING_PASSWORD) { // encrypt an existing database. connAttrs = "dataEncryption=true;bootPassword="******"dataEncryption=true;encryptionKey=" + OLD_KEY; } if (verbose) logMessage("encrypting " + currentTestDatabase + " with " + connAttrs); return TestUtil.getConnection(currentTestDatabase, connAttrs); }
/* * create an encrypted database. */ private Connection createEncryptedDatabase() throws SQLException { String connAttrs = ""; if (encryptionType == USING_PASSWORD) { // create encrypted database. connAttrs = "create=true;dataEncryption=true;bootPassword="******"create=true;dataEncryption=true;encryptionKey=" + OLD_KEY; } return TestUtil.getConnection(currentTestDatabase, connAttrs); }
/** * Boot the database. * * @param passwordOrKey the password/key to use. * @exception SQLException if any database exception occurs. */ Connection bootDatabase(int passwordKey) throws SQLException { String connAttrs = ""; if (encryptionType == USING_PASSWORD) { if (passwordKey == NEW) connAttrs = "bootPassword="******"bootPassword="******"encryptionKey=" + NEW_KEY; else if (passwordKey == OLD) connAttrs = "encryptionKey=" + OLD_KEY; } if (verbose) logMessage("booting " + currentTestDatabase + " with " + connAttrs); return TestUtil.getConnection(currentTestDatabase, connAttrs); }
/** * Re-encrypt the database. * * @exception SQLException if any database exception occurs. */ private Connection reEncryptDatabase() throws SQLException { String connAttrs = ""; if (encryptionType == USING_PASSWORD) { // re-encrypt the database. connAttrs = "bootPassword="******";newBootPassword="******"encryptionKey=" + OLD_KEY + ";newEncryptionKey=" + NEW_KEY; } if (verbose) logMessage("re-encrypting " + currentTestDatabase + " with " + connAttrs); return TestUtil.getConnection(currentTestDatabase, connAttrs); }
public static void main(String[] args) { try { ij.getPropertyArg(args); Connection conn = ij.startJBMS(); conn.setAutoCommit(false); createTablesAndInsertData(conn); getStatistics(conn); conn.rollback(); conn.close(); } catch (SQLException e) { TestUtil.dumpSQLExceptions(e); } catch (Throwable e) { System.out.println("FAIL -- unexpected exception:" + e.toString()); } }
/* * Test online backup with unlogged operations. And DML/DDL's * running in paralel to the backup. After the backup is complete restore * the database from the backup and performs consistency checks on the * database to make sure backup was good one. */ private void runTest() throws Exception { logMessage("Begin Online Backup Test1"); Connection conn = ij.startJBMS(); conn.setAutoCommit(false); DatabaseActions dbActions = new DatabaseActions(conn); // create the test tables. dbActions.createTable(TEST_TABLE_NAME); dbActions.createTable(TEST_TABLE_NAME_1); dbActions.createTable(TEST_TABLE_NAME_2); conn.commit(); // start first unlogged operation dbActions.startUnloggedAction(TEST_TABLE_NAME_1); logMessage("First Transaction with Unlogged Operation Started"); // start second unlogged opearation Connection conn1 = ij.startJBMS(); conn1.setAutoCommit(false); DatabaseActions dbActions1 = new DatabaseActions(conn1); dbActions1.startUnloggedAction(TEST_TABLE_NAME_2); logMessage("Second Transaction with Unlogged Operation Started"); // setup threads. // start a thread to perform online backup OnlineBackup backup = new OnlineBackup(TEST_DATABASE_NAME, BACKUP_PATH); Thread backupThread = new Thread(backup, "BACKUP"); // run some dml actions in another thread Connection dmlConn = TestUtil.getConnection(TEST_DATABASE_NAME, null); DatabaseActions dmlActions = new DatabaseActions(DatabaseActions.DMLACTIONS, dmlConn); Thread dmlThread = new Thread(dmlActions, "DML_THREAD"); // run some DDL create/drop tables in another thread Connection ddlConn = TestUtil.getConnection(TEST_DATABASE_NAME, null); DatabaseActions ddlActions = new DatabaseActions(DatabaseActions.CREATEDROPS, ddlConn); Thread ddlThread = new Thread(ddlActions, "DDL_THREAD"); try { // start a thread to perform online backup backupThread.start(); // wait for the backup to start backup.waitForBackupToBegin(); logMessage("BACKUP STARTED"); // run some dml actions in another thread dmlThread.start(); // run some DDL create/drop tables in another thread ddlThread.start(); // sleep for few seconds just to make sure backup thread is actually // gone to a wait state for unlogged actions to commit and there is // some ddl and dml activity in progress. java.lang.Thread.sleep(50000); // backup should not even start doing real work before the // unlogged transaction is commited if (!backup.isRunning()) logMessage("Backup is not waiting for unlogged actions to commit"); // end the unlogged work transaction. dbActions.endUnloggedAction(TEST_TABLE_NAME_1); // end the unlogged work transaction. dbActions1.endUnloggedAction(TEST_TABLE_NAME_2); backup.waitForBackupToEnd(); } finally { // stop all threads activities. backupThread.join(); dmlActions.stopActivity(); ddlActions.stopActivity(); dmlThread.join(); ddlThread.join(); } // close the connections. conn.close(); conn1.close(); dmlConn.close(); ddlConn.close(); // shutdown the test db shutdown(TEST_DATABASE_NAME); // restore the database from the backup and run some checks backup.restoreFromBackup(); logMessage("Restored From the Backup"); runConsistencyChecker(TEST_DATABASE_NAME); logMessage("Consistency Check is Done"); // shutdown the test db shutdown(TEST_DATABASE_NAME); logMessage("End Online Backup Test1"); }
/* * create an un-encrypted database. */ private Connection createDatabase() throws SQLException { return TestUtil.getConnection(currentTestDatabase, "create=true"); }