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 25 public class ProxoolAdapter implements ConnectionAdapterIF, ConfigurationListenerIF { 26 27 private static final Log LOG = LogFactory.getLog(ProxoolAdapter.class); 28 29 private String alias = String.valueOf(hashCode()); 30 31 private String fullUrl; 32 33 private Properties changedInfo; 34 35 private Properties completeInfo; 36 37 41 public ProxoolAdapter(String alias) { 42 this.alias = alias; 43 } 44 45 48 public ProxoolAdapter() { 49 } 50 51 public void definitionUpdated(ConnectionPoolDefinitionIF connectionPoolDefinition, Properties completeInfo, Properties changedInfo) { 52 setCompleteInfo(completeInfo); 53 setChangedInfo(changedInfo); 54 LOG.debug("Definition updated " + connectionPoolDefinition.getCompleteUrl()); 55 if (changedInfo != null && changedInfo.size() > 0) { 56 LOG.debug(changedInfo.size() + " properties updated"); 57 } else { 58 LOG.debug("No properties updated"); 59 } 60 } 61 62 public Properties getChangedInfo() { 63 return changedInfo; 64 } 65 66 public void setChangedInfo(Properties changedInfo) { 67 this.changedInfo = changedInfo; 68 } 69 70 public Properties getCompleteInfo() { 71 return completeInfo; 72 } 73 74 public void setCompleteInfo(Properties completeInfo) { 75 this.completeInfo = completeInfo; 76 } 77 78 public String getName() { 79 return "proxool"; 80 } 81 82 public void update(Properties info) throws SQLException , ProxoolException { 83 ProxoolFacade.updateConnectionPool(getFullUrl(), info); 84 } 85 86 public void update(String url) throws SQLException , ProxoolException { 87 ProxoolFacade.updateConnectionPool(url, null); 88 } 89 90 public void setup(String driver, String url, Properties info) throws SQLException , ProxoolException { 91 92 try { 93 Class.forName(ProxoolDriver.class.getName()); 94 } catch (ClassNotFoundException e) { 95 throw new SQLException ("Couldn't find " + driver); 96 } 97 98 fullUrl = TestHelper.buildProxoolUrl(alias, driver, url); 99 ProxoolFacade.registerConnectionPool(fullUrl, info); 100 ProxoolFacade.addConfigurationListener(alias, this); 101 } 102 103 public Connection getConnection() 104 throws SQLException { 105 return DriverManager.getConnection(ProxoolConstants.PROXOOL 106 + ProxoolConstants.ALIAS_DELIMITER + alias); 107 } 108 109 public String getFullUrl() { 110 return fullUrl; 111 } 112 113 public void closeConnection(Connection connection) throws SQLException { 114 if (connection != null) { 115 connection.close(); 116 } 117 } 118 119 public void tearDown() { 120 try { 121 ProxoolFacade.removeConnectionPool(alias); 122 } catch (ProxoolException e) { 123 LOG.error("Problem tearing down " + alias, e); 124 } 125 } 126 127 } 128 129 204 | Popular Tags |