1 5 package org.h2.test.jdbc; 6 7 import java.sql.Connection ; 8 import java.sql.DatabaseMetaData ; 9 import java.sql.PreparedStatement ; 10 import java.sql.ResultSet ; 11 import java.sql.Statement ; 12 13 import org.h2.engine.Constants; 14 import org.h2.test.TestBase; 15 16 public class TestManyJdbcObjects extends TestBase { 17 18 public void test() throws Exception { 19 testNestedResultSets(); 20 testManyConnections(); 21 testOneConnectionPrepare(); 22 } 23 24 private void testNestedResultSets() throws Exception { 25 if(config.networked == false) { 26 return; 27 } 28 deleteDb("manyObjects"); 29 Connection conn = getConnection("manyObjects"); 30 DatabaseMetaData meta = conn.getMetaData(); 31 ResultSet rsTables = meta.getColumns(null, null, null, null); 32 while(rsTables.next()) { 33 meta.getExportedKeys(null, null, null); 34 meta.getImportedKeys(null, null, null); 35 } 36 conn.close(); 37 } 38 39 private void testManyConnections() throws Exception { 40 if(config.networked == false || config.memory) { 41 return; 42 } 43 deleteDb("manyObjects"); 47 Constants.RUN_FINALIZERS = false; 48 int connCount = getSize(4, 40); 49 Connection [] conn = new Connection [connCount]; 50 for(int i=0; i<connCount; i++) { 51 conn[i] = getConnection("manyObjects"); 52 } 53 int len = getSize(50, 500); 54 for (int j=0;j<len;j++) { 55 if((j % 10) == 0) { 56 trace("j=" + j); 57 } 58 for(int i=0; i<connCount; i++) { 59 conn[i].getMetaData().getSchemas().close(); 60 } 61 } 62 for(int i=0; i<connCount; i++) { 63 conn[i].close(); 64 } 65 Constants.RUN_FINALIZERS = true; 66 } 67 68 private void testOneConnectionPrepare() throws Exception { 69 deleteDb("manyObjects"); 70 Constants.RUN_FINALIZERS = false; 71 Connection conn = getConnection("manyObjects"); 72 PreparedStatement prep; 73 Statement stat; 74 int size = getSize(10, 1000); 75 for(int i=0; i<size; i++) { 76 conn.getMetaData(); 77 } 78 for(int i=0; i<size; i++) { 79 conn.createStatement(); 80 } 81 stat = conn.createStatement(); 82 stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"); 83 stat.execute("INSERT INTO TEST VALUES(1, 'Hello')"); 84 for(int i=0; i<size; i++) { 85 stat.executeQuery("SELECT * FROM TEST WHERE 1=0"); 86 } 87 for(int i=0; i<size; i++) { 88 stat.executeQuery("SELECT * FROM TEST"); 89 } 90 for(int i=0; i<size; i++) { 91 conn.prepareStatement("SELECT * FROM TEST"); 92 } 93 prep = conn.prepareStatement("SELECT * FROM TEST WHERE 1=0"); 94 for(int i=0; i<size; i++) { 95 prep.executeQuery(); 96 } 97 prep = conn.prepareStatement("SELECT * FROM TEST"); 98 for(int i=0; i<size; i++) { 99 prep.executeQuery(); 100 } 101 Constants.RUN_FINALIZERS = true; 102 conn.close(); 103 } 104 105 } 106 | Popular Tags |