1 16 17 package org.springframework.orm.hibernate3; 18 19 import java.sql.Connection ; 20 import java.sql.SQLException ; 21 import java.util.Properties ; 22 23 import javax.sql.DataSource ; 24 25 import org.hibernate.HibernateException; 26 import org.hibernate.connection.ConnectionProvider; 27 import org.hibernate.util.JDBCExceptionReporter; 28 29 38 public class LocalDataSourceConnectionProvider implements ConnectionProvider { 39 40 private DataSource dataSource; 41 42 private DataSource dataSourceToUse; 43 44 45 public void configure(Properties props) throws HibernateException { 46 this.dataSource = LocalSessionFactoryBean.getConfigTimeDataSource(); 47 if (this.dataSource == null) { 49 throw new HibernateException("No local DataSource found for configuration - " + 50 "dataSource property must be set on LocalSessionFactoryBean"); 51 } 52 this.dataSourceToUse = getDataSourceToUse(this.dataSource); 53 } 54 55 64 protected DataSource getDataSourceToUse(DataSource originalDataSource) { 65 return originalDataSource; 66 } 67 68 71 public DataSource getDataSource() { 72 return dataSource; 73 } 74 75 79 public Connection getConnection() throws SQLException { 80 try { 81 return this.dataSourceToUse.getConnection(); 82 } 83 catch (SQLException ex) { 84 JDBCExceptionReporter.logExceptions(ex); 85 throw ex; 86 } 87 } 88 89 93 public void closeConnection(Connection con) throws SQLException { 94 try { 95 con.close(); 96 } 97 catch (SQLException ex) { 98 JDBCExceptionReporter.logExceptions(ex); 99 throw ex; 100 } 101 } 102 103 107 public void close() { 108 } 109 110 115 public boolean supportsAggressiveRelease() { 116 return false; 117 } 118 119 } 120 | Popular Tags |