⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdbbasics.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
               st.setLong(5, 1L); // loop only once               st.registerOutParameter(1, Types.CLOB);               ResultSet rs = st.executeQuery();               Clob clob = st.getClob(1);               long len = clob.length();               byte[] buf = new byte[(int)len];               clob.getAsciiStream().read(buf);               rs.close();               st.close();               log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");               String out = new String(buf);               assertEquals("invocation '" + sql + "' gave the wrong result ", result+result, out);            }            catch (SQLException sqlEx) {               sqlEx.printStackTrace();               assertTrue("an exception should not occur ocalhostwhen testing '" + sql + "'", false);            }         }         {            sql = "{? = call " + this.replPrefix + "check_tables(?,?,?,?,NULL)}"; // name text, content text)            try {               CallableStatement st = conn.prepareCall(sql);               st.setString(2, "dbName");    // database name               st.setString(3, "schema");               st.setString(4, "table");               st.setString(5, "COMMAND");               st.registerOutParameter(1, Types.VARCHAR);               ResultSet rs = st.executeQuery();               String ret = st.getString(1);               log.fine("The return value of the query '" + sql + "' is '" + ret + "'");               rs.close();               st.close();            }            catch (SQLException sqlEx) {               sqlEx.printStackTrace();               assertTrue("an exception should not occur when testing '" + sql + "'", false);            }         }         {            sql = "{? = call " + this.replPrefix + "check_tables(?,?,?,?,?)}"; // name text, content text)            try {               CallableStatement st = conn.prepareCall(sql);               st.setString(2, "dbName");    // database name               st.setString(3, "schema");               st.setString(4, "table");               st.setString(5, "COMMAND");               st.setString(6, "TEST CONTENT");               st.registerOutParameter(1, Types.VARCHAR);               ResultSet rs = st.executeQuery();               String ret = st.getString(1);               log.fine("The return value of the query '" + sql + "' is '" + ret + "'");               rs.close();               st.close();            }            catch (SQLException sqlEx) {               sqlEx.printStackTrace();               assertTrue("an exception should not occur when testing '" + sql + "'", false);            }         }         // TEST HERE THE repl_add_table function behaviour         {            sql = "{? = call " + this.replPrefix + "add_table(?,?,?,?)}"; // name text, content text)            try {               try {                  this.pool.update("DELETE FROM " + "TEST_REPLICATION");               }               catch (Exception e) {               }               CallableStatement st = conn.prepareCall(sql);               st.setString(2, null);               st.setString(3, this.specificHelper.getOwnSchema(this.pool));               st.setString(4, "TEST_REPLICATION");               st.setString(5, "CREATE");               st.registerOutParameter(1, Types.VARCHAR);               ResultSet rs = st.executeQuery();               String ret = st.getString(1);               log.fine("The return value of the query '" + sql + "' is '" + ret + "'");               rs.close();               st.close();               // assertEquals("Checking the invocation of '" + this.replPrefix + "add_table': and addition which must result in no operation", "FALSE", ret);            }            catch (SQLException sqlEx) {               sqlEx.printStackTrace();               assertTrue("an exception should not occur when testing '" + sql + "'", false);            }         }         // TEST HERE THE repl_add_table function behaviour         {            sql = "{? = call " + this.replPrefix + "add_table(?,?,?,?)}"; // name text, content text)            try {               boolean force = false;               boolean forceSend = false;               TableToWatchInfo tableToWatch = new TableToWatchInfo(null, this.specificHelper.getOwnSchema(this.pool), "TEST_REPLICATION");               tableToWatch.setActions("");               tableToWatch.setTrigger(null);               this.dbSpecific.addTableToWatch(tableToWatch, force, null, forceSend);               CallableStatement st = conn.prepareCall(sql);               st.setString(2, null);               st.setString(3, this.specificHelper.getOwnSchema(this.pool));               st.setString(4, "TEST_REPLICATION");               st.setString(5, "CREATE");               st.registerOutParameter(1, Types.VARCHAR);               ResultSet rs = st.executeQuery();               String ret = st.getString(1);               log.fine("The return value of the query '" + sql + "' is '" + ret + "'");               rs.close();               st.close();               assertEquals("Checking the invocation of '" + this.replPrefix + "add_table': and addition which must result in no operation", "TRUE", ret);               // and the entry should be in the repl_items table            }            catch (SQLException sqlEx) {               sqlEx.printStackTrace();               assertTrue("an exception should not occur when testing '" + sql + "'", false);            }         }         try {            this.pool.update("DELETE FROM " + this.replPrefix + "TEST_REPLICATION");         }         catch (Exception e) {         }      }       catch (Exception ex) {         ex.printStackTrace();         assertTrue("an exception should not occur " + ex.getMessage(), false);      }      log.info("SUCCESS");   }   private String extractBase64Part(String txt) {      String sep = "encoding=\"base64\">";      int pos = txt.indexOf(sep);      if (pos < 0)         return null;      pos += sep.length();      txt = txt.substring(pos);      sep = "</col>";      pos = txt.indexOf(sep);      if (pos < 0)         return null;      return txt.substring(0, pos);   }      /**    * This method makes some calls to system functions.    * @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)            CallableStatement st = conn.prepareCall(sql);            st.setString(2, "COL2XML_CDATA");            st.setString(3, "prova");            st.setString(4, "test");            st.setLong(5, 1L); // loop only once            st.registerOutParameter(1, Types.CLOB);            ResultSet rs = st.executeQuery();            Clob clob = st.getClob(1);            long len = clob.length();            byte[] buf = new byte[(int)len];            clob.getAsciiStream().read(buf);            rs.close();            st.close();            log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");            assertEquals(sql, "<col name=\"test\"><![CDATA[prova]]></col>", new String(buf));         }         {            // col2xml_base64(?, ?)            sql = "{? = call " + this.replPrefix + "test_blob(?,?,?,?)}"; // name text, content text)            CallableStatement st = conn.prepareCall(sql);            st.setString(2, "COL2XML_BASE64");            st.setBytes(3, "prova".getBytes());            st.setString(4, "test");            st.setLong(5, 1L); // loop only once            st.registerOutParameter(1, Types.CLOB);            ResultSet rs = st.executeQuery();            Clob clob = st.getClob(1);            long len = clob.length();            byte[] buf = new byte[(int)len];            clob.getAsciiStream().read(buf);            rs.close();            st.close();            log.fine("The return value of the query '" + sql + "' is '" + new String(buf) + "'");            assertEquals(sql, "<col name=\"test\" encoding=\"base64\">cHJvdmE=</col>", new String(buf));            String tmp = extractBase64Part(new String(buf));            byte[] ret = org.xmlBlaster.util.Base64.decode(tmp);            String returnName = new String(ret);            assertEquals("The returned (decoded) String is checked", "prova", returnName);                     }         {              // col2xml_base64(?, ?) CONTENTS BIGGER THAN 4 kB             sql = "{? = call " + this.replPrefix + "test_blob(?,?,?,?)}"; // name text, content text)            CallableStatement st = conn.prepareCall(sql);            st.setString(2, "COL2XML_BASE64");            int nmax = 256;            byte[] blob = new byte[nmax];            for (int i=0; i < nmax; i++)               blob[i] = (byte)i;            st.setBytes(3, blob);            st.setString(4, "test");            st.setLong(5, (long)nmax); // loop multiple times to simulate big contents            st.registerOutParameter(1, Types.CLOB);            ResultSet rs = st.executeQuery();            Clob clob = st.getClob(1);            long len = clob.length();            byte[] buf = new byte[(int)len];            clob.getAsciiStream().read(buf);            rs.close();            st.close();            String tmp = extractBase64Part(new String(buf));            byte[] ret = org.xmlBlaster.util.Base64.decode(tmp);            assertEquals("Comparison of lenght of input blob with output blob", nmax * nmax, ret.length);            log.fine("success");         }         // now testing the " + this.replPrefix + "needs_prot for the three cases ...         { // needs no protection needs_prot(?)            sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)            CallableStatement st = conn.prepareCall(sql);            st.setString(2, "NEEDS_PROT");            st.setString(3, "prova");            st.setString(4, "unused");            st.setLong(5, 1L);            // st.registerOutParameter(1, Types.INTEGER);            st.registerOutParameter(1, Types.CLOB);            ResultSet rs = st.executeQuery();            // int ret = st.getInt(1);            Clob clob = st.getClob(1);            long len = clob.length();            byte[] buf = new byte[(int)len];            clob.getAsciiStream().read(buf);            String txt = new String(buf);            log.fine("The return value of the query '" + sql + "' is '" + txt + "'");            int ret = -1000;            try {               ret = Integer.parseInt(txt);            }            catch (Throwable e) {               assertTrue("Conversion exception should not occur on '" + sql + "' where ret is '" + txt + "'", false);            }            rs.close();            st.close();            assertEquals(sql, 0, ret);         }         { // needs BASE64 needs_prot(?)            sql = "{? = call " + this.replPrefix + "test_clob(?,?,?,?)}"; // name text, content text)            CallableStatement st = conn.prepareCall(sql);            st.setString(2, "NEEDS_PROT");            st.setString(3, "<![[CDATAsome text]]>");            st.setString(4, "unused");            st.setLong(5, 1L);            // st.registerOutParameter(1, Types.INTEGER);            st.registerOutParameter(1, Types.CLOB);            ResultSet rs = st.executeQuery();            // int ret = st.getInt(1);            Clob clob = st.getClob(1);            long len = clob.length();            byte[] buf = new byte[(int)len];            clob.getAsciiStream().read(buf);            String txt = new String(buf);            log.fine("The return value of the query '" + sql + "' is '" + txt + "'");            int ret = -1000;            try {               ret = Integer.parseInt(txt);            }            catch (Throwable e) {               assertTrue("Conversion exception should not occur on '" + sql + "' where ret is '" + txt + "'", false);            }            rs.close();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -