1 24 25 package org.objectweb.cjdbc.scenario.raidb1.driver; 26 27 import java.sql.Connection ; 28 import java.util.Properties ; 29 30 import org.objectweb.cjdbc.driver.ControllerInfo; 31 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryTemplate; 32 import org.objectweb.cjdbc.scenario.tools.util.RequestSender; 33 34 40 public class CompiledPreparedStatementScenario extends Raidb1RecoveryTemplate 41 { 42 43 static final String CJDBC_PREPARED_OPTIMIZED = "cjdbc with preparedstatement optimized"; 44 static final String CJDBC_PREPARED_NO_OPTIMIZED = "cjdbc with preparedstatement non optimized"; 45 static final String CJDBC_NO_PREPARED = "cjdbc without preparedstatement"; 46 static final String DATABASE_PREPARED = "hsqldb with preparedstatement"; 47 static final String DATABASE_NO_PREPARED = "hsqldb without preparedstatement"; 48 static final int NUMBER_OF_EXECUTIONS = 15000; 49 50 55 public void testComparePreparedStatementOptimization() throws Exception 56 { 57 Connection con = getCJDBCConnection(); 59 dotest(CJDBC_NO_PREPARED, con, true); 60 con.close(); 61 62 con = getCJDBCConnection(); 64 dotest(CJDBC_PREPARED_NO_OPTIMIZED, con, true); 65 con.close(); 66 Properties props = new Properties (); 67 props.put("user", "user"); 68 props.put("password", ""); 69 props.put("driverProcessed", "false"); 70 con = getCJDBCConnection(new ControllerInfo[]{new ControllerInfo( 71 "localhost", 25322)}, "myDB", props); 72 73 dotest(CJDBC_PREPARED_OPTIMIZED, con, true); 75 con.close(); 76 77 con = getHypersonicConnection(9001); 79 dotest(DATABASE_PREPARED, con, true); 80 con.close(); 81 con = getHypersonicConnection(9001); 82 dotest(DATABASE_NO_PREPARED, con, false); 83 con.close(); 84 } 85 86 private void dotest(String name, Connection con, boolean usePreparedStatement) 87 throws Exception 88 { 89 System.gc(); 90 RequestSender sender = new RequestSender(con); 91 sender.setLoopInThread(NUMBER_OF_EXECUTIONS); 92 sender.setRequestInterval(-1); 93 sender.setUsePreparedStatement(usePreparedStatement); 94 Thread t = new Thread (sender); 95 t.start(); 96 sender.setQuit(true); 97 t.join(); 98 System.out.println("Test [" + name + "] lasted:" + sender.getRuntime()); 99 assertTrue("Got errors", sender.getExceptions().size() == 0); 100 } 101 } | Popular Tags |