1 64 65 package com.jcorporate.expresso.core.db; 66 67 import org.apache.log4j.Logger; 68 69 import javax.sql.DataSource ; 70 import java.io.PrintWriter ; 71 import java.sql.Connection ; 72 import java.sql.SQLException ; 73 74 98 public class SimpleDataSource implements DataSource { 99 private java.io.PrintWriter logWriter = null; 100 101 104 private static final Logger log = Logger.getLogger(SimpleDataSource.class); 105 106 109 private DBConnectionPool poolInstance; 110 111 112 118 public SimpleDataSource(DBConnectionPool newPoolInstance) { 119 poolInstance = newPoolInstance; 120 } 121 122 128 protected DBConnectionPool getConnectionPool() { 129 return poolInstance; 130 } 131 132 139 public Connection getConnection() throws SQLException { 140 if (logWriter != null) { 141 logWriter.println("DataConnectionPool: Retrieving new Connection"); 142 } 143 144 try { 145 return poolInstance.buildNewConnection().getConnection(); 146 } catch (DBException ex) { 147 log.error("Error getting connection", ex); 148 throw new SQLException (ex.getMessage()); 149 } 150 } 151 152 165 public Connection getConnection(String username, String password) throws SQLException { 166 log.warn("getConnection(username,password) not directly implemented. falling back to getConnection()"); 167 168 return getConnection(); 169 } 170 171 177 public PrintWriter getLogWriter() throws SQLException { 178 return logWriter; 179 } 180 181 187 public void setLogWriter(PrintWriter out) throws SQLException { 188 logWriter = out; 189 } 190 191 197 public void setLoginTimeout(int seconds) throws SQLException { 198 log.warn("setLoginTimeout not yet implemented"); 199 } 200 201 207 public int getLoginTimeout() throws SQLException { 208 log.warn("getLoginTimeout not yet implemented"); 209 return 0; 210 } 211 } | Popular Tags |