KickJava   Java API By Example, From Geeks To Geeks.

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


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.driver;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.DriverManager JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.sql.Statement JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb1Template;
35 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
36
37 /**
38  * This class defines a AutoCommitScenario
39  *
40  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
41  * @version 1.0
42  */

43 public class AutoCommitScenario extends SimpleRaidb1Template
44 {
45   /**
46    * Test change of autocommit is done properly.
47    *
48    * @throws Exception if fails
49    */

50   public void testAutoCommit() throws Exception JavaDoc
51   {
52     cm.loadVirtualDatabases(controller, "myDB",
53         "hsqldb-raidb1-pessimistic-roundrobin-wfall.xml");
54     mainVdb = controller.getVirtualDatabase("myDB");
55     mainVdb.enableAllBackends();
56
57     Connection JavaDoc aConnection = getCJDBCConnection();
58     Statement JavaDoc stmt = aConnection.createStatement();
59     stmt.executeUpdate("create table test (id int)");
60     aConnection.setAutoCommit(false);
61     stmt.executeUpdate("insert into test (id) values (2)");
62     aConnection.setAutoCommit(true);
63
64     try
65     {
66       aConnection.commit();
67       fail("Expected exception here because committing an autocommit connection");
68     }
69     catch (Exception JavaDoc expected)
70     {
71
72     }
73
74     aConnection.close();
75
76     Properties JavaDoc props = new Properties JavaDoc();
77     props.put("user", "TEST");
78     props.put("password", "");
79     Connection JavaDoc hsqlCon = DriverManager.getConnection(
80         "jdbc:hsqldb:hsql://localhost:9001", props);
81
82     ResultSet JavaDoc set = hsqlCon.createStatement()
83         .executeQuery("Select * from test");
84     ArrayList JavaDoc list = ScenarioUtility.convertResultSet(set);
85     System.out.println(list);
86     assertTrue(list.size() == 1);
87   }
88 }
Popular Tags