*
*/
public final void testPerformAllOperationsOnTable() {
log.info("Start testPerformAllOperationsOnTable");
I_DbPool pool = (I_DbPool)info.getObject("db.pool");
assertNotNull("pool must be instantiated", pool);
Connection conn = null;
try {
conn = pool.reserve();
conn.setAutoCommit(true);
String sql = null;
{
try {
sql = "CREATE TABLE " + this.tableName + " (name VARCHAR(20), age INTEGER, PRIMARY KEY(name))";
pool.update(sql);
Thread.sleep(500L);
conn = this.pool.reserve();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * from " + this.replPrefix + "items");
assertEquals("Testing creation of table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());
String transKey = rs.getString(2);
// String dbId = rs.getString(3);
String tableName = rs.getString(4);
// String guid = rs.getString(5);
String dbAction = rs.getString(6);
// String dbCatalog = rs.getString(7);
// String dbSchema = rs.getString(8);
// InputStream content = rs.getAsciiStream(9);
// byte[] tmp = new byte[10000];
// content.read(tmp);
// String contentTxt = new String(tmp);
// InputStream oldContent = rs.getAsciiStream(10);
// content.read(tmp);
// String oldContentTxt = new String(tmp);
// String version = rs.getString(11);
assertEquals("Testing the content of the action", "CREATE", dbAction);
//assertEquals("Testing the content of the replKey", 2, replKey); // 1 is the addition to the repl_tables
assertNotNull("Testing that the transaction is not null", transKey);
assertEquals("Testing that the table name is correct", this.dbHelper.getIdentifier(this.tableName), tableName);
this.pool.update("DELETE from " + this.replPrefix + "items");
}
catch (Exception e) {
e.printStackTrace();
assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);
}
finally {
if (conn != null)
this.pool.release(conn);
}
}
this.dbSpecific.readNewTable(null, this.specificHelper.getOwnSchema(this.pool), this.dbHelper.getIdentifier(this.tableName), null, true);
{
try {
sql = "INSERT INTO " + this.tableName + " VALUES ('first', 44)";
pool.update(sql);
Thread.sleep(500L);
conn = this.pool.reserve();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * from " + this.replPrefix + "items");
assertEquals("Testing insertion into table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());
String transKey = rs.getString(2);
String tableName = rs.getString(4);
String dbAction = rs.getString(6);
InputStream content = rs.getAsciiStream(9);
byte[] tmp = new byte[10000];
content.read(tmp);
String contentTxt = new String(tmp);
assertEquals("Testing the content of the action", "INSERT", dbAction);
// assertEquals("Testing the content of the replKey", 2+ref, replKey);
assertNotNull("Testing that the transaction is not null", transKey);
assertNotNull("Testing that the content is not null", contentTxt);
assertEquals("Testing that the table name is correct", this.dbHelper.getIdentifier(this.tableName), tableName);
log.info("'" + sql + "' generates (new) '" + contentTxt + "'");
this.pool.update("DELETE from " + this.replPrefix + "items");
}
catch (Exception e) {
e.printStackTrace();
assertTrue("Exception when testing operation 'INSERT' should not have happened: " + e.getMessage(), false);
}
finally {
if (conn != null)
this.pool.release(conn);
}
}
{
try {
sql = "UPDATE " + this.tableName + " SET age=33 WHERE name='first'";
pool.update(sql);
Thread.sleep(500L);
conn = this.pool.reserve();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * from " + this.replPrefix + "items");
assertEquals("Testing UPDATE of table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());
String transKey = rs.getString(2);
String tableName = rs.getString(4);
String dbAction = rs.getString(6);
InputStream content = rs.getAsciiStream(9);
byte[] tmp = new byte[10000];
content.read(tmp);
String contentTxt = new String(tmp);
InputStream oldContent = rs.getAsciiStream(10);
oldContent.read(tmp);
String oldContentTxt = new String(tmp);
assertEquals("Testing the content of the action", "UPDATE", dbAction);
// assertEquals("Testing the content of the replKey", 3+ref, replKey);
assertNotNull("Testing that the transaction is not null", transKey);
assertNotNull("Testing that the content is not null", contentTxt);
assertNotNull("Testing that the old content is not null", oldContentTxt);
assertEquals("Testing that the table name is correct", this.dbHelper.getIdentifier(this.tableName), tableName);
log.info("'" + sql + "' generates (new) '" + contentTxt + "'");
log.info("'" + sql + "' generates (old) '" + oldContentTxt + "'");
this.pool.update("DELETE from " + this.replPrefix + "items");
}
catch (Exception e) {
e.printStackTrace();
assertTrue("Exception when testing operation 'UPDATE' should not have happened: " + e.getMessage(), false);
}
finally {
if (conn != null)
this.pool.release(conn);
}
}
{
try {
sql = "DELETE FROM " + this.tableName;
pool.update(sql);
Thread.sleep(500L);
conn = this.pool.reserve();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * from " + this.replPrefix + "items");
assertEquals("Testing DELETE of table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());
// long replKey = rs.getLong(1);
String transKey = rs.getString(2);
String tableName = rs.getString(4);
String dbAction = rs.getString(6);
// InputStream content = rs.getAsciiStream(9);
byte[] tmp = new byte[10000];
InputStream oldContent = rs.getAsciiStream(10);
oldContent.read(tmp);
String oldContentTxt = new String(tmp);
assertEquals("Testing the content of the action", "DELETE", dbAction);
// assertEquals("Testing the content of the replKey", 4+ref, replKey);
assertNotNull("Testing that the transaction is not null", transKey);
assertNotNull("Testing that the old content is not null", oldContentTxt);
assertEquals("Testing that the table name is correct", this.dbHelper.getIdentifier(this.tableName), tableName);
log.info("'" + sql + "' generates (old) '" + oldContentTxt + "'");
this.pool.update("DELETE from " + this.replPrefix + "items");
}
catch (Exception e) {
e.printStackTrace();
assertTrue("Exception when testing operation 'DELETE' should not have happened: " + e.getMessage(), false);
}
finally {
if (conn != null)
this.pool.release(conn);
}
}
{
try {
sql = "ALTER TABLE " + this.tableName + " ADD (city VARCHAR(30))";
pool.update(sql);
Thread.sleep(500L);
conn = this.pool.reserve();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * from " + this.replPrefix + "items");
assertEquals("Testing ALTER of table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());
// long replKey = rs.getLong(1);
String transKey = rs.getString(2);
String tableName = rs.getString(4);
String dbAction = rs.getString(6);
assertEquals("Testing the content of the action", "ALTER", dbAction);
// assertEquals("Testing the content of the replKey", 5+ref, replKey);
assertNotNull("Testing that the transaction is not null", transKey);
assertEquals("Testing that the table name is correct", this.dbHelper.getIdentifier(this.tableName), tableName);
this.pool.update("DELETE from " + this.replPrefix + "items");
}
catch (Exception e) {
e.printStackTrace();
assertTrue("Exception when testing operation 'ALTER' should not have happened: " + e.getMessage(), false);
}
finally {
if (conn != null)
this.pool.release(conn);
}
}
{
try {
sql = "DROP TABLE " + this.tableName;
pool.update(sql);
Thread.sleep(500L);
conn = this.pool.reserve();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * from " + this.replPrefix + "items");
assertEquals("Testing DROP table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());