01: package simpleorm.core;
02:
03: import java.sql.Connection;
04: import java.util.Properties;
05: import javax.sql.DataSource;
06:
07: /**
08: * SDataSource for using javax.sql.DataSource.
09: *
10: * If you are using Java 1.3 or earlier just remove this class from the distribution,
11: * it is not needed.<p>
12: * <pre>
13: * Context ctx = new InitialContext();
14: * DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
15: * SDataSource sds = new SDataSourceJavaX(ds);
16: * SConnection.attach(sds, "MyCon");
17: * </pre>
18: */
19: public class SDataSourceJavaX extends SDataSource {
20:
21: DataSource dataSource;
22:
23: public DataSource getDataSource() {
24: return dataSource;
25: }
26:
27: public void setDataSource(DataSource dataSource) {
28: this .dataSource = dataSource;
29: }
30:
31: public SDataSourceJavaX(DataSource dataSource) {
32: this .dataSource = dataSource;
33: }
34:
35: protected Connection openDBConnection() {
36: Connection con;
37: try {
38: con = dataSource.getConnection();
39: } catch (Exception ex) {
40: throw new SException.JDBC("Opening " + dataSource, ex);
41: }
42: return con;
43:
44: }
45: }
|