1 25 26 package org.snipsnap.jdbc; 27 28 import org.snipsnap.util.ConnectionManager; 29 30 import javax.sql.DataSource ; 31 import java.io.PrintWriter ; 32 import java.sql.Connection ; 33 import java.sql.SQLException ; 34 35 41 42 public class LazyDataSource implements DataSource { 43 private DataSource ds; 44 45 private DataSource getDataSource() { 46 if (null == ds) { 47 ds = ConnectionManager.getDataSource(); 48 } 49 return ds; 50 } 51 52 public Connection getConnection() throws SQLException { 53 return getDataSource().getConnection(); 54 } 55 56 public Connection getConnection(String username, String password) 57 throws SQLException { 58 return getDataSource().getConnection(username, password); 59 } 60 61 public PrintWriter getLogWriter() throws SQLException { 62 return getDataSource().getLogWriter(); 63 } 64 65 public void setLogWriter(PrintWriter out) throws SQLException { 66 getDataSource().setLogWriter(out); 67 } 68 69 public void setLoginTimeout(int seconds) throws SQLException { 70 getDataSource().setLoginTimeout(seconds); 71 } 72 73 public int getLoginTimeout() throws SQLException { 74 return getDataSource().getLoginTimeout(); 75 } 76 77 } 78 | Popular Tags |