1 24 25 package org.objectweb.cjdbc.scenario.raidb0; 26 27 import java.sql.Connection ; 28 29 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb0Template; 30 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 31 32 40 public class Raidb0BasicConnectScenario extends SimpleRaidb0Template 41 { 42 43 48 public void testFailOverWithRandomWaitPool() throws Exception 49 { 50 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 tableName) throws Exception 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 documentUpdate = "update DOCUMENT set ADDRESSID=0"; 69 String productUpdate = "update PRODUCT set NAME='product'"; 70 71 private void queryUpdateTable(String tableName, boolean autoCommit, 72 boolean prepare) throws Exception 73 { 74 Connection 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 |