1 21 package oracle.toplink.essentials.internal.ejb.cmp3.jdbc.base; 23 24 import java.io.PrintWriter ; 25 import java.sql.Connection ; 26 import java.sql.SQLException ; 27 import java.sql.DriverManager ; 28 import javax.sql.DataSource ; 29 import oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.TransactionManagerImpl; 30 31 36 public class DataSourceImpl implements DataSource { 37 String dsName; 38 String url; 39 String userName; 40 String password; 41 42 TransactionManagerImpl tm; 45 46 47 48 49 private void debug(String s) { 50 System.out.println(s); 51 } 52 53 56 public DataSourceImpl(String dsName, String url, String userName, String password) { 57 this.dsName = dsName; 58 this.url = url; 59 this.userName = userName; 60 this.password = password; 61 } 62 63 66 public String getName() { 67 return this.dsName; 68 } 69 70 74 public void setTransactionManager(TransactionManagerImpl tm) { 75 this.tm = tm; 76 } 77 78 81 public Connection internalGetConnection(String userName, String password) throws SQLException { 82 return DriverManager.getConnection(this.url, userName, password); 83 } 84 85 88 public Connection internalGetConnection() throws SQLException { 89 return internalGetConnection(this.userName, this.password); 90 } 91 92 95 public boolean isTransactional() { 96 return tm != null; 97 } 98 99 100 101 102 103 106 public Connection getConnection() throws SQLException { 107 return getConnection(this.userName, this.password); 108 } 109 110 113 public Connection getConnection(String userName, String password) throws SQLException { 114 if (isTransactional() && tm.isTransactionActive()) { 115 return tm.getConnection(this, userName, password); 118 } else { debug("Ds - Allocating new non-tx connection"); 120 } 121 return internalGetConnection(userName, password); 122 } 123 124 127 public PrintWriter getLogWriter() throws SQLException { 128 return DriverManager.getLogWriter(); 129 } 130 131 134 public void setLogWriter(PrintWriter out) throws SQLException { 135 DriverManager.setLogWriter(out); 136 } 137 138 141 public int getLoginTimeout() throws SQLException { 142 return DriverManager.getLoginTimeout(); 143 } 144 145 148 public void setLoginTimeout(int seconds) throws SQLException { 149 DriverManager.setLoginTimeout(seconds); 150 } 151 } 152 | Popular Tags |