1 16 17 package org.springframework.jdbc.datasource; 18 19 import java.io.PrintWriter ; 20 import java.sql.Connection ; 21 import java.sql.SQLException ; 22 23 import javax.sql.DataSource ; 24 25 import org.springframework.beans.factory.InitializingBean; 26 import org.springframework.util.Assert; 27 28 40 public class DelegatingDataSource implements DataSource , InitializingBean { 41 42 private DataSource targetDataSource; 43 44 45 49 public DelegatingDataSource() { 50 } 51 52 56 public DelegatingDataSource(DataSource targetDataSource) { 57 setTargetDataSource(targetDataSource); 58 } 59 60 61 64 public final void setTargetDataSource(DataSource targetDataSource) { 65 Assert.notNull(targetDataSource, "'targetDataSource' must not be null"); 66 this.targetDataSource = targetDataSource; 67 } 68 69 72 public DataSource getTargetDataSource() { 73 return this.targetDataSource; 74 } 75 76 public void afterPropertiesSet() { 77 if (getTargetDataSource() == null) { 78 throw new IllegalArgumentException ("Property 'targetDataSource' is required"); 79 } 80 } 81 82 83 public Connection getConnection() throws SQLException { 84 return getTargetDataSource().getConnection(); 85 } 86 87 public Connection getConnection(String username, String password) throws SQLException { 88 return getTargetDataSource().getConnection(username, password); 89 } 90 91 public PrintWriter getLogWriter() throws SQLException { 92 return getTargetDataSource().getLogWriter(); 93 } 94 95 public void setLogWriter(PrintWriter out) throws SQLException { 96 getTargetDataSource().setLogWriter(out); 97 } 98 99 public int getLoginTimeout() throws SQLException { 100 return getTargetDataSource().getLoginTimeout(); 101 } 102 103 public void setLoginTimeout(int seconds) throws SQLException { 104 getTargetDataSource().setLoginTimeout(seconds); 105 } 106 107 } 108 | Popular Tags |