1 22 package org.jboss.test.cmp2.dbschema.util; 23 24 import net.sourceforge.junitejb.EJBTestCase; 25 26 import javax.sql.DataSource ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import java.sql.Connection ; 30 import java.sql.SQLException ; 31 32 33 37 public class AbstractDBSchemaTest 38 extends EJBTestCase 39 { 40 protected String datasourceName = "java:/DefaultDS"; 41 protected DataSource datasource; 42 43 public AbstractDBSchemaTest(String s) 44 { 45 super(s); 46 } 47 48 protected Connection getConnection() 49 throws NamingException , SQLException 50 { 51 return getDataSource().getConnection(); 52 } 53 54 protected DataSource getDataSource() throws NamingException 55 { 56 if(datasource == null) 57 { 58 datasource = getDataSource(datasourceName); 59 } 60 return datasource; 61 } 62 63 protected DataSource getDataSource(String datasource) throws NamingException 64 { 65 InitialContext ic = null; 66 try 67 { 68 ic = new InitialContext (); 69 return (DataSource )ic.lookup(datasource); 70 } 71 finally 72 { 73 if(ic != null) 74 try 75 { 76 ic.close(); 77 } 78 catch(Exception ignore){} 79 } 80 } 81 } 82 | Popular Tags |