1 22 23 24 package com.mchange.v2.c3p0.mbean; 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 43 public class C3P0PooledDataSource implements C3P0PooledDataSourceMBean 44 { 45 private final static MLogger logger = MLog.getLogger( C3P0PooledDataSource.class ); 46 47 String jndiName; 48 49 ComboPooledDataSource combods = new ComboPooledDataSource(); 50 51 private void rebind() throws NamingException 52 { rebind(null); } 53 54 private void rebind(String unbindName) throws NamingException 55 { 56 InitialContext ictx = new InitialContext (); 57 if (unbindName != null) 58 ictx.unbind( unbindName ); 59 60 if (jndiName != null) 61 { 62 Name name = ictx.getNameParser( jndiName ).parse( jndiName ); 65 Context ctx = ictx; 66 for (int i = 0, max = name.size() - 1; i < max; i++) 67 { 68 try 69 { ctx = ctx.createSubcontext( name.get( i ) ); } 70 catch (NameAlreadyBoundException ignore) 71 { ctx = (Context ) ctx.lookup( name.get( i ) ); } 72 } 73 74 ictx.rebind( jndiName, combods ); 75 } 76 77 78 } 79 80 public void setJndiName(String jndiName) throws NamingException 82 { 83 String unbindName = this.jndiName; 84 this.jndiName = jndiName; 85 rebind( unbindName ); 86 } 87 88 public String getJndiName() 89 { return jndiName; } 90 91 public String getDescription() 93 { return combods.getDescription(); } 94 95 public void setDescription( String description ) throws NamingException 96 { 97 combods.setDescription( description ); 98 rebind(); 99 } 100 101 public String getDriverClass() 102 { return combods.getDriverClass(); } 103 104 public void setDriverClass( String driverClass ) throws PropertyVetoException , NamingException 105 { 106 combods.setDriverClass( driverClass ); 107 rebind(); 108 } 109 110 public String getJdbcUrl() 111 { return combods.getJdbcUrl(); } 112 113 public void setJdbcUrl( String jdbcUrl ) throws NamingException 114 { 115 combods.setJdbcUrl( jdbcUrl ); 116 rebind(); 117 } 118 119 public String getUser() 121 { return combods.getUser(); } 122 123 public void setUser( String user ) throws NamingException 124 { 125 combods.setUser( user ); 126 rebind(); 127 } 128 129 public String getPassword() 130 { return combods.getPassword(); } 131 132 public void setPassword( String password ) throws NamingException 133 { 134 combods.setPassword( password ); 135 rebind(); 136 } 137 138 public int getCheckoutTimeout() 140 { return combods.getCheckoutTimeout(); } 141 142 public void setCheckoutTimeout( int checkoutTimeout ) throws NamingException 143 { 144 combods.setCheckoutTimeout( checkoutTimeout ); 145 rebind(); 146 } 147 148 public int getAcquireIncrement() 149 { return combods.getAcquireIncrement(); } 150 151 public void setAcquireIncrement( int acquireIncrement ) throws NamingException 152 { 153 combods.setAcquireIncrement( acquireIncrement ); 154 rebind(); 155 } 156 157 public int getAcquireRetryAttempts() 158 { return combods.getAcquireRetryAttempts(); } 159 160 public void setAcquireRetryAttempts( int acquireRetryAttempts ) throws NamingException 161 { 162 combods.setAcquireRetryAttempts( acquireRetryAttempts ); 163 rebind(); 164 } 165 166 public int getAcquireRetryDelay() 167 { return combods.getAcquireRetryDelay(); } 168 169 public void setAcquireRetryDelay( int acquireRetryDelay ) throws NamingException 170 { 171 combods.setAcquireRetryDelay( acquireRetryDelay ); 172 rebind(); 173 } 174 175 public boolean isAutoCommitOnClose() 176 { return combods.isAutoCommitOnClose(); } 177 178 public void setAutoCommitOnClose( boolean autoCommitOnClose ) throws NamingException 179 { 180 combods.setAutoCommitOnClose( autoCommitOnClose ); 181 rebind(); 182 } 183 184 public String getConnectionTesterClassName() 185 { return combods.getConnectionTesterClassName(); } 186 187 public void setConnectionTesterClassName( String connectionTesterClassName ) throws PropertyVetoException , NamingException 188 { 189 combods.setConnectionTesterClassName( connectionTesterClassName ); 190 rebind(); 191 } 192 193 public String getAutomaticTestTable() 194 { return combods.getAutomaticTestTable(); } 195 196 public void setAutomaticTestTable( String automaticTestTable ) throws NamingException 197 { 198 combods.setAutomaticTestTable( automaticTestTable ); 199 rebind(); 200 } 201 202 public boolean isForceIgnoreUnresolvedTransactions() 203 { return combods.isForceIgnoreUnresolvedTransactions(); } 204 205 public void setForceIgnoreUnresolvedTransactions( boolean forceIgnoreUnresolvedTransactions ) throws NamingException 206 { 207 combods.setForceIgnoreUnresolvedTransactions( forceIgnoreUnresolvedTransactions ); 208 rebind(); 209 } 210 211 public int getIdleConnectionTestPeriod() 212 { return combods.getIdleConnectionTestPeriod(); } 213 214 public void setIdleConnectionTestPeriod( int idleConnectionTestPeriod ) throws NamingException 215 { 216 combods.setIdleConnectionTestPeriod( idleConnectionTestPeriod ); 217 rebind(); 218 } 219 220 public int getInitialPoolSize() 221 { return combods.getInitialPoolSize(); } 222 223 public void setInitialPoolSize( int initialPoolSize ) throws NamingException 224 { 225 combods.setInitialPoolSize( initialPoolSize ); 226 rebind(); 227 } 228 229 public int getMaxIdleTime() 230 { return combods.getMaxIdleTime(); } 231 232 public void setMaxIdleTime( int maxIdleTime ) throws NamingException 233 { 234 combods.setMaxIdleTime( maxIdleTime ); 235 rebind(); 236 } 237 238 public int getMaxPoolSize() 239 { return combods.getMaxPoolSize(); } 240 241 public void setMaxPoolSize( int maxPoolSize ) throws NamingException 242 { 243 combods.setMaxPoolSize( maxPoolSize ); 244 rebind(); 245 } 246 247 public int getMaxStatements() 248 { return combods.getMaxStatements(); } 249 250 public void setMaxStatements( int maxStatements ) throws NamingException 251 { 252 combods.setMaxStatements( maxStatements ); 253 rebind(); 254 } 255 256 public int getMaxStatementsPerConnection() 257 { return combods.getMaxStatementsPerConnection(); } 258 259 public void setMaxStatementsPerConnection( int maxStatementsPerConnection ) throws NamingException 260 { 261 combods.setMaxStatementsPerConnection( maxStatementsPerConnection ); 262 rebind(); 263 } 264 265 public int getMinPoolSize() 266 { return combods.getMinPoolSize(); } 267 268 public void setMinPoolSize( int minPoolSize ) throws NamingException 269 { 270 combods.setMinPoolSize( minPoolSize ); 271 rebind(); 272 } 273 274 public int getPropertyCycle() 275 { return combods.getPropertyCycle(); } 276 277 public void setPropertyCycle( int propertyCycle ) throws NamingException 278 { 279 combods.setPropertyCycle( propertyCycle ); 280 rebind(); 281 } 282 283 public boolean isBreakAfterAcquireFailure() 284 { return combods.isBreakAfterAcquireFailure(); } 285 286 public void setBreakAfterAcquireFailure( boolean breakAfterAcquireFailure ) throws NamingException 287 { 288 combods.setBreakAfterAcquireFailure( breakAfterAcquireFailure ); 289 rebind(); 290 } 291 292 public boolean isTestConnectionOnCheckout() 293 { return combods.isTestConnectionOnCheckout(); } 294 295 public void setTestConnectionOnCheckout( boolean testConnectionOnCheckout ) throws NamingException 296 { 297 combods.setTestConnectionOnCheckout( testConnectionOnCheckout ); 298 rebind(); 299 } 300 301 public boolean isTestConnectionOnCheckin() 302 { return combods.isTestConnectionOnCheckin(); } 303 304 public void setTestConnectionOnCheckin( boolean testConnectionOnCheckin ) throws NamingException 305 { 306 combods.setTestConnectionOnCheckin( testConnectionOnCheckin ); 307 rebind(); 308 } 309 310 public boolean isUsesTraditionalReflectiveProxies() 311 { return combods.isUsesTraditionalReflectiveProxies(); } 312 313 public void setUsesTraditionalReflectiveProxies( boolean usesTraditionalReflectiveProxies ) throws NamingException 314 { 315 combods.setUsesTraditionalReflectiveProxies( usesTraditionalReflectiveProxies ); 316 rebind(); 317 } 318 319 public String getPreferredTestQuery() 320 { return combods.getPreferredTestQuery(); } 321 322 public void setPreferredTestQuery( String preferredTestQuery ) throws NamingException 323 { 324 combods.setPreferredTestQuery( preferredTestQuery ); 325 rebind(); 326 } 327 328 public String getDataSourceName() 330 { return combods.getDataSourceName(); } 331 332 public void setDataSourceName( String name ) throws NamingException 333 { 334 combods.setDataSourceName( name ); 335 rebind(); 336 } 337 338 public int getNumHelperThreads() 339 { return combods.getNumHelperThreads(); } 340 341 public void setNumHelperThreads( int numHelperThreads ) throws NamingException 342 { 343 combods.setNumHelperThreads( numHelperThreads ); 344 rebind(); 345 } 346 347 public String getFactoryClassLocation() 349 { return combods.getFactoryClassLocation(); } 350 351 public void setFactoryClassLocation( String factoryClassLocation ) throws NamingException 352 { 353 combods.setFactoryClassLocation( factoryClassLocation ); 354 rebind(); 355 } 356 357 359 public int getNumUserPools() throws SQLException 360 { return combods.getNumUserPools(); } 361 362 public int getNumConnectionsDefaultUser() throws SQLException 363 { return combods.getNumConnectionsDefaultUser(); } 364 365 public int getNumIdleConnectionsDefaultUser() throws SQLException 366 { return combods.getNumIdleConnectionsDefaultUser(); } 367 368 public int getNumBusyConnectionsDefaultUser() throws SQLException 369 { return combods.getNumBusyConnectionsDefaultUser(); } 370 371 public int getNumUnclosedOrphanedConnectionsDefaultUser() throws SQLException 372 { return combods.getNumUnclosedOrphanedConnectionsDefaultUser(); } 373 374 public int getNumConnections(String username, String password) throws SQLException 375 { return combods.getNumConnections(username, password); } 376 377 public int getNumIdleConnections(String username, String password) throws SQLException 378 { return combods.getNumIdleConnections(username, password); } 379 380 public int getNumBusyConnections(String username, String password) throws SQLException 381 { return combods.getNumBusyConnections(username, password); } 382 383 public int getNumUnclosedOrphanedConnections(String username, String password) throws SQLException 384 { return combods.getNumUnclosedOrphanedConnections(username, password); } 385 386 public int getNumConnectionsAllUsers() throws SQLException 387 { return combods.getNumConnectionsAllUsers(); } 388 389 public int getNumIdleConnectionsAllUsers() throws SQLException 390 { return combods.getNumIdleConnectionsAllUsers(); } 391 392 public int getNumBusyConnectionsAllUsers() throws SQLException 393 { return combods.getNumBusyConnectionsAllUsers(); } 394 395 public int getNumUnclosedOrphanedConnectionsAllUsers() throws SQLException 396 { return combods.getNumUnclosedOrphanedConnectionsAllUsers(); } 397 398 public void softResetDefaultUser() throws SQLException 400 { combods.softResetDefaultUser(); } 401 402 public void softReset(String username, String password) throws SQLException 403 { combods.softReset(username, password); } 404 405 public void softResetAllUsers() throws SQLException 406 { combods.softResetAllUsers(); } 407 408 public void hardReset() throws SQLException 409 { combods.hardReset(); } 410 411 public void close() throws SQLException 412 { combods.close(); } 413 414 public void create() throws Exception 416 { } 417 418 public void start() throws Exception 420 { 421 logger.log(MLevel.INFO, "Bound C3P0 PooledDataSource to name ''{0}''. Starting...", jndiName); 423 combods.getNumBusyConnectionsDefaultUser(); } 425 426 427 public void stop() 428 { } 429 430 public void destroy() 431 { } 432 } 433 434 | Popular Tags |