01: package net.sourceforge.jaxor.db;
02:
03: import net.sourceforge.jaxor.api.ConnectionFactory;
04: import net.sourceforge.jaxor.util.SystemException;
05:
06: import javax.naming.Context;
07: import javax.naming.InitialContext;
08: import javax.naming.NamingException;
09: import javax.naming.NoInitialContextException;
10: import javax.sql.DataSource;
11: import java.sql.Connection;
12: import java.sql.SQLException;
13:
14: /**
15: * Author: mrettig
16: * Created: Jun 27, 2003
17: *
18: * Last Checkin: $Author: mrettig $
19: * Date: $Date: 2004/01/21 04:09:51 $
20: * Revision: $Revision: 1.3 $
21: */
22: public class DataSourceConnectionFactory implements ConnectionFactory {
23:
24: private final String _datasource;
25:
26: public DataSourceConnectionFactory(String datasource) {
27: _datasource = datasource;
28: }
29:
30: public Connection getConnection() {
31: try {
32: Context initContext = new InitialContext();
33: DataSource ds = (DataSource) initContext
34: .lookup(_datasource);
35: return ds.getConnection();
36: } catch (NoInitialContextException e) {
37: throw new SystemException(e);
38: } catch (NamingException hosed) {
39: throw new SystemException(hosed);
40: } catch (SQLException hosed) {
41: throw new SystemException(hosed);
42: }
43:
44: }
45: }
|