00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.objectweb.jonas.jdbc;
00027
00028 import java.io.PrintWriter;
00029 import java.io.Serializable;
00030
00031 import java.sql.Connection;
00032 import java.sql.SQLException;
00033
00034 import javax.naming.Reference;
00035
00036 import javax.resource.Referenceable;
00037 import javax.resource.ResourceException;
00038 import javax.resource.spi.ConnectionManager;
00039
00040 import org.objectweb.util.monolog.api.BasicLevel;
00041
00042
00050 public class DataSourceImpl
00051 implements javax.sql.DataSource, Serializable, Referenceable {
00052
00053 private ConnectionManager cm;
00054 private ManagedConnectionFactoryImpl mcf;
00055 private PrintWriter pw;
00056 private Reference reference;
00057
00058 int loginTimeout = 0;
00059
00060 public DataSourceImpl(ManagedConnectionFactoryImpl _mcf, ConnectionManager _cm) {
00061 if(_cm == null) {
00062 cm = new ConnectionManagerImpl();
00063 } else {
00064 cm = _cm;
00065 }
00066 mcf = _mcf;
00067 }
00068
00069 public Connection getConnection()
00070 throws SQLException {
00071 mcf.trace.log(BasicLevel.DEBUG,"");
00072 try {
00073 Connection con = (Connection) cm.allocateConnection(mcf, null);
00074 if (con == null) {
00075 SQLException se = new SQLException("Null connection object returned");
00076 throw se;
00077 }
00078 return con;
00079 } catch(ResourceException re) {
00080 throw new SQLException(re.getMessage());
00081 }
00082 }
00083
00084 public Connection getConnection(String user, String pwd)
00085 throws SQLException {
00086 mcf.trace.log(BasicLevel.DEBUG,""+user);
00087 try {
00088 ConnectionRequestInfoImpl info = new ConnectionRequestInfoImpl(user, pwd);
00089 Connection con = (Connection) cm.allocateConnection(mcf, info);
00090 if (con == null) {
00091 SQLException se = new SQLException("Null connection object returned");
00092 throw se;
00093 }
00094 return con;
00095 } catch(ResourceException re) {
00096 throw new SQLException(re.getMessage());
00097 }
00098 }
00099
00100 public int getLoginTimeout()
00101 throws SQLException {
00102 return loginTimeout;
00103 }
00104
00105 public PrintWriter getLogWriter()
00106 throws SQLException {
00107 return pw;
00108 }
00109
00110 public Reference getReference() {
00111 return reference;
00112 }
00113
00114 public void setLoginTimeout(int _loginTimeout)
00115 throws SQLException {
00116 loginTimeout = _loginTimeout;
00117 }
00118
00119 public void setLogWriter(PrintWriter _pw)
00120 throws SQLException {
00121 pw = _pw;
00122 }
00123
00124 public void setReference(Reference _ref) {
00125 reference = _ref;
00126 }
00127
00128
00129
00130 public String getMapperName() {
00131 String mn = mcf.getMapperName();
00132 mcf.trace.log(BasicLevel.DEBUG, mn);
00133 return mn;
00134 }
00135
00136 }