KickJava   Java API By Example, From Geeks To Geeks.

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


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.CallableStatement JavaDoc;
28 import java.sql.Connection JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.sql.Statement JavaDoc;
31
32 /**
33  * This class defines a ProcedureTestLet
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  * @version 1.0
37  */

38 public class ProcedureTestLet extends AbstractConnectionTestLet
39 {
40
41   /**
42    * Creates a new <code>ProcedureTestLet</code> object
43    *
44    * @param con connection to use for testing
45    */

46   public ProcedureTestLet(Connection JavaDoc con)
47   {
48     super(con);
49     config.put(PROCEDURE_NAME, "SIN(100)");
50     config.put(USE_PREPARED_STATEMENT, Boolean.FALSE);
51     config.put(USE_UPDATE_STATEMENT, Boolean.FALSE);
52   }
53
54   /**
55    * @see org.objectweb.cjdbc.scenario.tools.testlet.AbstractTestLet#execute()
56    */

57   public void execute() throws Exception JavaDoc
58   {
59     boolean useStatement = ((Boolean JavaDoc) config.get(USE_PREPARED_STATEMENT))
60         .booleanValue();
61     boolean useUpdate = ((Boolean JavaDoc) config.get(USE_UPDATE_STATEMENT))
62         .booleanValue();
63     ResultSet JavaDoc rs = null;
64     int updated = -10;
65     String JavaDoc procedure = "{call " + config.get(PROCEDURE_NAME);
66     System.out.println(procedure);
67     if (useStatement)
68     {
69       CallableStatement JavaDoc cs = jdbcConnection.prepareCall(procedure);
70       if (!useUpdate)
71         rs = cs.executeQuery();
72       else
73         updated = cs.executeUpdate();
74     }
75     else
76     {
77       Statement JavaDoc statement = jdbcConnection.createStatement();
78       if (!useUpdate)
79         rs = statement.executeQuery(procedure);
80       else
81         updated = statement.executeUpdate(procedure);
82     }
83     if (!useUpdate)
84     {
85       assertTrue("No result set", rs.next());
86       String JavaDoc result = rs.getString(1);
87       System.out.println(result);
88     }
89     else
90     {
91       System.out.println(updated + " rows updated");
92       assertTrue("Expected updated value:", updated >= -1);
93     }
94   }
95
96 }
Popular Tags