1 7 package org.jboss.test.cmp2.dbschema.util; 8 9 import net.sourceforge.junitejb.EJBTestCase; 10 11 import javax.sql.DataSource ; 12 import javax.naming.InitialContext ; 13 import javax.naming.NamingException ; 14 import java.sql.Connection ; 15 import java.sql.SQLException ; 16 17 18 22 public class AbstractDBSchemaTestCase 23 extends EJBTestCase 24 { 25 protected String datasourceName = "java:/DefaultDS"; 26 protected DataSource datasource; 27 28 public AbstractDBSchemaTestCase(String s) 29 { 30 super(s); 31 } 32 33 protected Connection getConnection() 34 throws NamingException , SQLException 35 { 36 return getDataSource().getConnection(); 37 } 38 39 protected DataSource getDataSource() throws NamingException 40 { 41 if(datasource == null) 42 { 43 datasource = getDataSource(datasourceName); 44 } 45 return datasource; 46 } 47 48 protected DataSource getDataSource(String datasource) throws NamingException 49 { 50 InitialContext ic = null; 51 try 52 { 53 ic = new InitialContext (); 54 return (DataSource )ic.lookup(datasource); 55 } 56 finally 57 { 58 if(ic != null) 59 try 60 { 61 ic.close(); 62 } 63 catch(Exception ignore){} 64 } 65 } 66 } 67 | Popular Tags |