/
DruidAbstractDataSource.java
2239 lines (1811 loc) · 82.3 KB
/
DruidAbstractDataSource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.pool;
import java.io.PrintWriter;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import javax.management.JMException;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeDataSupport;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.sql.DataSource;
import com.alibaba.druid.DbType;
import com.alibaba.druid.DruidRuntimeException;
import com.alibaba.druid.VERSION;
import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.filter.FilterChainImpl;
import com.alibaba.druid.filter.FilterManager;
import com.alibaba.druid.pool.vendor.NullExceptionSorter;
import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
import com.alibaba.druid.proxy.jdbc.TransactionInfo;
import com.alibaba.druid.stat.JdbcDataSourceStat;
import com.alibaba.druid.stat.JdbcSqlStat;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.util.DruidPasswordCallback;
import com.alibaba.druid.util.Histogram;
import com.alibaba.druid.util.JdbcConstants;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.MySqlUtils;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.druid.util.Utils;
/**
* @author wenshao [szujobs@hotmail.com]
* @author ljw [ljw2083@alibaba-inc.com]
*/
public abstract class DruidAbstractDataSource extends WrapperAdapter implements DruidAbstractDataSourceMBean, DataSource, DataSourceProxy, Serializable {
private static final long serialVersionUID = 1L;
private final static Log LOG = LogFactory.getLog(DruidAbstractDataSource.class);
public final static int DEFAULT_INITIAL_SIZE = 0;
public final static int DEFAULT_MAX_ACTIVE_SIZE = 8;
public final static int DEFAULT_MAX_IDLE = 8;
public final static int DEFAULT_MIN_IDLE = 0;
public final static int DEFAULT_MAX_WAIT = -1;
public final static String DEFAULT_VALIDATION_QUERY = null; //
public final static boolean DEFAULT_TEST_ON_BORROW = false;
public final static boolean DEFAULT_TEST_ON_RETURN = false;
public final static boolean DEFAULT_WHILE_IDLE = true;
public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = 60 * 1000L;
public static final long DEFAULT_TIME_BETWEEN_CONNECT_ERROR_MILLIS = 500;
public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L;
public static final long DEFAULT_MAX_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 60L * 7;
public static final long DEFAULT_PHY_TIMEOUT_MILLIS = -1;
protected volatile boolean defaultAutoCommit = true;
protected volatile Boolean defaultReadOnly;
protected volatile Integer defaultTransactionIsolation;
protected volatile String defaultCatalog = null;
protected String name;
protected volatile String username;
protected volatile String password;
protected volatile String jdbcUrl;
protected volatile String driverClass;
protected volatile ClassLoader driverClassLoader;
protected volatile Properties connectProperties = new Properties();
protected volatile PasswordCallback passwordCallback;
protected volatile NameCallback userCallback;
protected volatile int initialSize = DEFAULT_INITIAL_SIZE;
protected volatile int maxActive = DEFAULT_MAX_ACTIVE_SIZE;
protected volatile int minIdle = DEFAULT_MIN_IDLE;
protected volatile int maxIdle = DEFAULT_MAX_IDLE;
protected volatile long maxWait = DEFAULT_MAX_WAIT;
protected int notFullTimeoutRetryCount = 0;
protected volatile String validationQuery = DEFAULT_VALIDATION_QUERY;
protected volatile int validationQueryTimeout = -1;
protected volatile boolean testOnBorrow = DEFAULT_TEST_ON_BORROW;
protected volatile boolean testOnReturn = DEFAULT_TEST_ON_RETURN;
protected volatile boolean testWhileIdle = DEFAULT_WHILE_IDLE;
protected volatile boolean poolPreparedStatements = false;
protected volatile boolean sharePreparedStatements = false;
protected volatile int maxPoolPreparedStatementPerConnectionSize = 10;
protected volatile boolean inited = false;
protected volatile boolean initExceptionThrow = true;
protected PrintWriter logWriter = new PrintWriter(System.out);
protected List<Filter> filters = new CopyOnWriteArrayList<Filter>();
private boolean clearFiltersEnable = true;
protected volatile ExceptionSorter exceptionSorter = null;
protected Driver driver;
protected volatile int queryTimeout;
protected volatile int transactionQueryTimeout;
protected long createTimespan;
protected volatile int maxWaitThreadCount = -1;
protected volatile boolean accessToUnderlyingConnectionAllowed = true;
protected volatile long timeBetweenEvictionRunsMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
protected volatile int numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
protected volatile long minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
protected volatile long maxEvictableIdleTimeMillis = DEFAULT_MAX_EVICTABLE_IDLE_TIME_MILLIS;
protected volatile long keepAliveBetweenTimeMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS * 2;
protected volatile long phyTimeoutMillis = DEFAULT_PHY_TIMEOUT_MILLIS;
protected volatile long phyMaxUseCount = -1;
protected volatile boolean removeAbandoned;
protected volatile long removeAbandonedTimeoutMillis = 300 * 1000;
protected volatile boolean logAbandoned;
protected volatile int maxOpenPreparedStatements = -1;
protected volatile List<String> connectionInitSqls;
protected volatile String dbTypeName;
protected volatile long timeBetweenConnectErrorMillis = DEFAULT_TIME_BETWEEN_CONNECT_ERROR_MILLIS;
protected volatile ValidConnectionChecker validConnectionChecker = null;
protected final Map<DruidPooledConnection, Object> activeConnections = new IdentityHashMap<DruidPooledConnection, Object>();
protected final static Object PRESENT = new Object();
protected long id;
protected int connectionErrorRetryAttempts = 1;
protected boolean breakAfterAcquireFailure = false;
protected long transactionThresholdMillis = 0L;
protected final Date createdTime = new Date();
protected Date initedTime;
protected volatile long errorCount = 0L;
protected volatile long dupCloseCount = 0L;
protected volatile long startTransactionCount = 0L;
protected volatile long commitCount = 0L;
protected volatile long rollbackCount = 0L;
protected volatile long cachedPreparedStatementHitCount = 0L;
protected volatile long preparedStatementCount = 0L;
protected volatile long closedPreparedStatementCount = 0L;
protected volatile long cachedPreparedStatementCount = 0L;
protected volatile long cachedPreparedStatementDeleteCount = 0L;
protected volatile long cachedPreparedStatementMissCount = 0L;
final static AtomicLongFieldUpdater<DruidAbstractDataSource> errorCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "errorCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> dupCloseCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "dupCloseCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> startTransactionCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "startTransactionCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> commitCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "commitCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> rollbackCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "rollbackCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> cachedPreparedStatementHitCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "cachedPreparedStatementHitCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> preparedStatementCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "preparedStatementCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> closedPreparedStatementCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "closedPreparedStatementCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> cachedPreparedStatementCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "cachedPreparedStatementCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> cachedPreparedStatementDeleteCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "cachedPreparedStatementDeleteCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> cachedPreparedStatementMissCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "cachedPreparedStatementMissCount");
protected final Histogram transactionHistogram = new Histogram(1,
10,
100,
1000,
10 * 1000,
100 * 1000);
private boolean dupCloseLogEnable = false;
private ObjectName objectName;
protected volatile long executeCount = 0L;
protected volatile long executeQueryCount = 0L;
protected volatile long executeUpdateCount = 0L;
protected volatile long executeBatchCount = 0L;
final static AtomicLongFieldUpdater<DruidAbstractDataSource> executeQueryCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "executeQueryCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> executeUpdateCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "executeUpdateCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> executeBatchCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "executeBatchCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> executeCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "executeCount");
protected volatile Throwable createError;
protected volatile Throwable lastError;
protected volatile long lastErrorTimeMillis;
protected volatile Throwable lastCreateError;
protected volatile long lastCreateErrorTimeMillis;
protected volatile long lastCreateStartTimeMillis;
protected boolean isOracle = false;
protected boolean isMySql = false;
protected boolean useOracleImplicitCache = true;
protected ReentrantLock lock;
protected Condition notEmpty;
protected Condition empty;
protected ReentrantLock activeConnectionLock = new ReentrantLock();
protected volatile int createErrorCount = 0;
protected volatile int creatingCount = 0;
protected volatile int directCreateCount = 0;
protected volatile long createCount = 0L;
protected volatile long destroyCount = 0L;
protected volatile long createStartNanos = 0L;
final static AtomicIntegerFieldUpdater<DruidAbstractDataSource> createErrorCountUpdater = AtomicIntegerFieldUpdater.newUpdater(DruidAbstractDataSource.class, "createErrorCount");
final static AtomicIntegerFieldUpdater<DruidAbstractDataSource> creatingCountUpdater = AtomicIntegerFieldUpdater.newUpdater(DruidAbstractDataSource.class, "creatingCount");
final static AtomicIntegerFieldUpdater<DruidAbstractDataSource> directCreateCountUpdater = AtomicIntegerFieldUpdater.newUpdater(DruidAbstractDataSource.class, "directCreateCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> createCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "createCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> destroyCountUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "destroyCount");
final static AtomicLongFieldUpdater<DruidAbstractDataSource> createStartNanosUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "createStartNanos");
private Boolean useUnfairLock = null;
private boolean useLocalSessionState = true;
protected long timeBetweenLogStatsMillis;
protected DruidDataSourceStatLogger statLogger = new DruidDataSourceStatLoggerImpl();
private boolean asyncCloseConnectionEnable = false;
protected int maxCreateTaskCount = 3;
protected boolean failFast = false;
protected volatile int failContinuous = 0;
protected volatile long failContinuousTimeMillis = 0L;
protected ScheduledExecutorService destroyScheduler;
protected ScheduledExecutorService createScheduler;
final static AtomicLongFieldUpdater<DruidAbstractDataSource> failContinuousTimeMillisUpdater = AtomicLongFieldUpdater.newUpdater(DruidAbstractDataSource.class, "failContinuousTimeMillis");
final static AtomicIntegerFieldUpdater<DruidAbstractDataSource> failContinuousUpdater = AtomicIntegerFieldUpdater.newUpdater(DruidAbstractDataSource.class, "failContinuous");
protected boolean initVariants = false;
protected boolean initGlobalVariants = false;
protected volatile boolean onFatalError = false;
protected volatile int onFatalErrorMaxActive = 0;
protected volatile int fatalErrorCount = 0;
protected volatile int fatalErrorCountLastShrink = 0;
protected volatile long lastFatalErrorTimeMillis = 0;
protected volatile String lastFatalErrorSql = null;
protected volatile Throwable lastFatalError = null;
public DruidAbstractDataSource(boolean lockFair){
lock = new ReentrantLock(lockFair);
notEmpty = lock.newCondition();
empty = lock.newCondition();
}
public boolean isUseLocalSessionState() {
return useLocalSessionState;
}
public void setUseLocalSessionState(boolean useLocalSessionState) {
this.useLocalSessionState = useLocalSessionState;
}
public DruidDataSourceStatLogger getStatLogger() {
return statLogger;
}
public void setStatLoggerClassName(String className) {
Class<?> clazz;
try {
clazz = Class.forName(className);
DruidDataSourceStatLogger statLogger = (DruidDataSourceStatLogger) clazz.newInstance();
this.setStatLogger(statLogger);
} catch (Exception e) {
throw new IllegalArgumentException(className, e);
}
}
public void setStatLogger(DruidDataSourceStatLogger statLogger) {
this.statLogger = statLogger;
}
public long getTimeBetweenLogStatsMillis() {
return timeBetweenLogStatsMillis;
}
public void setTimeBetweenLogStatsMillis(long timeBetweenLogStatsMillis) {
this.timeBetweenLogStatsMillis = timeBetweenLogStatsMillis;
}
public boolean isOracle() {
return isOracle;
}
public void setOracle(boolean isOracle) {
if (inited) {
throw new IllegalStateException();
}
this.isOracle = isOracle;
}
public boolean isUseUnfairLock() {
return !lock.isFair();
}
public void setUseUnfairLock(boolean useUnfairLock) {
if (lock.isFair() == !useUnfairLock && this.useUnfairLock != null) {
return;
}
if (!this.inited) {
final ReentrantLock lock = this.lock;
lock.lock();
try {
if (!this.inited) {
this.lock = new ReentrantLock(!useUnfairLock);
this.notEmpty = this.lock.newCondition();
this.empty = this.lock.newCondition();
this.useUnfairLock = useUnfairLock;
}
} finally {
lock.unlock();
}
}
}
public boolean isUseOracleImplicitCache() {
return useOracleImplicitCache;
}
public void setUseOracleImplicitCache(boolean useOracleImplicitCache) {
if (this.useOracleImplicitCache != useOracleImplicitCache) {
this.useOracleImplicitCache = useOracleImplicitCache;
boolean isOracleDriver10 = isOracle() && this.driver != null && this.driver.getMajorVersion() == 10;
if (isOracleDriver10 && useOracleImplicitCache) {
this.getConnectProperties().setProperty("oracle.jdbc.FreeMemoryOnEnterImplicitCache", "true");
} else {
this.getConnectProperties().remove("oracle.jdbc.FreeMemoryOnEnterImplicitCache");
}
}
}
public Throwable getLastCreateError() {
return lastCreateError;
}
public Throwable getLastError() {
return this.lastError;
}
public long getLastErrorTimeMillis() {
return lastErrorTimeMillis;
}
public Date getLastErrorTime() {
if (lastErrorTimeMillis <= 0) {
return null;
}
return new Date(lastErrorTimeMillis);
}
public long getLastCreateErrorTimeMillis() {
return lastCreateErrorTimeMillis;
}
public Date getLastCreateErrorTime() {
if (lastCreateErrorTimeMillis <= 0) {
return null;
}
return new Date(lastCreateErrorTimeMillis);
}
public int getTransactionQueryTimeout() {
if (transactionQueryTimeout <= 0) {
return queryTimeout;
}
return transactionQueryTimeout;
}
public void setTransactionQueryTimeout(int transactionQueryTimeout) {
this.transactionQueryTimeout = transactionQueryTimeout;
}
public long getExecuteCount() {
return executeCount + executeQueryCount + executeUpdateCount + executeBatchCount;
}
public long getExecuteUpdateCount() {
return executeUpdateCount;
}
public long getExecuteQueryCount() {
return executeQueryCount;
}
public long getExecuteBatchCount() {
return executeBatchCount;
}
public long getAndResetExecuteCount() {
return executeCountUpdater.getAndSet(this, 0)
+ executeQueryCountUpdater.getAndSet(this, 0)
+ executeUpdateCountUpdater.getAndSet(this, 0)
+ executeBatchCountUpdater.getAndSet(this, 0);
}
public long getExecuteCount2() {
return executeCount;
}
public void incrementExecuteCount() {
this.executeCountUpdater.incrementAndGet(this);
}
public void incrementExecuteUpdateCount() {
this.executeUpdateCount++;
}
public void incrementExecuteQueryCount() {
this.executeQueryCount++;
}
public void incrementExecuteBatchCount() {
this.executeBatchCount++;
}
public boolean isDupCloseLogEnable() {
return dupCloseLogEnable;
}
public void setDupCloseLogEnable(boolean dupCloseLogEnable) {
this.dupCloseLogEnable = dupCloseLogEnable;
}
public ObjectName getObjectName() {
return objectName;
}
public void setObjectName(ObjectName objectName) {
this.objectName = objectName;
}
public Histogram getTransactionHistogram() {
return transactionHistogram;
}
public void incrementCachedPreparedStatementCount() {
cachedPreparedStatementCountUpdater.incrementAndGet(this);
}
public void decrementCachedPreparedStatementCount() {
cachedPreparedStatementCountUpdater.decrementAndGet(this);
}
public void incrementCachedPreparedStatementDeleteCount() {
cachedPreparedStatementDeleteCountUpdater.incrementAndGet(this);
}
public void incrementCachedPreparedStatementMissCount() {
cachedPreparedStatementMissCountUpdater.incrementAndGet(this);
}
public long getCachedPreparedStatementMissCount() {
return cachedPreparedStatementMissCount;
}
public long getCachedPreparedStatementAccessCount() {
return cachedPreparedStatementMissCount + cachedPreparedStatementHitCount;
}
public long getCachedPreparedStatementDeleteCount() {
return cachedPreparedStatementDeleteCount;
}
public long getCachedPreparedStatementCount() {
return cachedPreparedStatementCount;
}
public void incrementClosedPreparedStatementCount() {
closedPreparedStatementCountUpdater.incrementAndGet(this);
}
public long getClosedPreparedStatementCount() {
return closedPreparedStatementCount;
}
public void incrementPreparedStatementCount() {
preparedStatementCountUpdater.incrementAndGet(this);
}
public long getPreparedStatementCount() {
return preparedStatementCount;
}
public void incrementCachedPreparedStatementHitCount() {
cachedPreparedStatementHitCountUpdater.incrementAndGet(this);
}
public long getCachedPreparedStatementHitCount() {
return cachedPreparedStatementHitCount;
}
public long getTransactionThresholdMillis() {
return transactionThresholdMillis;
}
public void setTransactionThresholdMillis(long transactionThresholdMillis) {
this.transactionThresholdMillis = transactionThresholdMillis;
}
public abstract void logTransaction(TransactionInfo info);
public long[] getTransactionHistogramValues() {
return transactionHistogram.toArray();
}
public long[] getTransactionHistogramRanges() {
return transactionHistogram.getRanges();
}
public long getCommitCount() {
return commitCount;
}
public void incrementCommitCount() {
commitCountUpdater.incrementAndGet(this);
}
public long getRollbackCount() {
return rollbackCount;
}
public void incrementRollbackCount() {
rollbackCountUpdater.incrementAndGet(this);
}
public long getStartTransactionCount() {
return startTransactionCount;
}
public void incrementStartTransactionCount() {
startTransactionCountUpdater.incrementAndGet(this);
}
public boolean isBreakAfterAcquireFailure() {
return breakAfterAcquireFailure;
}
public void setBreakAfterAcquireFailure(boolean breakAfterAcquireFailure) {
this.breakAfterAcquireFailure = breakAfterAcquireFailure;
}
public int getConnectionErrorRetryAttempts() {
return connectionErrorRetryAttempts;
}
public void setConnectionErrorRetryAttempts(int connectionErrorRetryAttempts) {
this.connectionErrorRetryAttempts = connectionErrorRetryAttempts;
}
public long getDupCloseCount() {
return dupCloseCount;
}
public int getMaxPoolPreparedStatementPerConnectionSize() {
return maxPoolPreparedStatementPerConnectionSize;
}
public void setMaxPoolPreparedStatementPerConnectionSize(int maxPoolPreparedStatementPerConnectionSize) {
if (maxPoolPreparedStatementPerConnectionSize > 0) {
this.poolPreparedStatements = true;
} else {
this.poolPreparedStatements = false;
}
this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
}
public boolean isSharePreparedStatements() {
return sharePreparedStatements;
}
public void setSharePreparedStatements(boolean sharePreparedStatements) {
this.sharePreparedStatements = sharePreparedStatements;
}
public void incrementDupCloseCount() {
dupCloseCountUpdater.incrementAndGet(this);
}
public ValidConnectionChecker getValidConnectionChecker() {
return validConnectionChecker;
}
public void setValidConnectionChecker(ValidConnectionChecker validConnectionChecker) {
this.validConnectionChecker = validConnectionChecker;
}
public String getValidConnectionCheckerClassName() {
if (validConnectionChecker == null) {
return null;
}
return validConnectionChecker.getClass().getName();
}
public void setValidConnectionCheckerClassName(String validConnectionCheckerClass) throws Exception {
Class<?> clazz = Utils.loadClass(validConnectionCheckerClass);
ValidConnectionChecker validConnectionChecker = null;
if (clazz != null) {
validConnectionChecker = (ValidConnectionChecker) clazz.newInstance();
this.validConnectionChecker = validConnectionChecker;
} else {
LOG.error("load validConnectionCheckerClass error : " + validConnectionCheckerClass);
}
}
public String getDbType() {
return dbTypeName;
}
public void setDbType(DbType dbType) {
if (dbType == null) {
this.dbTypeName = null;
} else {
this.dbTypeName = dbType.name();
}
}
public void setDbType(String dbType) {
this.dbTypeName = dbType;
}
public void addConnectionProperty(String name, String value) {
if (StringUtils.equals(connectProperties.getProperty(name), value)) {
return;
}
if (inited) {
throw new UnsupportedOperationException();
}
connectProperties.put(name, value);
}
public Collection<String> getConnectionInitSqls() {
Collection<String> result = connectionInitSqls;
if (result == null) {
return Collections.emptyList();
}
return result;
}
public void setConnectionInitSqls(Collection<? extends Object> connectionInitSqls) {
if ((connectionInitSqls != null) && (connectionInitSqls.size() > 0)) {
ArrayList<String> newVal = null;
for (Object o : connectionInitSqls) {
if (o == null) {
continue;
}
String s = o.toString();
s = s.trim();
if (s.length() == 0) {
continue;
}
if (newVal == null) {
newVal = new ArrayList<String>();
}
newVal.add(s);
}
this.connectionInitSqls = newVal;
} else {
this.connectionInitSqls = null;
}
}
public long getTimeBetweenConnectErrorMillis() {
return timeBetweenConnectErrorMillis;
}
public void setTimeBetweenConnectErrorMillis(long timeBetweenConnectErrorMillis) {
this.timeBetweenConnectErrorMillis = timeBetweenConnectErrorMillis;
}
public int getMaxOpenPreparedStatements() {
return maxPoolPreparedStatementPerConnectionSize;
}
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
this.setMaxPoolPreparedStatementPerConnectionSize(maxOpenPreparedStatements);
}
public boolean isLogAbandoned() {
return logAbandoned;
}
public void setLogAbandoned(boolean logAbandoned) {
this.logAbandoned = logAbandoned;
}
public int getRemoveAbandonedTimeout() {
return (int) (removeAbandonedTimeoutMillis / 1000);
}
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
this.removeAbandonedTimeoutMillis = (long) removeAbandonedTimeout * 1000;
}
public void setRemoveAbandonedTimeoutMillis(long removeAbandonedTimeoutMillis) {
this.removeAbandonedTimeoutMillis = removeAbandonedTimeoutMillis;
}
public long getRemoveAbandonedTimeoutMillis() {
return removeAbandonedTimeoutMillis;
}
public boolean isRemoveAbandoned() {
return removeAbandoned;
}
public void setRemoveAbandoned(boolean removeAbandoned) {
this.removeAbandoned = removeAbandoned;
}
public long getMinEvictableIdleTimeMillis() {
return minEvictableIdleTimeMillis;
}
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
if (minEvictableIdleTimeMillis < 1000 * 30) {
LOG.error("minEvictableIdleTimeMillis should be greater than 30000");
}
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public long getKeepAliveBetweenTimeMillis() {
return keepAliveBetweenTimeMillis;
}
public void setKeepAliveBetweenTimeMillis(long keepAliveBetweenTimeMillis) {
if (keepAliveBetweenTimeMillis < 1000 * 30) {
LOG.error("keepAliveBetweenTimeMillis should be greater than 30000");
}
if (keepAliveBetweenTimeMillis <= timeBetweenEvictionRunsMillis) {
LOG.warn("keepAliveBetweenTimeMillis should be greater than timeBetweenEvictionRunsMillis");
}
this.keepAliveBetweenTimeMillis = keepAliveBetweenTimeMillis;
}
public long getMaxEvictableIdleTimeMillis() {
return maxEvictableIdleTimeMillis;
}
public void setMaxEvictableIdleTimeMillis(long maxEvictableIdleTimeMillis) {
if (maxEvictableIdleTimeMillis < 1000 * 30) {
LOG.error("maxEvictableIdleTimeMillis should be greater than 30000");
}
if (inited && maxEvictableIdleTimeMillis < minEvictableIdleTimeMillis) {
throw new IllegalArgumentException("maxEvictableIdleTimeMillis must be grater than minEvictableIdleTimeMillis");
}
this.maxEvictableIdleTimeMillis = maxEvictableIdleTimeMillis;
}
public long getPhyTimeoutMillis() {
return phyTimeoutMillis;
}
public void setPhyTimeoutMillis(long phyTimeoutMillis) {
this.phyTimeoutMillis = phyTimeoutMillis;
}
public long getPhyMaxUseCount() {
return phyMaxUseCount;
}
public void setPhyMaxUseCount(long phyMaxUseCount) {
this.phyMaxUseCount = phyMaxUseCount;
}
public int getNumTestsPerEvictionRun() {
return numTestsPerEvictionRun;
}
/**
* @param numTestsPerEvictionRun
*/
@Deprecated
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
}
public long getTimeBetweenEvictionRunsMillis() {
return timeBetweenEvictionRunsMillis;
}
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
public int getMaxWaitThreadCount() {
return maxWaitThreadCount;
}
public void setMaxWaitThreadCount(int maxWaithThreadCount) {
this.maxWaitThreadCount = maxWaithThreadCount;
}
public String getValidationQuery() {
return validationQuery;
}
public void setValidationQuery(String validationQuery) {
this.validationQuery = validationQuery;
}
public int getValidationQueryTimeout() {
return validationQueryTimeout;
}
public void setValidationQueryTimeout(int validationQueryTimeout) {
if (validationQueryTimeout < 0 && DbType.of(dbTypeName) == DbType.sqlserver) {
LOG.error("validationQueryTimeout should be >= 0");
}
this.validationQueryTimeout = validationQueryTimeout;
}
public boolean isAccessToUnderlyingConnectionAllowed() {
return accessToUnderlyingConnectionAllowed;
}
public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) {
this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed;
}
public boolean isTestOnBorrow() {
return testOnBorrow;
}
public void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
}
public boolean isTestOnReturn() {
return testOnReturn;
}
public void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
}
public boolean isTestWhileIdle() {
return testWhileIdle;
}
public void setTestWhileIdle(boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
public boolean isDefaultAutoCommit() {
return defaultAutoCommit;
}
public void setDefaultAutoCommit(boolean defaultAutoCommit) {
this.defaultAutoCommit = defaultAutoCommit;
}
public Boolean getDefaultReadOnly() {
return defaultReadOnly;
}
public void setDefaultReadOnly(Boolean defaultReadOnly) {
this.defaultReadOnly = defaultReadOnly;
}
public Integer getDefaultTransactionIsolation() {
return defaultTransactionIsolation;
}
public void setDefaultTransactionIsolation(Integer defaultTransactionIsolation) {
this.defaultTransactionIsolation = defaultTransactionIsolation;
}
public String getDefaultCatalog() {
return defaultCatalog;
}
public void setDefaultCatalog(String defaultCatalog) {
this.defaultCatalog = defaultCatalog;
}
public PasswordCallback getPasswordCallback() {
return passwordCallback;
}
public void setPasswordCallback(PasswordCallback passwordCallback) {
this.passwordCallback = passwordCallback;
}
public void setPasswordCallbackClassName(String passwordCallbackClassName) throws Exception {
Class<?> clazz = Utils.loadClass(passwordCallbackClassName);
if (clazz != null) {
this.passwordCallback = (PasswordCallback) clazz.newInstance();
} else {
LOG.error("load passwordCallback error : " + passwordCallbackClassName);
this.passwordCallback = null;
}
}
public NameCallback getUserCallback() {
return userCallback;
}
public void setUserCallback(NameCallback userCallback) {
this.userCallback = userCallback;
}
public boolean isInitVariants() {
return initVariants;
}
public void setInitVariants(boolean initVariants) {
this.initVariants = initVariants;
}
public boolean isInitGlobalVariants() {
return initGlobalVariants;
}
public void setInitGlobalVariants(boolean initGlobalVariants) {
this.initGlobalVariants = initGlobalVariants;
}
/**
* Retrieves the number of seconds the driver will wait for a <code>Statement</code> object to execute. If the limit
* is exceeded, a <code>SQLException</code> is thrown.
*
* @return the current query timeout limit in seconds; zero means there is no limit
* <code>Statement</code>
* @see #setQueryTimeout
*/
public int getQueryTimeout() {
return queryTimeout;
}
/**
* Sets the number of seconds the driver will wait for a <code>Statement</code> object to execute to the given
* number of seconds. If the limit is exceeded, an <code>SQLException</code> is thrown. A JDBC driver must apply