KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > driver > CompiledPreparedStatementScenario


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.scenario.raidb1.driver;
26
27 import java.sql.Connection JavaDoc;
28 import java.util.Properties JavaDoc;
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 /**
35  * This class defines a CompiledPreparedStatementScenario
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
38  * @version 1.0
39  */

40 public class CompiledPreparedStatementScenario extends Raidb1RecoveryTemplate
41 {
42
43   static final String JavaDoc CJDBC_PREPARED_OPTIMIZED = "cjdbc with preparedstatement optimized";
44   static final String JavaDoc CJDBC_PREPARED_NO_OPTIMIZED = "cjdbc with preparedstatement non optimized";
45   static final String JavaDoc CJDBC_NO_PREPARED = "cjdbc without preparedstatement";
46   static final String JavaDoc DATABASE_PREPARED = "hsqldb with preparedstatement";
47   static final String JavaDoc DATABASE_NO_PREPARED = "hsqldb without preparedstatement";
48   static final int NUMBER_OF_EXECUTIONS = 15000;
49
50   /**
51    * Test prepared statements with/without jaco's optimization
52    *
53    * @throws Exception if fails
54    */

55   public void testComparePreparedStatementOptimization() throws Exception JavaDoc
56   {
57     // No prepared statement
58
Connection JavaDoc con = getCJDBCConnection();
59     dotest(CJDBC_NO_PREPARED, con, true);
60     con.close();
61
62     // prepared statement non optimized
63
con = getCJDBCConnection();
64     dotest(CJDBC_PREPARED_NO_OPTIMIZED, con, true);
65     con.close();
66     Properties JavaDoc props = new Properties JavaDoc();
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     // prepared statement optimized
74
dotest(CJDBC_PREPARED_OPTIMIZED, con, true);
75     con.close();
76
77     // Compare with hypersonic
78
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 JavaDoc name, Connection JavaDoc con, boolean usePreparedStatement)
87       throws Exception JavaDoc
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 JavaDoc t = new Thread JavaDoc(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