1 22 23 24 package com.mchange.v2.c3p0.jboss; 25 26 import com.mchange.v2.c3p0.*; 27 import com.mchange.v2.log.*; 28 import java.beans.PropertyVetoException ; 29 import java.sql.Connection ; 30 import java.sql.SQLException ; 31 import java.io.PrintWriter ; 32 import java.util.Properties ; 33 import javax.sql.DataSource ; 34 import javax.naming.InitialContext ; 35 import javax.naming.Name ; 36 import javax.naming.Context ; 37 import javax.naming.NameAlreadyBoundException ; 38 import javax.naming.NamingException ; 39 40 public class C3P0PooledDataSource implements C3P0PooledDataSourceMBean 41 { 42 private final static MLogger logger = MLog.getLogger( C3P0PooledDataSource.class ); 43 44 String jndiName; 45 46 ComboPooledDataSource combods = new ComboPooledDataSource(); 47 48 private void rebind() throws NamingException 49 { rebind(null); } 50 51 private void rebind(String unbindName) throws NamingException 52 { 53 InitialContext ictx = new InitialContext (); 54 if (unbindName != null) 55 ictx.unbind( unbindName ); 56 57 if (jndiName != null) 58 { 59 Name name = ictx.getNameParser( jndiName ).parse( jndiName ); 62 Context ctx = ictx; 63 for (int i = 0, max = name.size() - 1; i < max; i++) 64 { 65 try 66 { ctx = ctx.createSubcontext( name.get( i ) ); } 67 catch (NameAlreadyBoundException ignore) 68 { ctx = (Context ) ctx.lookup( name.get( i ) ); } 69 } 70 71 ictx.rebind( jndiName, combods ); 72 } 73 74 75 } 76 77 public void setJndiName(String jndiName) throws NamingException 79 { 80 String unbindName = this.jndiName; 81 this.jndiName = jndiName; 82 rebind( unbindName ); 83 } 84 85 public String getJndiName() 86 { return jndiName; } 87 88 public String getDescription() 90 { return combods.getDescription(); } 91 92 public void setDescription( String description ) throws NamingException 93 { 94 combods.setDescription( description ); 95 rebind(); 96 } 97 98 public String getDriverClass() 99 { return combods.getDriverClass(); } 100 101 public void setDriverClass( String driverClass ) throws PropertyVetoException , NamingException 102 { 103 combods.setDriverClass( driverClass ); 104 rebind(); 105 } 106 107 public String getJdbcUrl() 108 { return combods.getJdbcUrl(); } 109 110 public void setJdbcUrl( String jdbcUrl ) throws NamingException 111 { 112 combods.setJdbcUrl( jdbcUrl ); 113 rebind(); 114 } 115 116 public String getUser() 118 { return combods.getUser(); } 119 120 public void setUser( String user ) throws NamingException 121 { 122 combods.setUser( user ); 123 rebind(); 124 } 125 126 public String getPassword() 127 { return combods.getPassword(); } 128 129 public void setPassword( String password ) throws NamingException 130 { 131 combods.setPassword( password ); 132 rebind(); 133 } 134 135 public int getCheckoutTimeout() 137 { return combods.getCheckoutTimeout(); } 138 139 public void setCheckoutTimeout( int checkoutTimeout ) throws NamingException 140 { 141 combods.setCheckoutTimeout( checkoutTimeout ); 142 rebind(); 143 } 144 145 public int getAcquireIncrement() 146 { return combods.getAcquireIncrement(); } 147 148 public void setAcquireIncrement( int acquireIncrement ) throws NamingException 149 { 150 combods.setAcquireIncrement( acquireIncrement ); 151 rebind(); 152 } 153 154 public int getAcquireRetryAttempts() 155 { return combods.getAcquireRetryAttempts(); } 156 157 public void setAcquireRetryAttempts( int acquireRetryAttempts ) throws NamingException 158 { 159 combods.setAcquireRetryAttempts( acquireRetryAttempts ); 160 rebind(); 161 } 162 163 public int getAcquireRetryDelay() 164 { return combods.getAcquireRetryDelay(); } 165 166 public void setAcquireRetryDelay( int acquireRetryDelay ) throws NamingException 167 { 168 combods.setAcquireRetryDelay( acquireRetryDelay ); 169 rebind(); 170 } 171 172 public boolean isAutoCommitOnClose() 173 { return combods.isAutoCommitOnClose(); } 174 175 public void setAutoCommitOnClose( boolean autoCommitOnClose ) throws NamingException 176 { 177 combods.setAutoCommitOnClose( autoCommitOnClose ); 178 rebind(); 179 } 180 181 public String getConnectionTesterClassName() 182 { return combods.getConnectionTesterClassName(); } 183 184 public void setConnectionTesterClassName( String connectionTesterClassName ) throws PropertyVetoException , NamingException 185 { 186 combods.setConnectionTesterClassName( connectionTesterClassName ); 187 rebind(); 188 } 189 190 public String getAutomaticTestTable() 191 { return combods.getAutomaticTestTable(); } 192 193 public void setAutomaticTestTable( String automaticTestTable ) throws NamingException 194 { 195 combods.setAutomaticTestTable( automaticTestTable ); 196 rebind(); 197 } 198 199 public boolean isForceIgnoreUnresolvedTransactions() 200 { return combods.isForceIgnoreUnresolvedTransactions(); } 201 202 public void setForceIgnoreUnresolvedTransactions( boolean forceIgnoreUnresolvedTransactions ) throws NamingException 203 { 204 combods.setForceIgnoreUnresolvedTransactions( forceIgnoreUnresolvedTransactions ); 205 rebind(); 206 } 207 208 public int getIdleConnectionTestPeriod() 209 { return combods.getIdleConnectionTestPeriod(); } 210 211 public void setIdleConnectionTestPeriod( int idleConnectionTestPeriod ) throws NamingException 212 { 213 combods.setIdleConnectionTestPeriod( idleConnectionTestPeriod ); 214 rebind(); 215 } 216 217 public int getInitialPoolSize() 218 { return combods.getInitialPoolSize(); } 219 220 public void setInitialPoolSize( int initialPoolSize ) throws NamingException 221 { 222 combods.setInitialPoolSize( initialPoolSize ); 223 rebind(); 224 } 225 226 public int getMaxIdleTime() 227 { return combods.getMaxIdleTime(); } 228 229 public void setMaxIdleTime( int maxIdleTime ) throws NamingException 230 { 231 combods.setMaxIdleTime( maxIdleTime ); 232 rebind(); 233 } 234 235 public int getMaxPoolSize() 236 { return combods.getMaxPoolSize(); } 237 238 public void setMaxPoolSize( int maxPoolSize ) throws NamingException 239 { 240 combods.setMaxPoolSize( maxPoolSize ); 241 rebind(); 242 } 243 244 public int getMaxStatements() 245 { return combods.getMaxStatements(); } 246 247 public void setMaxStatements( int maxStatements ) throws NamingException 248 { 249 combods.setMaxStatements( maxStatements ); 250 rebind(); 251 } 252 253 public int getMaxStatementsPerConnection() 254 { return combods.getMaxStatementsPerConnection(); } 255 256 public void setMaxStatementsPerConnection( int maxStatementsPerConnection ) throws NamingException 257 { 258 combods.setMaxStatementsPerConnection( maxStatementsPerConnection ); 259 rebind(); 260 } 261 262 public int getMinPoolSize() 263 { return combods.getMinPoolSize(); } 264 265 public void setMinPoolSize( int minPoolSize ) throws NamingException 266 { 267 combods.setMinPoolSize( minPoolSize ); 268 rebind(); 269 } 270 271 public int getPropertyCycle() 272 { return combods.getPropertyCycle(); } 273 274 public void setPropertyCycle( int propertyCycle ) throws NamingException 275 { 276 combods.setPropertyCycle( propertyCycle ); 277 rebind(); 278 } 279 280 public boolean isBreakAfterAcquireFailure() 281 { return combods.isBreakAfterAcquireFailure(); } 282 283 public void setBreakAfterAcquireFailure( boolean breakAfterAcquireFailure ) throws NamingException 284 { 285 combods.setBreakAfterAcquireFailure( breakAfterAcquireFailure ); 286 rebind(); 287 } 288 289 public boolean isTestConnectionOnCheckout() 290 { return combods.isTestConnectionOnCheckout(); } 291 292 public void setTestConnectionOnCheckout( boolean testConnectionOnCheckout ) throws NamingException 293 { 294 combods.setTestConnectionOnCheckout( testConnectionOnCheckout ); 295 rebind(); 296 } 297 298 public boolean isTestConnectionOnCheckin() 299 { return combods.isTestConnectionOnCheckin(); } 300 301 public void setTestConnectionOnCheckin( boolean testConnectionOnCheckin ) throws NamingException 302 { 303 combods.setTestConnectionOnCheckin( testConnectionOnCheckin ); 304 rebind(); 305 } 306 307 public boolean isUsesTraditionalReflectiveProxies() 308 { return combods.isUsesTraditionalReflectiveProxies(); } 309 310 public void setUsesTraditionalReflectiveProxies( boolean usesTraditionalReflectiveProxies ) throws NamingException 311 { 312 combods.setUsesTraditionalReflectiveProxies( usesTraditionalReflectiveProxies ); 313 rebind(); 314 } 315 316 public String getPreferredTestQuery() 317 { return combods.getPreferredTestQuery(); } 318 319 public void setPreferredTestQuery( String preferredTestQuery ) throws NamingException 320 { 321 combods.setPreferredTestQuery( preferredTestQuery ); 322 rebind(); 323 } 324 325 public String getDataSourceName() 327 { return combods.getDataSourceName(); } 328 329 public void setDataSourceName( String name ) throws NamingException 330 { 331 combods.setDataSourceName( name ); 332 rebind(); 333 } 334 335 public int getNumHelperThreads() 336 { return combods.getNumHelperThreads(); } 337 338 public void setNumHelperThreads( int numHelperThreads ) throws NamingException 339 { 340 combods.setNumHelperThreads( numHelperThreads ); 341 rebind(); 342 } 343 344 public String getFactoryClassLocation() 346 { return combods.getFactoryClassLocation(); } 347 348 public void setFactoryClassLocation( String factoryClassLocation ) throws NamingException 349 { 350 combods.setFactoryClassLocation( factoryClassLocation ); 351 rebind(); 352 } 353 354 356 public int getNumUserPools() throws SQLException 357 { return combods.getNumUserPools(); } 358 359 public int getNumConnectionsDefaultUser() throws SQLException 360 { return combods.getNumConnectionsDefaultUser(); } 361 362 public int getNumIdleConnectionsDefaultUser() throws SQLException 363 { return combods.getNumIdleConnectionsDefaultUser(); } 364 365 public int getNumBusyConnectionsDefaultUser() throws SQLException 366 { return combods.getNumBusyConnectionsDefaultUser(); } 367 368 public int getNumUnclosedOrphanedConnectionsDefaultUser() throws SQLException 369 { return combods.getNumUnclosedOrphanedConnectionsDefaultUser(); } 370 371 public int getNumConnections(String username, String password) throws SQLException 372 { return combods.getNumConnections(username, password); } 373 374 public int getNumIdleConnections(String username, String password) throws SQLException 375 { return combods.getNumIdleConnections(username, password); } 376 377 public int getNumBusyConnections(String username, String password) throws SQLException 378 { return combods.getNumBusyConnections(username, password); } 379 380 public int getNumUnclosedOrphanedConnections(String username, String password) throws SQLException 381 { return combods.getNumUnclosedOrphanedConnections(username, password); } 382 383 public int getNumConnectionsAllUsers() throws SQLException 384 { return combods.getNumConnectionsAllUsers(); } 385 386 public int getNumIdleConnectionsAllUsers() throws SQLException 387 { return combods.getNumIdleConnectionsAllUsers(); } 388 389 public int getNumBusyConnectionsAllUsers() throws SQLException 390 { return combods.getNumBusyConnectionsAllUsers(); } 391 392 public int getNumUnclosedOrphanedConnectionsAllUsers() throws SQLException 393 { return combods.getNumUnclosedOrphanedConnectionsAllUsers(); } 394 395 public void softResetDefaultUser() throws SQLException 397 { combods.softResetDefaultUser(); } 398 399 public void softReset(String username, String password) throws SQLException 400 { combods.softReset(username, password); } 401 402 public void softResetAllUsers() throws SQLException 403 { combods.softResetAllUsers(); } 404 405 public void hardReset() throws SQLException 406 { combods.hardReset(); } 407 408 public void close() throws SQLException 409 { combods.close(); } 410 411 public void create() throws Exception 413 { } 414 415 public void start() throws Exception 417 { 418 logger.log(MLevel.INFO, "Bound C3P0 PooledDataSource to name ''{0}''. Starting...", jndiName); 420 combods.getNumBusyConnectionsDefaultUser(); } 422 423 424 public void stop() 425 { } 426 427 public void destroy() 428 { 429 try 430 { 431 combods.close(); 432 logger.log(MLevel.INFO, "Destroyed C3P0 PooledDataSource with name ''{0}''.", jndiName); 433 } 434 catch (Exception e) 435 { 436 logger.log(MLevel.INFO, "Failed to destroy C3P0 PooledDataSource.", e); 437 } 438 } 439 440 public String getConnectionCustomizerClassName() 441 { return combods.getConnectionCustomizerClassName(); } 442 443 public float getEffectivePropertyCycle(String username, String password) throws SQLException 444 { return combods.getEffectivePropertyCycle(username, password); } 445 446 public float getEffectivePropertyCycleDefaultUser() throws SQLException 447 { return combods.getEffectivePropertyCycleDefaultUser(); } 448 449 public int getMaxAdministrativeTaskTime() 450 { return combods.getMaxAdministrativeTaskTime(); } 451 452 public int getMaxConnectionAge() 453 { return combods.getMaxConnectionAge(); } 454 455 public int getMaxIdleTimeExcessConnections() 456 { return combods.getMaxIdleTimeExcessConnections(); } 457 458 public int getUnreturnedConnectionTimeout() 459 { return combods.getUnreturnedConnectionTimeout(); } 460 461 public boolean isDebugUnreturnedConnectionStackTraces() 462 { return combods.isDebugUnreturnedConnectionStackTraces(); } 463 464 public void setConnectionCustomizerClassName(String connectionCustomizerClassName) throws NamingException 465 { 466 combods.setConnectionCustomizerClassName(connectionCustomizerClassName); 467 rebind(); 468 } 469 470 public void setDebugUnreturnedConnectionStackTraces(boolean debugUnreturnedConnectionStackTraces) throws NamingException 471 { 472 combods.setDebugUnreturnedConnectionStackTraces(debugUnreturnedConnectionStackTraces); 473 rebind(); 474 } 475 476 public void setMaxAdministrativeTaskTime(int maxAdministrativeTaskTime) throws NamingException 477 { 478 combods.setMaxAdministrativeTaskTime(maxAdministrativeTaskTime); 479 rebind(); 480 } 481 482 public void setMaxConnectionAge(int maxConnectionAge) throws NamingException 483 { 484 combods.setMaxConnectionAge( maxConnectionAge ); 485 rebind(); 486 } 487 488 public void setMaxIdleTimeExcessConnections(int maxIdleTimeExcessConnections) throws NamingException 489 { 490 combods.setMaxIdleTimeExcessConnections(maxIdleTimeExcessConnections); 491 rebind(); 492 } 493 494 public void setUnreturnedConnectionTimeout(int unreturnedConnectionTimeout) throws NamingException 495 { 496 combods.setUnreturnedConnectionTimeout(unreturnedConnectionTimeout); 497 rebind(); 498 } 499 } 500 501 | Popular Tags |