KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > tools > testlet > MacroStatementTestLet


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 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): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.tools.testlet;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29 import java.sql.Statement JavaDoc;
30 import java.util.Properties JavaDoc;
31
32 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
33
34 /**
35  * This class defines a MacroStatementTestLet
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
38  * @version 1.0
39  */

40 public class MacroStatementTestLet extends AbstractVdbTestLet
41 {
42   static final String JavaDoc UPDATE = "update ADDRESS set FIRSTNAME=";
43
44   /**
45    * Creates a new <code>MacroStatementTestLet</code> object
46    *
47    * @param vdb virtual database
48    */

49   public MacroStatementTestLet(VirtualDatabase vdb)
50   {
51     super(vdb);
52     set(MACRO_NAME, "now()");
53     set(USE_OPTIMIZED_STATEMENT, "true");
54     set(USE_PREPARED_STATEMENT, "true");
55     set(USE_UPDATE_STATEMENT, "true");
56   }
57
58   /**
59    * @see org.objectweb.cjdbc.scenario.tools.testlet.AbstractTestLet#execute()
60    */

61   public void execute() throws Exception JavaDoc
62   {
63     boolean useOptimized = getConfigBoolean(USE_OPTIMIZED_STATEMENT);
64     boolean usePrepared = getConfigBoolean(USE_PREPARED_STATEMENT);
65     boolean useUpdate = getConfigBoolean(USE_UPDATE_STATEMENT);
66     String JavaDoc statement = UPDATE + ((String JavaDoc) config.get(MACRO_NAME));
67
68     Properties JavaDoc props = new Properties JavaDoc();
69     if (useOptimized)
70       props.put("driverProcessed", "false");
71     Connection JavaDoc con = getCJDBCConnection(props);
72     if (usePrepared)
73     {
74       PreparedStatement JavaDoc st = con.prepareStatement(statement);
75       if (useUpdate)
76         st.executeUpdate();
77       else
78         st.executeQuery();
79     }
80     else
81     {
82       Statement JavaDoc st = con.createStatement();
83       if (useUpdate)
84         st.executeUpdate(statement);
85       else
86         st.executeQuery(statement);
87     }
88   }
89
90 }
Popular Tags