1 22 23 24 package com.mchange.v2.c3p0; 25 26 import com.mchange.v2.c3p0.impl.*; 27 28 import java.beans.PropertyVetoException ; 29 import java.io.PrintWriter ; 30 import java.io.Serializable ; 31 import java.sql.SQLException ; 32 import java.util.Arrays ; 33 import java.util.Collection ; 34 import java.util.Hashtable ; 35 import javax.naming.NamingException ; 36 import javax.naming.Reference ; 37 import javax.naming.Referenceable ; 38 import javax.sql.ConnectionPoolDataSource ; 39 import javax.sql.PooledConnection ; 40 import com.mchange.v2.beans.BeansUtils; 41 import com.mchange.v2.log.MLevel; 42 import com.mchange.v2.log.MLog; 43 import com.mchange.v2.log.MLogger; 44 import com.mchange.v2.naming.JavaBeanReferenceMaker; 45 import com.mchange.v2.naming.JavaBeanObjectFactory; 46 import com.mchange.v2.naming.ReferenceMaker; 47 48 public final class JndiRefConnectionPoolDataSource extends IdentityTokenResolvable implements ConnectionPoolDataSource , Serializable , Referenceable 49 { 50 final static MLogger logger = MLog.getLogger( JndiRefConnectionPoolDataSource.class ); 51 52 final static Collection IGNORE_PROPS = Arrays.asList( new String [] {"reference", "pooledConnection"} ); 53 54 JndiRefForwardingDataSource jrfds; 55 WrapperConnectionPoolDataSource wcpds; 56 57 String identityToken; 58 59 public JndiRefConnectionPoolDataSource() 60 { this( true ); } 61 62 public JndiRefConnectionPoolDataSource( boolean autoregister ) 63 { 64 jrfds = new JndiRefForwardingDataSource(); 65 wcpds = new WrapperConnectionPoolDataSource(); 66 wcpds.setNestedDataSource( jrfds ); 67 68 if (autoregister) 69 { 70 this.identityToken = C3P0ImplUtils.allocateIdentityToken( this ); 71 C3P0Registry.reregister( this ); 72 } 73 } 74 75 public boolean isJndiLookupCaching() 76 { return jrfds.isCaching(); } 77 78 public void setJndiLookupCaching( boolean caching ) 79 { jrfds.setCaching( caching ); } 80 81 public Hashtable getJndiEnv() 82 { return jrfds.getJndiEnv(); } 83 84 public void setJndiEnv( Hashtable jndiEnv ) 85 { jrfds.setJndiEnv( jndiEnv ); } 86 87 public Object getJndiName() 88 { return jrfds.getJndiName(); } 89 90 public void setJndiName( Object jndiName ) throws PropertyVetoException 91 { jrfds.setJndiName( jndiName ); } 92 93 public int getAcquireIncrement() 94 { return wcpds.getAcquireIncrement(); } 95 96 public void setAcquireIncrement( int acquireIncrement ) 97 { wcpds.setAcquireIncrement( acquireIncrement ); } 98 99 public int getAcquireRetryAttempts() 100 { return wcpds.getAcquireRetryAttempts(); } 101 102 public void setAcquireRetryAttempts( int ara ) 103 { wcpds.setAcquireRetryAttempts( ara ); } 104 105 public int getAcquireRetryDelay() 106 { return wcpds.getAcquireRetryDelay(); } 107 108 public void setAcquireRetryDelay( int ard ) 109 { wcpds.setAcquireRetryDelay( ard ); } 110 111 public boolean isAutoCommitOnClose() 112 { return wcpds.isAutoCommitOnClose(); } 113 114 public void setAutoCommitOnClose( boolean autoCommitOnClose ) 115 { wcpds.setAutoCommitOnClose( autoCommitOnClose ); } 116 117 public void setAutomaticTestTable( String att ) 118 { wcpds.setAutomaticTestTable( att ); } 119 120 public String getAutomaticTestTable() 121 { return wcpds.getAutomaticTestTable(); } 122 123 public void setBreakAfterAcquireFailure( boolean baaf ) 124 { wcpds.setBreakAfterAcquireFailure( baaf ); } 125 126 public boolean isBreakAfterAcquireFailure() 127 { return wcpds.isBreakAfterAcquireFailure(); } 128 129 public void setCheckoutTimeout( int ct ) 130 { wcpds.setCheckoutTimeout( ct ); } 131 132 public int getCheckoutTimeout() 133 { return wcpds.getCheckoutTimeout(); } 134 135 public String getConnectionTesterClassName() 136 { return wcpds.getConnectionTesterClassName(); } 137 138 public void setConnectionTesterClassName( String connectionTesterClassName ) throws PropertyVetoException 139 { wcpds.setConnectionTesterClassName( connectionTesterClassName ); } 140 141 public boolean isForceIgnoreUnresolvedTransactions() 142 { return wcpds.isForceIgnoreUnresolvedTransactions(); } 143 144 public void setForceIgnoreUnresolvedTransactions( boolean forceIgnoreUnresolvedTransactions ) 145 { wcpds.setForceIgnoreUnresolvedTransactions( forceIgnoreUnresolvedTransactions ); } 146 147 public String getIdentityToken() 148 { return identityToken; } 149 150 public void setIdentityToken(String identityToken) 151 { this.identityToken = identityToken; } 152 153 public void setIdleConnectionTestPeriod( int idleConnectionTestPeriod ) 154 { wcpds.setIdleConnectionTestPeriod( idleConnectionTestPeriod ); } 155 156 public int getIdleConnectionTestPeriod() 157 { return wcpds.getIdleConnectionTestPeriod(); } 158 159 public int getInitialPoolSize() 160 { return wcpds.getInitialPoolSize(); } 161 162 public void setInitialPoolSize( int initialPoolSize ) 163 { wcpds.setInitialPoolSize( initialPoolSize ); } 164 165 public int getMaxIdleTime() 166 { return wcpds.getMaxIdleTime(); } 167 168 public void setMaxIdleTime( int maxIdleTime ) 169 { wcpds.setMaxIdleTime( maxIdleTime ); } 170 171 public int getMaxPoolSize() 172 { return wcpds.getMaxPoolSize(); } 173 174 public void setMaxPoolSize( int maxPoolSize ) 175 { wcpds.setMaxPoolSize( maxPoolSize ); } 176 177 public int getMaxStatements() 178 { return wcpds.getMaxStatements(); } 179 180 public void setMaxStatements( int maxStatements ) 181 { wcpds.setMaxStatements( maxStatements ); } 182 183 public int getMaxStatementsPerConnection() 184 { return wcpds.getMaxStatementsPerConnection(); } 185 186 public void setMaxStatementsPerConnection( int mspc ) 187 { wcpds.setMaxStatementsPerConnection( mspc ); } 188 189 public int getMinPoolSize() 190 { return wcpds.getMinPoolSize(); } 191 192 public void setMinPoolSize( int minPoolSize ) 193 { wcpds.setMinPoolSize( minPoolSize ); } 194 195 public String getPreferredTestQuery() 196 { return wcpds.getPreferredTestQuery(); } 197 198 public void setPreferredTestQuery( String ptq ) 199 { wcpds.setPreferredTestQuery( ptq ); } 200 201 public int getPropertyCycle() 202 { return wcpds.getPropertyCycle(); } 203 204 public void setPropertyCycle( int propertyCycle ) 205 { wcpds.setPropertyCycle( propertyCycle ); } 206 207 public boolean isTestConnectionOnCheckin() 208 { return wcpds.isTestConnectionOnCheckin(); } 209 210 public void setTestConnectionOnCheckin( boolean testConnectionOnCheckin ) 211 { wcpds.setTestConnectionOnCheckin( testConnectionOnCheckin ); } 212 213 public boolean isTestConnectionOnCheckout() 214 { return wcpds.isTestConnectionOnCheckout(); } 215 216 public void setTestConnectionOnCheckout( boolean testConnectionOnCheckout ) 217 { wcpds.setTestConnectionOnCheckout( testConnectionOnCheckout ); } 218 219 public boolean isUsesTraditionalReflectiveProxies() 220 { return wcpds.isUsesTraditionalReflectiveProxies(); } 221 222 public void setUsesTraditionalReflectiveProxies( boolean utrp ) 223 { wcpds.setUsesTraditionalReflectiveProxies( utrp ); } 224 225 public String getFactoryClassLocation() 226 { return jrfds.getFactoryClassLocation(); } 227 228 public void setFactoryClassLocation( String factoryClassLocation ) 229 { 230 jrfds.setFactoryClassLocation( factoryClassLocation ); 231 wcpds.setFactoryClassLocation( factoryClassLocation ); 232 } 233 234 final static JavaBeanReferenceMaker referenceMaker = new JavaBeanReferenceMaker(); 235 236 static 237 { 238 referenceMaker.setFactoryClassName( C3P0JavaBeanObjectFactory.class.getName() ); 239 referenceMaker.addReferenceProperty("acquireIncrement"); 240 referenceMaker.addReferenceProperty("acquireRetryAttempts"); 241 referenceMaker.addReferenceProperty("acquireRetryDelay"); 242 referenceMaker.addReferenceProperty("autoCommitOnClose"); 243 referenceMaker.addReferenceProperty("automaticTestTable"); 244 referenceMaker.addReferenceProperty("checkoutTimeout"); 245 referenceMaker.addReferenceProperty("connectionTesterClassName"); 246 referenceMaker.addReferenceProperty("factoryClassLocation"); 247 referenceMaker.addReferenceProperty("forceIgnoreUnresolvedTransactions"); 248 referenceMaker.addReferenceProperty("idleConnectionTestPeriod"); 249 referenceMaker.addReferenceProperty("identityToken"); 250 referenceMaker.addReferenceProperty("initialPoolSize"); 251 referenceMaker.addReferenceProperty("jndiEnv"); 252 referenceMaker.addReferenceProperty("jndiLookupCaching"); 253 referenceMaker.addReferenceProperty("jndiName"); 254 referenceMaker.addReferenceProperty("maxIdleTime"); 255 referenceMaker.addReferenceProperty("maxPoolSize"); 256 referenceMaker.addReferenceProperty("maxStatements"); 257 referenceMaker.addReferenceProperty("maxStatementsPerConnection"); 258 referenceMaker.addReferenceProperty("minPoolSize"); 259 referenceMaker.addReferenceProperty("preferredTestQuery"); 260 referenceMaker.addReferenceProperty("propertyCycle"); 261 referenceMaker.addReferenceProperty("testConnectionOnCheckin"); 262 referenceMaker.addReferenceProperty("testConnectionOnCheckout"); 263 referenceMaker.addReferenceProperty("usesTraditionalReflectiveProxies"); 264 } 265 266 public Reference getReference() throws NamingException 267 { return referenceMaker.createReference( this ); } 268 269 public PooledConnection getPooledConnection() 271 throws SQLException 272 { return wcpds.getPooledConnection(); } 273 274 public PooledConnection getPooledConnection(String user, String password) 275 throws SQLException 276 { return wcpds.getPooledConnection( user, password ); } 277 278 public PrintWriter getLogWriter() 279 throws SQLException 280 { return wcpds.getLogWriter(); } 281 282 public void setLogWriter(PrintWriter out) 283 throws SQLException 284 { wcpds.setLogWriter( out ); } 285 286 public void setLoginTimeout(int seconds) 287 throws SQLException 288 { wcpds.setLoginTimeout( seconds ); } 289 290 public int getLoginTimeout() 291 throws SQLException 292 { return wcpds.getLoginTimeout(); } 293 294 public String toString() 295 { 296 StringBuffer sb = new StringBuffer (512); 297 sb.append( super.toString() ); 298 sb.append(" ["); 299 try { BeansUtils.appendPropNamesAndValues( sb, this, IGNORE_PROPS ); } 300 catch (Exception e) 301 { 302 if ( Debug.DEBUG && logger.isLoggable( MLevel.FINE ) ) 304 logger.log( MLevel.FINE, "An exception occurred while extracting property names and values for toString()", e); 305 sb.append( e.toString() ); 306 } 307 sb.append("]"); 308 return sb.toString(); 309 } 310 } 311 312 | Popular Tags |