tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r1054730 - /tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java
Date Mon, 03 Jan 2011 20:11:50 GMT
Author: fhanik
Date: Mon Jan  3 20:11:50 2011
New Revision: 1054730

URL: http://svn.apache.org/viewvc?rev=1054730&view=rev
Log:
better count check

Modified:
    tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java

Modified: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java?rev=1054730&r1=1054729&r2=1054730&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java (original)
+++ tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java Mon
Jan  3 20:11:50 2011
@@ -55,18 +55,30 @@ public class CreateTestTable extends Def
             
             if (rs.next())
                 count = rs.getInt(1);
+            rs.close();
+            st.close();
             System.out.println("Count:"+count);
         }catch (Exception ignore) {}
+        con.close();
         return count;
     }
     
     public void testPopulateData() throws Exception {
-        init();
+        int count = 100000;
+        int actual = testCheckData();
+        if (actual>=count) {
+            System.out.println("Test tables has "+actual+" rows of data. No need to populate.");
+            return;
+        }
+        
         datasource.setJdbcInterceptors(ResetAbandonedTimer.class.getName());
         String insert = "insert into test values (?,?,?,?,?)";
         this.init();
         this.datasource.setRemoveAbandoned(false);
         Connection con = datasource.getConnection();
+        
+        boolean commit = con.getAutoCommit();
+        con.setAutoCommit(false);
         if (recreate) {
             Statement st = con.createStatement();
             try {
@@ -75,9 +87,11 @@ public class CreateTestTable extends Def
             st.execute("create table test(id int not null, val1 varchar(255), val2 varchar(255),
val3 varchar(255), val4 varchar(255))");
             st.close();
         }
+        
+        
         PreparedStatement ps = con.prepareStatement(insert);
         ps.setQueryTimeout(0);
-        for (int i=testCheckData(); i<100000; i++) {
+        for (int i=actual; i<count; i++) {
             ps.setInt(1,i);
             String s = getRandom();
             ps.setString(2, s);
@@ -93,12 +107,14 @@ public class CreateTestTable extends Def
                 System.out.print("\n"+(i+1));
                 ps.executeBatch();
                 ps.close();
+                con.commit();
                 ps = con.prepareStatement(insert);
                 ps.setQueryTimeout(0);
             }
 
         }
         ps.close();
+        con.setAutoCommit(commit);
         con.close();
     }
     



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message