1 6 package org.logicalcobwebs.proxool; 7 8 import org.logicalcobwebs.dbscript.ConnectionAdapterIF; 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 12 import java.sql.Connection ; 13 import java.sql.DriverManager ; 14 import java.sql.SQLException ; 15 import java.util.Properties ; 16 17 29 public class SimpoolAdapter implements ConnectionAdapterIF { 30 31 private static final Log LOG = LogFactory.getLog(SimpoolAdapter.class); 32 33 private Connection [] connections; 34 35 private int index = 0; 36 37 public String getName() { 38 return "simpool"; 39 } 40 41 public void setup(String driver, String url, Properties info) throws SQLException { 42 43 try { 44 Class.forName(driver); 45 } catch (ClassNotFoundException e) { 46 throw new SQLException ("Couldn't find " + driver); 47 } 48 49 int connectionCount = Integer.parseInt(info.getProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY)); 50 connections = new Connection [connectionCount]; 51 for (int i = 0; i < connectionCount; i++) { 52 connections[i] = DriverManager.getConnection(url, info); 53 } 54 } 55 56 public Connection getConnection() 57 throws SQLException { 58 Connection c = connections[index]; 59 index++; 60 if (index >= connections.length) { 61 index = 0; 62 } 63 return c; 64 } 65 66 public void closeConnection(Connection connection) { 67 } 69 70 public void tearDown() { 71 try { 72 for (int i = 0; i < connections.length; i++) { 73 connections[i].close(); 74 } 75 } catch (SQLException e) { 76 LOG.error("Problem tearing down " + getName() + " adapter", e); 77 } 78 } 79 80 } 81 82 126 | Popular Tags |