KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > loadbalancer > EnableDisableBackendScenario


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.raidb1.loadbalancer;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29 import java.sql.Statement JavaDoc;
30
31 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryTemplate;
32 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
33
34 /**
35  * This class defines a EnableDisableBackendScenario
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
38  * @version 1.0
39  */

40 public class EnableDisableBackendScenario extends Raidb1RecoveryTemplate
41 {
42   /**
43    * Marc got a dead lock on this after exception
44    *
45    * @throws Exception if fails
46    */

47   public void testDeadLockInUniqueConstraintViolation() throws Exception JavaDoc
48   {
49     Connection JavaDoc aConnection = getCJDBCConnection();
50     Statement JavaDoc stmt = aConnection.createStatement();
51     stmt
52         .executeUpdate("create table test2 (id int, CONSTRAINT test_PK PRIMARY KEY(id))");
53     PreparedStatement JavaDoc insert = aConnection
54         .prepareStatement("insert into test2 (id) values (?)");
55     insert.setInt(1, 1);
56     insert.executeUpdate();
57
58     mainVdb.disableBackendWithCheckpoint("localhost");
59     mainVdb.enableBackendFromCheckpoint("localhost");
60
61     String JavaDoc query = "select * from test2";
62
63     Connection JavaDoc hsqlcon = getHypersonicConnection(9001);
64     ScenarioUtility.displaySingleQueryResult(query, hsqlcon);
65     Connection JavaDoc hsqlcon2 = getHypersonicConnection(9002);
66     ScenarioUtility.displaySingleQueryResult(query, hsqlcon2);
67
68     PreparedStatement JavaDoc insert2 = aConnection
69         .prepareStatement("insert into test2 (id) values (?)");
70     insert2.setInt(1, 2);
71     insert2.executeUpdate();
72
73     hsqlcon = getHypersonicConnection(9001);
74     ScenarioUtility.displaySingleQueryResult(query, hsqlcon);
75     hsqlcon2 = getHypersonicConnection(9002);
76     ScenarioUtility.displaySingleQueryResult(query, hsqlcon2);
77   }
78 }
Popular Tags