KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb0 > Raidb0BasicConnectScenario


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.raidb0;
26
27 import java.sql.Connection JavaDoc;
28
29 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb0Template;
30 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
31
32 /**
33  * This test will try to update and execute queries on tables that are on
34  * different backend each time. It will perform the test in autocommit and
35  * transaction mode.
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
38  * @version 1.0
39  */

40 public class Raidb0BasicConnectScenario extends SimpleRaidb0Template
41 {
42
43   /**
44    * Test CJDBC basic raidb0 with randomwait pool
45    *
46    * @throws Exception if fails
47    */

48   public void testFailOverWithRandomWaitPool() throws Exception JavaDoc
49   {
50     //Load database
51
cm.loadVirtualDatabases(controller, "myDB",
52         "hsqldb-raidb0-randomwaitpool.xml");
53     mainVdb = controller.getVirtualDatabase("myDB");
54     mainVdb.enableAllBackends();
55
56     completeTest("PRODUCT");
57     completeTest("DOCUMENT");
58   }
59
60   private void completeTest(String JavaDoc tableName) throws Exception JavaDoc
61   {
62     queryUpdateTable(tableName, true, true);
63     queryUpdateTable(tableName, true, false);
64     queryUpdateTable(tableName, false, true);
65     queryUpdateTable(tableName, false, false);
66   }
67
68   String JavaDoc documentUpdate = "update DOCUMENT set ADDRESSID=0";
69   String JavaDoc productUpdate = "update PRODUCT set NAME='product'";
70
71   private void queryUpdateTable(String JavaDoc tableName, boolean autoCommit,
72       boolean prepare) throws Exception JavaDoc
73   {
74     Connection JavaDoc con = getCJDBCConnection();
75     con.setAutoCommit(autoCommit);
76     ScenarioUtility.displaySingleQueryResult("Select * from " + tableName, con,
77         prepare);
78     if (tableName.equalsIgnoreCase("DOCUMENT"))
79     {
80       if (prepare)
81         con.prepareStatement(documentUpdate).executeUpdate();
82       else
83         con.createStatement().executeUpdate(documentUpdate);
84     }
85     if (tableName.equalsIgnoreCase("PRODUCT"))
86     {
87       if (prepare)
88         con.prepareStatement(productUpdate).executeUpdate();
89       else
90         con.createStatement().executeUpdate(productUpdate);
91     }
92     ScenarioUtility.displaySingleQueryResult("Select * from " + tableName, con,
93         prepare);
94     if (!autoCommit)
95       con.commit();
96     con.close();
97   }
98 }
Popular Tags