1 16 17 package org.springframework.orm.hibernate; 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 net.sf.hibernate.HibernateException; 26 import net.sf.hibernate.connection.ConnectionProvider; 27 import net.sf.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 public Connection getConnection() throws SQLException { 76 try { 77 return this.dataSourceToUse.getConnection(); 78 } 79 catch (SQLException ex) { 80 JDBCExceptionReporter.logExceptions(ex); 81 throw ex; 82 } 83 } 84 85 public void closeConnection(Connection con) throws SQLException { 86 try { 87 con.close(); 88 } 89 catch (SQLException ex) { 90 JDBCExceptionReporter.logExceptions(ex); 91 throw ex; 92 } 93 } 94 95 public void close() { 96 } 98 99 } 100 | Popular Tags |