1 package org.hibernate.test.tm; 3 4 import java.sql.Connection ; 5 import java.sql.SQLException ; 6 import java.util.Properties ; 7 8 import org.hibernate.HibernateException; 9 import org.hibernate.connection.ConnectionProvider; 10 import org.hibernate.connection.ConnectionProviderFactory; 11 12 15 public class DummyConnectionProvider implements ConnectionProvider { 16 17 ConnectionProvider cp; 18 boolean isTransaction; 19 20 public void configure(Properties props) throws HibernateException { 21 cp = ConnectionProviderFactory.newConnectionProvider(); 22 } 23 24 public Connection getConnection() throws SQLException { 25 DummyTransactionManager dtm = DummyTransactionManager.INSTANCE; 26 if ( dtm!=null && dtm.getCurrent()!=null && dtm.getCurrent().getConnection()!=null ) { 27 isTransaction = true; 28 return dtm.getCurrent().getConnection(); 29 } 30 else { 31 isTransaction = false; 32 return cp.getConnection(); 33 } 34 } 35 36 public void closeConnection(Connection conn) throws SQLException { 37 if (!isTransaction) conn.close(); 38 } 39 40 public void close() throws HibernateException { 41 42 } 43 44 public boolean supportsAggressiveRelease() { 45 return true; 46 } 47 48 } 49 | Popular Tags |