@@ -362,55 +362,6 @@ public static BasicDataSource createDataSource(final $Dbcp dbcp) {
362
362
return createDataSource (null , ClassLoader .getSystemClassLoader (), dbcp );
363
363
}
364
364
365
- private final ClassLoader driverClassLoader ;
366
- private BasicDataSource dataSource = null ;
367
- private String driverClassName = null ;
368
- private String url = null ;
369
-
370
- private boolean autoCommit = true ;
371
- private boolean readOnly = false ;
372
-
373
- private Integer queryTimeout = null ;
374
- private String transactionIsolation = null ;
375
-
376
- private int initialSize = 0 ;
377
- private int minIdle = 0 ;
378
- private String maxIdle = INDEFINITE ;
379
- private String maxTotal = INDEFINITE ;
380
- private boolean poolPreparedStatements = false ;
381
- private String maxOpen = INDEFINITE ;
382
-
383
- private boolean lifo = true ;
384
-
385
- private boolean cacheState = true ;
386
- private String maxWait = INDEFINITE ;
387
- private String maxConnLifetime = INDEFINITE ;
388
- private boolean autoCommitOnReturn = true ;
389
- private boolean rollbackOnReturn = true ;
390
- private String removeAbandonedOn = null ;
391
- private int removeAbandonedTimeout = 0 ;
392
- private boolean abandonedUsageTracking = false ;
393
- private boolean accessToUnderlyingConnectionAllowed = false ;
394
- private boolean hasEviction = false ;
395
- private String timeBetweenEvictionRunsMillis = INDEFINITE ;
396
- private int numTestsPerRun = 3 ;
397
- private long minEvictableIdleTimeMillis = 1800000 ;
398
- private String softMinEvictableIdleTimeMillis = INDEFINITE ;
399
- private String policyClassName = null ;
400
-
401
- private boolean hasValidation = false ;
402
- private String validationQuery = null ;
403
- private String validationQueryTimeout = INDEFINITE ;
404
- private boolean testOnCreate = false ;
405
- private boolean testOnBorrow = true ;
406
- private boolean testOnReturn = false ;
407
- private boolean testWhileIdle = false ;
408
- private List <String > disconnectionQueryCodes = null ;
409
-
410
- private String loggingLevel = null ;
411
- private boolean logExpiredConnections = false ;
412
- private boolean logAbandoned = false ;
413
-
414
365
/**
415
366
* Create a {@link BasicDataSource} from the configuration supplied by the array of {@link Dbcp dbcp} JAX-B bindings that match the
416
367
* specified {@code id}.
@@ -423,7 +374,7 @@ public static BasicDataSource createDataSource(final $Dbcp dbcp) {
423
374
* @throws IllegalArgumentException If the {@code /dbcp:jdbc} element is missing from all members in {@code dbcps}.
424
375
*/
425
376
public static BasicDataSource createDataSource (final String id , final ClassLoader driverClassLoader , final Dbcp ... dbcps ) {
426
- return new DataSources (id , driverClassLoader , dbcps ). build ( );
377
+ return DataSources (id , driverClassLoader , dbcps );
427
378
}
428
379
429
380
/**
@@ -438,11 +389,58 @@ public static BasicDataSource createDataSource(final String id, final ClassLoade
438
389
* @throws IllegalArgumentException If the {@code /dbcp:jdbc} element is missing from all members in {@code dbcps}.
439
390
*/
440
391
public static BasicDataSource createDataSource (final String id , final ClassLoader driverClassLoader , final $Dbcp ... dbcps ) {
441
- return new DataSources (id , driverClassLoader , dbcps ). build ( );
392
+ return DataSources (id , driverClassLoader , dbcps );
442
393
}
443
394
444
- private DataSources (final String id , final ClassLoader driverClassLoader , final Dbcp ... dbcps ) {
445
- this .driverClassLoader = driverClassLoader ;
395
+ static BasicDataSource DataSources (final String id , final ClassLoader driverClassLoader , final Dbcp ... dbcps ) {
396
+ BasicDataSource dataSource = null ;
397
+ String driverClassName = null ;
398
+ String url = null ;
399
+
400
+ boolean autoCommit = true ;
401
+ boolean readOnly = false ;
402
+
403
+ Integer queryTimeout = null ;
404
+ String transactionIsolation = null ;
405
+
406
+ int initialSize = 0 ;
407
+ int minIdle = 0 ;
408
+ String maxIdle = INDEFINITE ;
409
+ String maxTotal = INDEFINITE ;
410
+ boolean poolPreparedStatements = false ;
411
+ String maxOpen = INDEFINITE ;
412
+
413
+ boolean lifo = true ;
414
+
415
+ boolean cacheState = true ;
416
+ String maxWait = INDEFINITE ;
417
+ String maxConnLifetime = INDEFINITE ;
418
+ boolean autoCommitOnReturn = true ;
419
+ boolean rollbackOnReturn = true ;
420
+ String removeAbandonedOn = null ;
421
+ int removeAbandonedTimeout = 0 ;
422
+ boolean abandonedUsageTracking = false ;
423
+ boolean accessToUnderlyingConnectionAllowed = false ;
424
+ boolean hasEviction = false ;
425
+ String timeBetweenEvictionRunsMillis = INDEFINITE ;
426
+ int numTestsPerRun = 3 ;
427
+ long minEvictableIdleTimeMillis = 1800000 ;
428
+ String softMinEvictableIdleTimeMillis = INDEFINITE ;
429
+ String policyClassName = null ;
430
+
431
+ boolean hasValidation = false ;
432
+ String validationQuery = null ;
433
+ String validationQueryTimeout = INDEFINITE ;
434
+ boolean testOnCreate = false ;
435
+ boolean testOnBorrow = true ;
436
+ boolean testOnReturn = false ;
437
+ boolean testWhileIdle = false ;
438
+ List <String > disconnectionQueryCodes = null ;
439
+
440
+ String loggingLevel = null ;
441
+ boolean logExpiredConnections = false ;
442
+ boolean logAbandoned = false ;
443
+
446
444
for (final Dbcp dbcp : dbcps ) { // [A]
447
445
if (id != null && !id .equals (dbcp .getId ()))
448
446
continue ;
@@ -494,13 +492,13 @@ private DataSources(final String id, final ClassLoader driverClassLoader, final
494
492
if (CollectionUtil .isRandomAccess (properties )) {
495
493
int i = 0 ;
496
494
do // [RA]
497
- add (properties .get (i ));
495
+ add (dataSource , properties .get (i ));
498
496
while (++i < i$ );
499
497
}
500
498
else {
501
499
final Iterator <Dbcp .Connection .Properties .Property > it = properties .iterator ();
502
500
do // [I]
503
- add (it .next ());
501
+ add (dataSource , it .next ());
504
502
while (it .hasNext ());
505
503
}
506
504
}
@@ -667,24 +665,73 @@ else if ("fifo".equals(queue))
667
665
668
666
dataSource .setJmxName (dbcp .getJmxName ());
669
667
}
668
+
669
+ return build (driverClassLoader , dataSource , driverClassName , url , autoCommit , readOnly , queryTimeout , transactionIsolation , initialSize , minIdle , maxIdle , maxTotal , poolPreparedStatements , maxOpen , lifo , cacheState , maxWait , maxConnLifetime , autoCommitOnReturn , rollbackOnReturn , removeAbandonedOn , removeAbandonedTimeout , abandonedUsageTracking , accessToUnderlyingConnectionAllowed , hasEviction , timeBetweenEvictionRunsMillis , numTestsPerRun , minEvictableIdleTimeMillis , softMinEvictableIdleTimeMillis , policyClassName , hasValidation , validationQuery , validationQueryTimeout , testOnCreate , testOnBorrow , testOnReturn , testWhileIdle , disconnectionQueryCodes , loggingLevel , logExpiredConnections , logAbandoned );
670
670
}
671
671
672
- private void add (final $Dbcp .Connection .Properties .Property property ) {
672
+ private static void add (final BasicDataSource dataSource , final $Dbcp .Connection .Properties .Property property ) {
673
673
final $Dbcp .Connection .Properties .Property .Name$ name = property .getName$ ();
674
674
final $Dbcp .Connection .Properties .Property .Value$ value = property .getValue$ ();
675
675
if (name != null && value != null )
676
676
dataSource .addConnectionProperty (name .text (), value .text ());
677
677
}
678
678
679
- private void add (final Dbcp .Connection .Properties .Property property ) {
679
+ private static void add (final BasicDataSource dataSource , final Dbcp .Connection .Properties .Property property ) {
680
680
final String name = property .getName ();
681
681
final String value = property .getValue ();
682
682
if (name != null && value != null )
683
683
dataSource .addConnectionProperty (name , value );
684
684
}
685
685
686
- private DataSources (final String id , final ClassLoader driverClassLoader , final $Dbcp ... dbcps ) {
687
- this .driverClassLoader = driverClassLoader ;
686
+ static BasicDataSource DataSources (final String id , final ClassLoader driverClassLoader , final $Dbcp ... dbcps ) {
687
+ BasicDataSource dataSource = null ;
688
+ String driverClassName = null ;
689
+ String url = null ;
690
+
691
+ boolean autoCommit = true ;
692
+ boolean readOnly = false ;
693
+
694
+ Integer queryTimeout = null ;
695
+ String transactionIsolation = null ;
696
+
697
+ int initialSize = 0 ;
698
+ int minIdle = 0 ;
699
+ String maxIdle = INDEFINITE ;
700
+ String maxTotal = INDEFINITE ;
701
+ boolean poolPreparedStatements = false ;
702
+ String maxOpen = INDEFINITE ;
703
+
704
+ boolean lifo = true ;
705
+
706
+ boolean cacheState = true ;
707
+ String maxWait = INDEFINITE ;
708
+ String maxConnLifetime = INDEFINITE ;
709
+ boolean autoCommitOnReturn = true ;
710
+ boolean rollbackOnReturn = true ;
711
+ String removeAbandonedOn = null ;
712
+ int removeAbandonedTimeout = 0 ;
713
+ boolean abandonedUsageTracking = false ;
714
+ boolean accessToUnderlyingConnectionAllowed = false ;
715
+ boolean hasEviction = false ;
716
+ String timeBetweenEvictionRunsMillis = INDEFINITE ;
717
+ int numTestsPerRun = 3 ;
718
+ long minEvictableIdleTimeMillis = 1800000 ;
719
+ String softMinEvictableIdleTimeMillis = INDEFINITE ;
720
+ String policyClassName = null ;
721
+
722
+ boolean hasValidation = false ;
723
+ String validationQuery = null ;
724
+ String validationQueryTimeout = INDEFINITE ;
725
+ boolean testOnCreate = false ;
726
+ boolean testOnBorrow = true ;
727
+ boolean testOnReturn = false ;
728
+ boolean testWhileIdle = false ;
729
+ List <String > disconnectionQueryCodes = null ;
730
+
731
+ String loggingLevel = null ;
732
+ boolean logExpiredConnections = false ;
733
+ boolean logAbandoned = false ;
734
+
688
735
for (final $Dbcp dbcp : dbcps ) { // [A]
689
736
final $Dbcp .Id$ id$ = dbcp .getId$ ();
690
737
if (id != null && (id$ == null || !id .equals (id$ .text ())))
@@ -737,13 +784,13 @@ private DataSources(final String id, final ClassLoader driverClassLoader, final
737
784
if (CollectionUtil .isRandomAccess (properties )) {
738
785
int i = 0 ;
739
786
do // [RA]
740
- add (properties .get (i ));
787
+ add (dataSource , properties .get (i ));
741
788
while (++i < i$ );
742
789
}
743
790
else {
744
791
final Iterator <$Dbcp .Connection .Properties .Property > it = properties .iterator ();
745
792
do // [I]
746
- add (it .next ());
793
+ add (dataSource , it .next ());
747
794
while (it .hasNext ());
748
795
}
749
796
}
@@ -931,9 +978,53 @@ else if ("fifo".equals(text))
931
978
if (dbcp .getJmxName () != null )
932
979
dataSource .setJmxName (dbcp .getJmxName ().text ());
933
980
}
981
+
982
+ return build (driverClassLoader , dataSource , driverClassName , url , autoCommit , readOnly , queryTimeout , transactionIsolation , initialSize , minIdle , maxIdle , maxTotal , poolPreparedStatements , maxOpen , lifo , cacheState , maxWait , maxConnLifetime , autoCommitOnReturn , rollbackOnReturn , removeAbandonedOn , removeAbandonedTimeout , abandonedUsageTracking , accessToUnderlyingConnectionAllowed , hasEviction , timeBetweenEvictionRunsMillis , numTestsPerRun , minEvictableIdleTimeMillis , softMinEvictableIdleTimeMillis , policyClassName , hasValidation , validationQuery , validationQueryTimeout , testOnCreate , testOnBorrow , testOnReturn , testWhileIdle , disconnectionQueryCodes , loggingLevel , logExpiredConnections , logAbandoned );
934
983
}
935
984
936
- private BasicDataSource build () {
985
+ private static BasicDataSource build (
986
+ final ClassLoader driverClassLoader ,
987
+ final BasicDataSource dataSource ,
988
+ final String driverClassName ,
989
+ final String url ,
990
+ final boolean autoCommit ,
991
+ final boolean readOnly ,
992
+ final Integer queryTimeout ,
993
+ final String transactionIsolation ,
994
+ final int initialSize ,
995
+ final int minIdle ,
996
+ final String maxIdle ,
997
+ final String maxTotal ,
998
+ final boolean poolPreparedStatements ,
999
+ final String maxOpen ,
1000
+ final boolean lifo ,
1001
+ final boolean cacheState ,
1002
+ final String maxWait ,
1003
+ final String maxConnLifetime ,
1004
+ final boolean autoCommitOnReturn ,
1005
+ final boolean rollbackOnReturn ,
1006
+ final String removeAbandonedOn ,
1007
+ final int removeAbandonedTimeout ,
1008
+ final boolean abandonedUsageTracking ,
1009
+ final boolean accessToUnderlyingConnectionAllowed ,
1010
+ final boolean hasEviction ,
1011
+ final String timeBetweenEvictionRunsMillis ,
1012
+ final int numTestsPerRun ,
1013
+ final long minEvictableIdleTimeMillis ,
1014
+ final String softMinEvictableIdleTimeMillis ,
1015
+ final String policyClassName ,
1016
+ final boolean hasValidation ,
1017
+ final String validationQuery ,
1018
+ final String validationQueryTimeout ,
1019
+ final boolean testOnCreate ,
1020
+ final boolean testOnBorrow ,
1021
+ final boolean testOnReturn ,
1022
+ final boolean testWhileIdle ,
1023
+ final List <String > disconnectionQueryCodes ,
1024
+ final String loggingLevel ,
1025
+ final boolean logExpiredConnections ,
1026
+ final boolean logAbandoned
1027
+ ) {
937
1028
if (dataSource == null )
938
1029
return null ;
939
1030
@@ -1032,4 +1123,7 @@ else if ("maintenance".equals(removeAbandonedOn))
1032
1123
1033
1124
return dataSource ;
1034
1125
}
1126
+
1127
+ private DataSources () {
1128
+ }
1035
1129
}
0 commit comments