1 23 24 package org.dbforms.conprovider; 25 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 import org.dbforms.util.Util; 31 32 import java.sql.Connection ; 33 import java.sql.DriverManager ; 34 import java.sql.SQLException ; 35 36 import java.util.Enumeration ; 37 import java.util.Hashtable ; 38 import java.util.Properties ; 39 40 41 42 49 public class ProtomatterConnectionProvider extends ConnectionProvider { 50 51 protected static final String CP_PROPS_INITIALSIZE = "pool.initialSize"; 52 53 57 protected static final String CP_PROPS_MAXSIZE = "pool.maxSize"; 58 59 63 protected static final String CP_PROPS_GROWBLOCK = "pool.growBlock"; 64 65 71 protected static final String CP_PROPS_CREATEWAITTIME = "pool.createWaitTime"; 72 73 79 protected static final String CP_PROPS_VALIDITYCHECKSTATEMENT = "jdbc.validityCheckStatement"; 80 81 92 protected static final String CP_PROPS_MAXCONNECTIONIDLETIME = "pool.maxConnectionIdleTime"; 93 94 98 protected static final String CP_PROPS_MAIDTHREADCHECKINTERVAL = "pool.maidThreadCheckInterval"; 99 100 101 private static final String CP_DRIVER = "com.protomatter.jdbc.pool.JdbcConnectionPoolDriver"; 102 103 104 private static Log logCat = LogFactory.getLog(ProtomatterConnectionProvider.class); 105 106 113 public ProtomatterConnectionProvider() throws Exception { 114 super(); 115 } 116 117 124 protected Connection getConnection() throws SQLException { 125 return DriverManager.getConnection(getPrefs().getConnectionPoolURL(), 126 getPrefs().getUser(), 127 getPrefs().getPassword()); 128 } 129 130 131 136 protected void init() throws Exception { 137 Properties props = null; 138 139 Hashtable args = new Hashtable (); 141 142 args.put("jdbc.driver", getPrefs().getJdbcDriver()); 144 145 args.put("jdbc.URL", getPrefs().getJdbcURL()); 147 148 Properties jdbcProperties = new Properties (); 150 jdbcProperties.put("user", getPrefs().getUser()); 151 jdbcProperties.put("password", getPrefs().getPassword()); 152 153 if ((props = getPrefs() 155 .getProperties()) != null) { 156 for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { 157 String key = (String ) e.nextElement(); 158 jdbcProperties.put(key, props.getProperty(key)); 159 logCat.info("::init - JDBC property [" + key + "] = [" 160 + props.getProperty(key) + "]"); 161 } 162 } 163 164 args.put("jdbc.properties", jdbcProperties); 165 166 if ((props = getPrefs() 170 .getPoolProperties()) == null) { 171 props = new Properties (); 172 } 173 174 setIntegerArg(args, props, CP_PROPS_INITIALSIZE, "0"); 176 setIntegerArg(args, props, CP_PROPS_MAXSIZE, "-1"); 177 setIntegerArg(args, props, CP_PROPS_GROWBLOCK, "1"); 178 setIntegerArg(args, props, CP_PROPS_CREATEWAITTIME, "0"); 179 setArg(args, props, CP_PROPS_VALIDITYCHECKSTATEMENT, null); 180 setIntegerArg(args, props, CP_PROPS_MAXCONNECTIONIDLETIME, null); 181 setIntegerArg(args, props, CP_PROPS_MAIDTHREADCHECKINTERVAL, null); 182 183 Class.forName(CP_DRIVER).newInstance(); 185 } 186 187 188 199 private final void setArg(Hashtable args, 200 Properties props, 201 String key, 202 String defValue) { 203 String value = props.getProperty(key, defValue); 204 205 if (!Util.isNull(value)) { 206 args.put(key, value); 207 logCat.info("::setArg - [" + key + "] = [" + value + "]"); 208 } 209 } 210 211 212 223 private final void setIntegerArg(Hashtable args, 224 Properties props, 225 String key, 226 String defValue) { 227 String value = props.getProperty(key, defValue); 228 229 if (!Util.isNull(value)) { 230 args.put(key, new Integer (value)); 231 logCat.info("::setIntegerArg - [" + key + "] = [" + value + "]"); 232 } 233 } 234 } 235 | Popular Tags |