1 24 25 package org.objectweb.cjdbc.scenario.raidb1.driver; 26 27 import java.sql.Connection ; 28 import java.sql.DriverManager ; 29 import java.sql.ResultSet ; 30 import java.sql.Statement ; 31 import java.util.ArrayList ; 32 import java.util.Properties ; 33 34 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb1Template; 35 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 36 37 43 public class AutoCommitScenario extends SimpleRaidb1Template 44 { 45 50 public void testAutoCommit() throws Exception 51 { 52 cm.loadVirtualDatabases(controller, "myDB", 53 "hsqldb-raidb1-pessimistic-roundrobin-wfall.xml"); 54 mainVdb = controller.getVirtualDatabase("myDB"); 55 mainVdb.enableAllBackends(); 56 57 Connection aConnection = getCJDBCConnection(); 58 Statement 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 expected) 70 { 71 72 } 73 74 aConnection.close(); 75 76 Properties props = new Properties (); 77 props.put("user", "TEST"); 78 props.put("password", ""); 79 Connection hsqlCon = DriverManager.getConnection( 80 "jdbc:hsqldb:hsql://localhost:9001", props); 81 82 ResultSet set = hsqlCon.createStatement() 83 .executeQuery("Select * from test"); 84 ArrayList list = ScenarioUtility.convertResultSet(set); 85 System.out.println(list); 86 assertTrue(list.size() == 1); 87 } 88 } | Popular Tags |