Package org.xmlBlaster.contrib.db

Examples of org.xmlBlaster.contrib.db.I_DbPool


    *
    */
   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());
View Full Code Here


    *
    */
   public final void testTableWithLongs() {

      log.info("Start testTableWithLongs");
      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), comments LONG, 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 tableName = rs.getString(4);
               String dbAction = rs.getString(6);
               assertEquals("Testing the content of the action", "CREATE", dbAction);
               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', 'some very long text here')";
               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);
               // must be null since it contains LONG which must be read individually
               assertTrue("The content must be null since entry contains LONG", content == null);

               String guid = rs.getString(5);
               String dbCatalog = rs.getString(7);
               String dbSchema = rs.getString(8);
               assertTrue("The guid can not be null", guid != null);

               String contentTxt = this.dbSpecific.getContentFromGuid(guid, dbCatalog, dbSchema, tableName, null);

               assertEquals("Testing the content of the action", "INSERT", dbAction);
               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 comments='some very long text here' 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);
               byte[] tmp = new byte[10000];

               String guid = rs.getString(5);
               String dbCatalog = rs.getString(7);
               String dbSchema = rs.getString(8);
               String contentTxt = this.dbSpecific.getContentFromGuid(guid, dbCatalog, dbSchema, tableName, null);

               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", 5+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());
               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);
               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 = "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());
View Full Code Here

   /**
    *
    */
   public final void testDateFormat() {
      log.info("Start testDifferentFormats");
      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;
         sql = "CREATE TABLE " + this.tableName + " (first DATE, PRIMARY KEY(first))";
         pool.update(sql);

         this.dbSpecific.readNewTable(null, this.specificHelper.getOwnSchema(this.pool), this.dbHelper.getIdentifier(this.tableName), null, true);
         try {
            this.pool.update("DELETE from " + this.replPrefix + "items");
            // long time = System.currentTimeMillis();
View Full Code Here

   /**
    *
    */
   public final void testTimestampFormat() {
      log.info("Start testDifferentFormats");
      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;
         String type = "TIMESTAMP";
         // TODO remove this after testing
         type = "DATE";
         sql = "CREATE TABLE " + this.tableName + " (first " + type + ", PRIMARY KEY(first))";
         pool.update(sql);

         this.dbSpecific.readNewTable(null, this.specificHelper.getOwnSchema(this.pool), this.dbHelper.getIdentifier(this.tableName), null, true);
         try {
            this.pool.update("DELETE from " + this.replPrefix + "items");
            // long time = System.currentTimeMillis();
View Full Code Here

    */
   public final void testBasicPerformance() throws Exception {
      String txt = "testBasicPerformance";
      log.info("Start " + txt);
     
      I_DbPool pool = (I_DbPool)info.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      try {
         pool.update("DROP TABLE PERFORM");
      }
      catch (SQLException ex) {
         log.info("An Exception here is allowed");
      }
     
      pool.update("CREATE TABLE PERFORM (name1 VARCHAR(20), name2 VARCHAR(128), name3 BLOB, primary key (name1))");

      Connection conn = pool.reserve();
      conn.setAutoCommit(false);
      String sql = "INSERT INTO PERFORM VALUES (?, ?, ?)";
      byte[] blob = new byte[1024];
      for (int i=0; i < blob.length; i++)
         blob[i] = (byte)i;
     
      int nmax = 50;
      {
         long t0 = System.currentTimeMillis();
         PreparedStatement st = conn.prepareStatement(sql);
         ByteArrayInputStream bais = new ByteArrayInputStream(blob);
         for (int i=0; i < nmax; i++) {
            st.setString(1, "name01_" + i);
            st.setString(2, "name02_" + i);
            st.setBinaryStream(3, bais, blob.length);
            st.addBatch();
         }
         st.executeBatch();
         conn.commit();
         long t1 = System.currentTimeMillis();
         long dt = t1-t0;
         log.info("batch statements='" + nmax + "' took '" + dt + "' ms (per statement: " + dt/nmax + ")");
         pool.update("delete from PERFORM");
         conn.commit();
      }
      {
         long t0 = System.currentTimeMillis();
         for (int i=0; i < nmax; i++) {
            ByteArrayInputStream bais = new ByteArrayInputStream(blob);
            PreparedStatement st = conn.prepareStatement(sql);
            st.setString(1, "name01_" + i);
            st.setString(2, "name02_" + i + "_hhjdhsdsdjsdkljsdjsdljljsdljsdkljsljsdsdsdsd");
            st.setBinaryStream(3, bais, blob.length);
            st.execute();
         }
         conn.commit();
         long t1 = System.currentTimeMillis();
         long dt = t1-t0;
         log.info("non-batch (single commit) statements='" + nmax + "' took '" + dt + "' ms (per statement: " + dt/nmax + ")");
         pool.update("delete from PERFORM");
         conn.commit();
      }
      {
         long t0 = System.currentTimeMillis();
         for (int i=0; i < nmax; i++) {
            ByteArrayInputStream bais = new ByteArrayInputStream(blob);
            PreparedStatement st = conn.prepareStatement(sql);
            st.setString(1, "name01_" + i);
            st.setString(2, "name02_" + i + "_hhjdhsdsdjsdkljsdjsdljljsdljsdkljsljsdsdsdsd");
            st.setBinaryStream(3, bais, blob.length);
            st.execute();
            conn.commit();
         }
         long t1 = System.currentTimeMillis();
         long dt = t1-t0;
         log.info("non-batch (all commit) statements='" + nmax + "' took '" + dt + "' ms (per statement: " + dt/nmax + ")");
         pool.update("delete from PERFORM");
         conn.commit();
      }

      pool.update("DROP TABLE PERFORM");
      pool.release(conn);
      log.info("SUCCESS");
   }
View Full Code Here

      if (!this.specificHelper.isOracle()) {
         log.info("Stop testInternalFunctions (nothing to be done since not oracle)");
         return;
      }
     
      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;
         { // test the test methods themselves first
             sql = "{? = call " + this.replPrefix + "test_blob(?,?,?,?)}";
             try {
View Full Code Here

    * @throws Exception Any type is possible
    */
   public final void testFunctions() throws Exception {
      log.info("Start testFunctions");

      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;
         {
          // col2xml_cdata(?, ?)
            sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)
View Full Code Here

    *
    * @throws Exception Any type is possible
    */
   public final void testChangesToReplTables() throws Exception {
      log.info("Start testChangesToReplTables");
      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 schema = this.specificHelper.getOwnSchema(pool);
         changesToReplTables(conn, null, schema, "test_lowecase", true);
         changesToReplTables(conn, "", schema, "test_lowecase", true);
         changesToReplTables(conn, null, schema, "test_lowecase", false);
View Full Code Here

      if (!this.specificHelper.isOracle()) {
         log.info("Stop testInternalFunctions (nothing to be done since not oracle)");
         return;
      }
     
      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;
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

    */
   public final void testCreateTablesWithDifferentTypes() throws Exception {
      currentMethod = new String("testCreateTablesWithDifferentTypes");
      log.info("Start " + currentMethod);

      I_DbPool pool = (I_DbPool)info.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      doCheck = true;
      String[] sqls = specificHelper.getSql(this.tableName);
      try {
         for (int i=0; i < sqls.length; i++) {
            try {
               try {
                  pool.update("DROP TABLE " + this.tableName + specificHelper.getCascade());
               }
               catch (Exception e) {
               }
               pool.update(sqls[i]);
               // don't do this since oracle 10.1.0 returns zero (don't know why)
               // assertEquals("the number of created tables must be one", 1, ret);
            }
            catch (Exception ex) {
               ex.printStackTrace();
View Full Code Here

TOP

Related Classes of org.xmlBlaster.contrib.db.I_DbPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.