1 24 25 package org.objectweb.cjdbc.scenario.tools.testlet; 26 27 import java.sql.Connection ; 28 import java.sql.DriverManager ; 29 import java.sql.SQLException ; 30 import java.util.Properties ; 31 32 import org.objectweb.cjdbc.controller.backend.DatabaseBackend; 33 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase; 34 35 41 public abstract class AbstractVdbTestLet 42 extends 43 AbstractTestLet 44 { 45 46 protected VirtualDatabase vdb; 47 48 53 public AbstractVdbTestLet(VirtualDatabase vdb) 54 { 55 super(); 56 this.vdb = vdb; 57 } 58 59 66 public Connection getDatabaseConnection(String url) throws SQLException 67 { 68 Properties props = new Properties (); 69 props.put("user", "test"); 70 props.put("password", ""); 71 Connection con = DriverManager.getConnection(url, props); 72 return con; 73 } 74 75 82 public Connection getCJDBCConnection(Properties props) throws Exception 83 { 84 Properties p = new Properties (); 85 p.put("user", "user"); 86 p.put("password", ""); 87 p.putAll(props); 88 Class.forName("org.objectweb.cjdbc.driver.Driver"); 89 Connection con = DriverManager.getConnection("jdbc:cjdbc://localhost/myDB",p); 90 return con; 91 } 92 93 100 public Connection getBackendConnection(int index) throws Exception 101 { 102 return getDatabaseConnection(getBackend(index).getURL()); 103 } 104 105 112 public DatabaseBackend getBackend(int index) throws Exception 113 { 114 DatabaseBackend b = ((DatabaseBackend)vdb.getBackends().get(index)); 115 System.out.println("Accessing backend:"+b.getName()); 116 return b; 117 } 118 } | Popular Tags |