1 22 package org.jboss.test.jmx.ejb; 23 24 import java.util.Collection ; 25 import javax.ejb.*; 26 import javax.sql.*; 27 import java.sql.*; 28 import javax.naming.*; 29 30 31 47 public class TestDataSourceBean 48 implements SessionBean 49 { 50 58 public void testDataSource(String dsName) 59 { 60 try 61 { 62 InitialContext ctx = new InitialContext(); 63 DataSource ds = (DataSource)ctx.lookup(dsName); 64 if (ds == null) { 65 throw new Exception ("DataSource lookup was null"); 66 } 67 Connection c = ds.getConnection(); 68 if (c == null) { 69 throw new Exception ("Connection was null!!"); 70 } 71 DatabaseMetaData dmd = c.getMetaData(); 72 ResultSet rs = dmd.getTables(null, null, "%", null); 73 c.close(); 74 } catch (Exception e) 75 { 76 throw new EJBException(e); 77 } 78 } 79 80 87 public boolean isBound(String name) 88 { 89 try 90 { 91 InitialContext ctx = new InitialContext(); 92 Object ds = ctx.lookup(name); 93 if (ds == null) { 94 return false; 95 } 96 return true; 97 } 98 catch (NamingException e) 99 { 100 return false; 101 } 103 } 104 105 108 public void ejbCreate() 109 throws CreateException 110 { 111 } 112 113 public void ejbActivate() {} 115 public void ejbPassivate() {} 116 public void setSessionContext(SessionContext ctx) {} 117 118 122 public void ejbRemove() {} 123 124 } 125 | Popular Tags |