1 17 18 package org.objectweb.jac.aspects.distrans.persistence; 19 20 import java.sql.Connection ; 21 import java.sql.SQLException ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.enhydra.jdbc.pool.StandardXAPoolDataSource; 26 import org.enhydra.jdbc.standard.StandardXADataSource; 27 28 39 public class XAPoolCache { 40 41 46 private static Map pools = new HashMap (); 47 48 49 private final static int POOL_SIZE = 4; 50 51 52 60 public static Connection getConnection( StandardXADataSource ds ) 61 throws SQLException { 62 63 64 Connection connection = (Connection ) pools.get(ds); 65 if ( connection!= null && !connection.isClosed() ) { 66 return connection; 67 } 68 69 StandardXAPoolDataSource pool = 70 new StandardXAPoolDataSource(POOL_SIZE); 71 pool.setUser( ds.getUser() ); 72 pool.setPassword( ds.getPassword() ); 73 pool.setTransactionManager( ds.getTransactionManager() ); 74 pool.setDataSource(ds); 75 76 connection = pool.getConnection(); 77 pools.put(ds,connection); 78 79 return connection; 80 } 81 82 } 83 | Popular Tags |