1 22 23 24 package com.mchange.v2.c3p0; 25 26 import java.sql.SQLException ; 27 import javax.sql.DataSource ; 28 import com.mchange.v2.sql.SqlUtils; 29 30 37 public final class PoolBackedDataSourceFactory 38 { 39 65 public static DataSource createReferenceable( DataSource unpooledDataSource, 66 int minPoolSize, 67 int maxPoolSize, 68 int acquireIncrement, 69 int maxIdleTime, 70 int maxStatements, 71 String factoryLocation ) throws SQLException 72 { 73 try 74 { 75 WrapperConnectionPoolDataSource cpds = new WrapperConnectionPoolDataSource(); 76 cpds.setNestedDataSource(unpooledDataSource); 77 cpds.setMinPoolSize( minPoolSize ); 78 cpds.setMaxPoolSize( maxPoolSize ); 79 cpds.setAcquireIncrement( acquireIncrement ); 80 cpds.setMaxIdleTime( maxIdleTime ); 81 cpds.setMaxStatements( maxStatements ); 82 cpds.setFactoryClassLocation( factoryLocation ); 83 84 85 PoolBackedDataSource out = new PoolBackedDataSource(); 86 out.setConnectionPoolDataSource( cpds ); 87 return out; 88 } 89 catch (Exception e) 90 { throw SqlUtils.toSQLException( e ); } 91 } 92 93 108 public static DataSource createReferenceable( DataSource unpooledDataSource, 109 String factoryLocation ) 110 throws SQLException 111 { 112 try 113 { 114 WrapperConnectionPoolDataSource cpds = new WrapperConnectionPoolDataSource(); 115 cpds.setNestedDataSource(unpooledDataSource); 116 cpds.setFactoryClassLocation( factoryLocation ); 117 118 PoolBackedDataSource out = new PoolBackedDataSource(); 119 out.setConnectionPoolDataSource( cpds ); 120 return out; 121 } 122 catch (Exception e) 123 { throw SqlUtils.toSQLException( e ); } 124 } 125 126 152 public static DataSource createReferenceable(String jdbcDriverClass, 153 String jdbcUrl, 154 String user, 155 String password, 156 int minPoolSize, 157 int maxPoolSize, 158 int acquireIncrement, 159 int maxIdleTime, 160 int maxStatements, 161 String factoryLocation ) throws SQLException 162 { 163 DataSource nested = DriverManagerDataSourceFactory.create( jdbcDriverClass, 164 jdbcUrl, 165 user, 166 password ); 167 return createReferenceable( nested, 168 minPoolSize, 169 maxPoolSize, 170 acquireIncrement, 171 maxIdleTime, 172 maxStatements, 173 factoryLocation ); 174 } 175 176 191 public static DataSource createReferenceable(String jdbcDriverClass, 192 String jdbcUrl, 193 String user, 194 String password, 195 String factoryLocation ) 196 throws SQLException 197 { 198 DataSource nested = DriverManagerDataSourceFactory.create( jdbcDriverClass, 199 jdbcUrl, 200 user, 201 password ); 202 return createReferenceable( nested, 203 factoryLocation ); 204 } 205 206 229 public static DataSource createSerializable( DataSource unpooledDataSource, 230 int minPoolSize, 231 int maxPoolSize, 232 int acquireIncrement, 233 int maxIdleTime, 234 int maxStatements) 235 throws SQLException 236 { 237 try 238 { 239 WrapperConnectionPoolDataSource cpds = new WrapperConnectionPoolDataSource(); 240 cpds.setNestedDataSource(unpooledDataSource); 241 cpds.setMinPoolSize( minPoolSize ); 242 cpds.setMaxPoolSize( maxPoolSize ); 243 cpds.setAcquireIncrement( acquireIncrement ); 244 cpds.setMaxIdleTime( maxIdleTime ); 245 cpds.setMaxStatements( maxStatements ); 246 247 PoolBackedDataSource out = new PoolBackedDataSource(); 248 out.setConnectionPoolDataSource( cpds ); 249 return out; 250 } 251 catch (Exception e) 252 { throw SqlUtils.toSQLException( e ); } 253 } 254 255 267 public static DataSource createSerializable( DataSource unpooledDataSource ) throws SQLException 268 { 269 try 270 { 271 WrapperConnectionPoolDataSource cpds = new WrapperConnectionPoolDataSource(); 272 cpds.setNestedDataSource(unpooledDataSource); 273 274 PoolBackedDataSource out = new PoolBackedDataSource(); 275 out.setConnectionPoolDataSource( cpds ); 276 return out; 277 } 278 catch (Exception e) 279 { throw SqlUtils.toSQLException( e ); } 280 } 281 282 283 306 public static DataSource createSerializable( String jdbcDriverClass, 307 String jdbcUrl, 308 String user, 309 String password, 310 int minPoolSize, 311 int maxPoolSize, 312 int acquireIncrement, 313 int maxIdleTime, 314 int maxStatements) 315 throws SQLException 316 { 317 DataSource nested = DriverManagerDataSourceFactory.create( jdbcDriverClass, 318 jdbcUrl, 319 user, 320 password ); 321 return createSerializable( nested, 322 minPoolSize, 323 maxPoolSize, 324 acquireIncrement, 325 maxIdleTime, 326 maxStatements); 327 } 328 329 341 public static DataSource createSerializable( String jdbcDriverClass, 342 String jdbcUrl, 343 String user, 344 String password) 345 throws SQLException 346 { 347 DataSource nested = DriverManagerDataSourceFactory.create( jdbcDriverClass, 348 jdbcUrl, 349 user, 350 password ); 351 return createSerializable( nested ); 352 } 353 354 377 public static DataSource create( DataSource unpooledDataSource, 378 int minPoolSize, 379 int maxPoolSize, 380 int acquireIncrement, 381 int maxIdleTime, 382 int maxStatements, 383 String factoryLocation) throws SQLException 384 { 385 return createReferenceable( unpooledDataSource, 386 minPoolSize, 387 maxPoolSize, 388 acquireIncrement, 389 maxIdleTime, 390 maxStatements, 391 factoryLocation ); 392 } 393 394 413 public static DataSource create( DataSource unpooledDataSource, 414 int minPoolSize, 415 int maxPoolSize, 416 int acquireIncrement, 417 int maxIdleTime, 418 int maxStatements ) throws SQLException 419 { 420 return createReferenceable( unpooledDataSource, 421 minPoolSize, 422 maxPoolSize, 423 acquireIncrement, 424 maxIdleTime, 425 maxStatements, 426 null ); 427 } 428 429 436 public static DataSource create( DataSource unpooledDataSource ) throws SQLException 437 { return createSerializable( unpooledDataSource ); } 438 439 463 public static DataSource create( String jdbcDriverClass, 464 String jdbcUrl, 465 String user, 466 String password, 467 int minPoolSize, 468 int maxPoolSize, 469 int acquireIncrement, 470 int maxIdleTime, 471 int maxStatements, 472 String factoryLocation ) 473 throws SQLException 474 { 475 return createReferenceable( jdbcDriverClass, 476 jdbcUrl, 477 user, 478 password, 479 minPoolSize, 480 maxPoolSize, 481 acquireIncrement, 482 maxIdleTime, 483 maxStatements, 484 factoryLocation ); 485 } 486 487 507 public static DataSource create( String jdbcDriverClass, 508 String jdbcUrl, 509 String user, 510 String password, 511 int minPoolSize, 512 int maxPoolSize, 513 int acquireIncrement, 514 int maxIdleTime, 515 int maxStatements ) 516 throws SQLException 517 { 518 return createReferenceable( jdbcDriverClass, 519 jdbcUrl, 520 user, 521 password, 522 minPoolSize, 523 maxPoolSize, 524 acquireIncrement, 525 maxIdleTime, 526 maxStatements, 527 null ); 528 } 529 555 public static DataSource create( String jdbcUrl, 556 String user, 557 String password, 558 int minPoolSize, 559 int maxPoolSize, 560 int acquireIncrement, 561 int maxIdleTime, 562 int maxStatements, 563 String factoryLocation ) 564 throws SQLException 565 { 566 return create( null, 567 jdbcUrl, 568 user, 569 password, 570 minPoolSize, 571 maxPoolSize, 572 acquireIncrement, 573 maxIdleTime, 574 maxStatements, 575 factoryLocation ); 576 } 577 578 600 public static DataSource create( String jdbcUrl, 601 String user, 602 String password, 603 int minPoolSize, 604 int maxPoolSize, 605 int acquireIncrement, 606 int maxIdleTime, 607 int maxStatements ) 608 throws SQLException 609 { 610 return create( null, 611 jdbcUrl, 612 user, 613 password, 614 minPoolSize, 615 maxPoolSize, 616 acquireIncrement, 617 maxIdleTime, 618 maxStatements, 619 null ); 620 } 621 622 631 public static DataSource create( String jdbcDriverClass, 632 String jdbcUrl, 633 String user, 634 String password) throws SQLException 635 { 636 return createSerializable( jdbcDriverClass, 637 jdbcUrl, 638 user, 639 password ); 640 } 641 642 653 public static DataSource create( String jdbcUrl, 654 String user, 655 String password) 656 throws SQLException 657 { 658 return create( null, 659 jdbcUrl, 660 user, 661 password ); 662 } 663 664 private PoolBackedDataSourceFactory() 665 {} 666 } 667 668 669 670 671 | Popular Tags |