Browse Source

Merge pull request #89 in CORE/base-third from release/10.0 to feature/10.0

* commit 'd52dc6010e95899b7367b4db055d240d10ef29e9':
  spring.schemas edited online with Bitbucket
  线程切换,多线程同步问题
  fix import
  druid断线重连机制修复
  CORE-110 调整hibernate源码,新增单独针对session设置的batchSize属性
  SB了
  sb了
  1
  build
  hibernate batch
  druid spring调整
research/11.0
daniel 6 years ago
parent
commit
4a29aa51c6
  1. 44
      build.third_step0.gradle
  2. 2
      build.third_step1.gradle
  3. 2
      build.third_step2.gradle
  4. 2
      build.third_step3.gradle
  5. 2
      build.third_step4.gradle
  6. 2
      build.third_step5.gradle
  7. 2
      build.third_step6.gradle
  8. 18
      fine-druid/pom.xml
  9. 221
      fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java
  10. 2
      fine-druid/src/com/fr/third/alibaba/druid/stat/JdbcStatManagerFactoryBean.java
  11. 4
      fine-druid/src/com/fr/third/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreator.java
  12. 12
      fine-druid/src/com/fr/third/alibaba/druid/support/ibatis/SpringIbatisBeanTypeAutoProxyCreator.java
  13. 2
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/MBeanServerFactoryBean.java
  14. 10
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/mvc/StatHandlerInterceptor.java
  15. 20
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/BeanTypeAutoProxyCreator.java
  16. 10
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/DruidStatInterceptor.java
  17. 14
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/annotation/StatAnnotationAdvisor.java
  18. 8
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/annotation/StatAnnotationBeanPostProcessor.java
  19. 16
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/config/DruidStatBeanDefinitionParser.java
  20. 2
      fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/config/DruidStatNamespaceHandler.java
  21. 18
      fine-hibernate/pom.xml
  22. 9
      fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java
  23. 65
      fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java
  24. 2
      fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java
  25. 11
      fine-hibernate/src/com/fr/third/org/hibernate/internal/AbstractSessionImpl.java
  26. 3
      fine-hibernate/src/com/fr/third/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java
  27. 116
      fine-hibernate/src/com/fr/third/org/hibernate/property/access/spi/UnsafeGetterFieldImpl.java
  28. 160
      fine-hibernate/src/com/fr/third/org/hibernate/property/access/spi/UnsafeSetterMethodImpl.java
  29. 4
      fine-hibernate/src/com/fr/third/org/hibernate/resource/jdbc/spi/JdbcSessionOwner.java
  30. 7
      fine-spring/resources/META-INF/spring.schemas

44
build.third_step0.gradle

@ -1,15 +1,22 @@
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish'
def classesDir='build/classes/main'
tasks.withType(JavaCompile){ tasks.withType(JavaCompile){
options.encoding = 'UTF-8' options.encoding = 'UTF-8'
destinationDir = file('build/classes/main') destinationDir = file(classesDir)
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
} }
//jdk版本 //jdk版本
sourceCompatibility=1.5 sourceCompatibility=1.5
def jarname="fine-third-10.0.jar"
def classesDir='build/classes/main'
//lib下的jar到classes文件夹 //lib下的jar到classes文件夹
version='10.0'
jar{ jar{
baseName="fine-third-10.0" baseName="fine-third"
} }
repositories { repositories {
@ -28,10 +35,13 @@ sourceSets{
} }
// //
FileTree files =fileTree(dir:'./',include:'build.*.gradle') FileTree files =fileTree(dir:'./',include:'build*.gradle')
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator)) def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf (java.io.File.separator))
def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1) def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1)
def srcDir="." def srcDir="."
def maven_version="${version}-RELEASE-SNAPSHOT"
def jar_version = version
configurations { configurations {
thirdjar thirdjar
@ -39,12 +49,34 @@ configurations {
} }
dependencies { dependencies {
thirdjar "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" thirdjar "com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT"
sigar "com.fr.third:sigar:1.6.0" sigar "com.fr.third:sigar:1.6.0"
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }
publishing {
publications {
third(MavenPublication) {
groupId "com.fr.third"
artifactId "fine-third"
version maven_version
from components.java
}
}
repositories {
maven {
url "http://mvn.finedevelop.com/repository/fanruan/"
credentials {
username = findProperty("NEXUS_USERNAME")
password = findProperty("NEXUS_PASSWORD")
}
}
}
}
task unpack(type:Copy) { task unpack(type:Copy) {
delete classesDir delete classesDir
destinationDir=file(classesDir) destinationDir=file(classesDir)

2
build.third_step1.gradle

@ -56,7 +56,7 @@ dependencies{
compile fileTree(dir:"${srcDir}/fine-poi/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-poi/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/fine-quartz/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-quartz/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar')
compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" compile "com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT"
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

2
build.third_step2.gradle

@ -45,7 +45,7 @@ dependencies{
compile fileTree(dir:"${srcDir}/fine-aspectj/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-aspectj/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/fine-spring/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-spring/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar')
compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" compile "com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT"
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

2
build.third_step3.gradle

@ -46,7 +46,7 @@ def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+
dependencies{ dependencies{
compile fileTree(dir:"${srcDir}/fine-jboss-logging/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-jboss-logging/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar')
compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" compile "com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT"
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

2
build.third_step4.gradle

@ -45,7 +45,7 @@ def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+
dependencies{ dependencies{
compile fileTree(dir:"${srcDir}/fine-hibernate/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-hibernate/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar')
compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" compile "com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT"
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

2
build.third_step5.gradle

@ -44,7 +44,7 @@ dependencies{
compile fileTree(dir:"${srcDir}/fine-druid/lib",include:'ojdbc7-12.1.0.jar') compile fileTree(dir:"${srcDir}/fine-druid/lib",include:'ojdbc7-12.1.0.jar')
compile fileTree(dir:"${srcDir}/fine-druid/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-druid/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar')
compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" compile "com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT"
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

2
build.third_step6.gradle

@ -66,7 +66,7 @@ dependencies{
compile fileTree(dir:"${srcDir}/fine-redisson/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-redisson/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/fine-socketio/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-socketio/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar')
compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" compile "com.fr.third:fine-third:10.0-RELEASE-SNAPSHOT"
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

18
fine-druid/pom.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.third</groupId>
<artifactId>base-third-code</artifactId>
<version>10.0-RELEASE-SNAPSHOT</version>
</parent>
<groupId>com.fr.third</groupId>
<artifactId>fine-druid</artifactId>
<version>10.0-RELEASE-SNAPSHOT</version>
</project>

221
fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSource.java

@ -100,78 +100,78 @@ import com.fr.third.alibaba.druid.wall.WallProviderStatValue;
*/ */
public class DruidDataSource extends DruidAbstractDataSource implements DruidDataSourceMBean, ManagedDataSource, Referenceable, Closeable, Cloneable, ConnectionPoolDataSource, MBeanRegistration { public class DruidDataSource extends DruidAbstractDataSource implements DruidDataSourceMBean, ManagedDataSource, Referenceable, Closeable, Cloneable, ConnectionPoolDataSource, MBeanRegistration {
private final static Log LOG = LogFactory.getLog(DruidDataSource.class); private final static Log LOG = LogFactory.getLog(DruidDataSource.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// stats // stats
private final AtomicLong recycleErrorCount = new AtomicLong(); private final AtomicLong recycleErrorCount = new AtomicLong();
private long connectCount = 0L; private long connectCount = 0L;
private long closeCount = 0L; private long closeCount = 0L;
private final AtomicLong connectErrorCount = new AtomicLong(); private final AtomicLong connectErrorCount = new AtomicLong();
private long recycleCount = 0L; private long recycleCount = 0L;
private long removeAbandonedCount = 0L; private long removeAbandonedCount = 0L;
private long notEmptyWaitCount = 0L; private long notEmptyWaitCount = 0L;
private long notEmptySignalCount = 0L; private long notEmptySignalCount = 0L;
private long notEmptyWaitNanos = 0L; private long notEmptyWaitNanos = 0L;
private int keepAliveCheckCount = 0; private int keepAliveCheckCount = 0;
private int activePeak = 0; private int activePeak = 0;
private long activePeakTime = 0; private long activePeakTime = 0;
private int poolingPeak = 0; private int poolingPeak = 0;
private long poolingPeakTime = 0; private long poolingPeakTime = 0;
// store // store
private volatile DruidConnectionHolder[] connections; private volatile DruidConnectionHolder[] connections;
private int poolingCount = 0; private int poolingCount = 0;
private int activeCount = 0; private int activeCount = 0;
private long discardCount = 0; private long discardCount = 0;
private int notEmptyWaitThreadCount = 0; private int notEmptyWaitThreadCount = 0;
private int notEmptyWaitThreadPeak = 0; private int notEmptyWaitThreadPeak = 0;
// //
private DruidConnectionHolder[] evictConnections; private DruidConnectionHolder[] evictConnections;
private DruidConnectionHolder[] keepAliveConnections; private DruidConnectionHolder[] keepAliveConnections;
// threads // threads
private ScheduledFuture<?> destroySchedulerFuture; private ScheduledFuture<?> destroySchedulerFuture;
private DestroyTask destroyTask; private DestroyTask destroyTask;
private CreateConnectionThread createConnectionThread; private CreateConnectionThread createConnectionThread;
private DestroyConnectionThread destroyConnectionThread; private DestroyConnectionThread destroyConnectionThread;
private LogStatsThread logStatsThread; private LogStatsThread logStatsThread;
private int createTaskCount; private int createTaskCount;
private final CountDownLatch initedLatch = new CountDownLatch(2); private CountDownLatch initedLatch = new CountDownLatch(2);
private volatile boolean enable = true; private volatile boolean enable = true;
private boolean resetStatEnable = true; private boolean resetStatEnable = true;
private final AtomicLong resetCount = new AtomicLong(); private final AtomicLong resetCount = new AtomicLong();
private String initStackTrace; private String initStackTrace;
private volatile boolean closed = false; private volatile boolean closed = false;
private long closeTimeMillis = -1L; private long closeTimeMillis = -1L;
protected JdbcDataSourceStat dataSourceStat; protected JdbcDataSourceStat dataSourceStat;
private boolean useGlobalDataSourceStat = false; private boolean useGlobalDataSourceStat = false;
private boolean mbeanRegistered = false; private boolean mbeanRegistered = false;
public static ThreadLocal<Long> waitNanosLocal = new ThreadLocal<Long>(); public static ThreadLocal<Long> waitNanosLocal = new ThreadLocal<Long>();
private boolean logDifferentThread = true; private boolean logDifferentThread = true;
private volatile boolean keepAlive = false; private volatile boolean keepAlive = false;
public DruidDataSource(){ public DruidDataSource() {
this(false); this(false);
} }
public DruidDataSource(boolean fairLock){ public DruidDataSource(boolean fairLock) {
super(fairLock); super(fairLock);
configFromPropety(System.getProperties()); configFromPropety(System.getProperties());
@ -602,6 +602,34 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
this.connectProperties = properties; this.connectProperties = properties;
} }
private synchronized void createThreadChange() {
String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this) + this.getUrl();
createConnectionThread = new CreateConnectionThread(threadName);
createConnectionThread.setStarted(false);
String destroyName = "Druid-ConnectionPool-Destroy-" + System.identityHashCode(this) + this.getUrl();
destroyConnectionThread = new DestroyConnectionThread(destroyName);
destroyConnectionThread.setStarted(false);
initedLatch = new CountDownLatch(2);
}
private void checkThread() throws SQLException {
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) {
synchronized (this) {//线程安全问题,加个双检锁
if (!createConnectionThread.isStarted() && !destroyConnectionThread.isStarted()) {
createConnectionThread.setStarted(true);
createConnectionThread.start();
destroyConnectionThread.setStarted(true);
destroyConnectionThread.start();
try {
initedLatch.await();
} catch (InterruptedException e) {
throw new SQLException(e.getMessage(), e);
}
}
}
}
}
public void init() throws SQLException { public void init() throws SQLException {
if (inited) { if (inited) {
return; return;
@ -645,7 +673,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
if (JdbcConstants.MYSQL.equals(this.dbType) || // if (JdbcConstants.MYSQL.equals(this.dbType) || //
JdbcConstants.MARIADB.equals(this.dbType)) { JdbcConstants.MARIADB.equals(this.dbType)) {
boolean cacheServerConfigurationSet = false; boolean cacheServerConfigurationSet = false;
if (this.connectProperties.containsKey("cacheServerConfiguration")) { if (this.connectProperties.containsKey("cacheServerConfiguration")) {
cacheServerConfigurationSet = true; cacheServerConfigurationSet = true;
@ -805,7 +833,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
period = 1000; period = 1000;
} }
destroySchedulerFuture = destroyScheduler.scheduleAtFixedRate(destroyTask, period, period, destroySchedulerFuture = destroyScheduler.scheduleAtFixedRate(destroyTask, period, period,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
initedLatch.countDown(); initedLatch.countDown();
return; return;
} }
@ -817,7 +845,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
protected void createAndStartCreatorThread() { protected void createAndStartCreatorThread() {
if (createScheduler == null) { if (createScheduler == null) {
String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this); String threadName = "Druid-ConnectionPool-Create-" + System.identityHashCode(this) + this.getUrl();
createConnectionThread = new CreateConnectionThread(threadName); createConnectionThread = new CreateConnectionThread(threadName);
createConnectionThread.start(); createConnectionThread.start();
return; return;
@ -828,7 +856,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
/** /**
* load filters from SPI ServiceLoader * load filters from SPI ServiceLoader
* *
* @see ServiceLoader * @see ServiceLoader
*/ */
private void initFromSPIServiceLoader() { private void initFromSPIServiceLoader() {
@ -873,7 +901,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
/** /**
* 会去重复 * 会去重复
* *
* @param filter * @param filter
*/ */
private void addFilter(Filter filter) { private void addFilter(Filter filter) {
@ -928,7 +956,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (driver.getMajorVersion() < 10) { if (driver.getMajorVersion() < 10) {
throw new SQLException("not support oracle driver " + driver.getMajorVersion() + "." throw new SQLException("not support oracle driver " + driver.getMajorVersion() + "."
+ driver.getMinorVersion()); + driver.getMinorVersion());
} }
if (driver.getMajorVersion() == 10 && isUseOracleImplicitCache()) { if (driver.getMajorVersion() == 10 && isUseOracleImplicitCache()) {
@ -965,7 +993,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (query instanceof SQLSelectQueryBlock) { if (query instanceof SQLSelectQueryBlock) {
if (((SQLSelectQueryBlock) query).getFrom() == null) { if (((SQLSelectQueryBlock) query).getFrom() == null) {
LOG.error("invalid oracle validationQuery. " + validationQuery + ", may should be : " + validationQuery LOG.error("invalid oracle validationQuery. " + validationQuery + ", may should be : " + validationQuery
+ " FROM DUAL"); + " FROM DUAL");
} }
} }
} }
@ -994,7 +1022,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (query instanceof SQLSelectQueryBlock) { if (query instanceof SQLSelectQueryBlock) {
if (((SQLSelectQueryBlock) query).getFrom() == null) { if (((SQLSelectQueryBlock) query).getFrom() == null) {
LOG.error("invalid db2 validationQuery. " + validationQuery + ", may should be : " + validationQuery LOG.error("invalid db2 validationQuery. " + validationQuery + ", may should be : " + validationQuery
+ " FROM SYSDUMMY"); + " FROM SYSDUMMY");
} }
} }
} }
@ -1002,14 +1030,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private void initValidConnectionChecker() { private void initValidConnectionChecker() {
String realDriverClassName = driver.getClass().getName(); String realDriverClassName = driver.getClass().getName();
if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER) // if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER) //
|| realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) { || realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) {
this.validConnectionChecker = new MySqlValidConnectionChecker(); this.validConnectionChecker = new MySqlValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER) } else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER)
|| realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) { || realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) {
this.validConnectionChecker = new OracleValidConnectionChecker(); this.validConnectionChecker = new OracleValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER) } else if (realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER)
|| realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_SQLJDBC4) || realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_SQLJDBC4)
|| realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_JTDS)) { || realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_JTDS)) {
this.validConnectionChecker = new MSSQLValidConnectionChecker(); this.validConnectionChecker = new MSSQLValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.POSTGRESQL_DRIVER)) { } else if (realDriverClassName.equals(JdbcConstants.POSTGRESQL_DRIVER)) {
this.validConnectionChecker = new PGValidConnectionChecker(); this.validConnectionChecker = new PGValidConnectionChecker();
@ -1027,7 +1055,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
String realDriverClassName = driver.getClass().getName(); String realDriverClassName = driver.getClass().getName();
if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER) // if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER) //
|| realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) { || realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) {
this.exceptionSorter = new MySqlExceptionSorter(); this.exceptionSorter = new MySqlExceptionSorter();
} else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER) } else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER)
|| realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) { || realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) {
@ -1055,7 +1083,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public DruidPooledConnection getConnection(long maxWaitMillis) throws SQLException { public DruidPooledConnection getConnection(long maxWaitMillis) throws SQLException {
init(); init();
checkThread();
if (filters.size() > 0) { if (filters.size() > 0) {
FilterChainImpl filterChain = new FilterChainImpl(this); FilterChainImpl filterChain = new FilterChainImpl(this);
return filterChain.dataSource_connect(this, maxWaitMillis); return filterChain.dataSource_connect(this, maxWaitMillis);
@ -1076,7 +1104,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public DruidPooledConnection getConnectionDirect(long maxWaitMillis) throws SQLException { public DruidPooledConnection getConnectionDirect(long maxWaitMillis) throws SQLException {
int notFullTimeoutRetryCnt = 0; int notFullTimeoutRetryCnt = 0;
for (;;) { for (; ; ) {
// handle notFullTimeoutRetry // handle notFullTimeoutRetry
DruidPooledConnection poolableConnection; DruidPooledConnection poolableConnection;
try { try {
@ -1157,7 +1185,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
/** /**
* 抛弃连接不进行回收而是抛弃 * 抛弃连接不进行回收而是抛弃
* *
* @param realConnection * @param realConnection
*/ */
public void discardConnection(Connection realConnection) { public void discardConnection(Connection realConnection) {
@ -1203,7 +1231,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (notEmptyWaitThreadCount >= maxWaitThreadCount) { if (notEmptyWaitThreadCount >= maxWaitThreadCount) {
connectErrorCount.incrementAndGet(); connectErrorCount.incrementAndGet();
throw new SQLException("maxWaitThreadCount " + maxWaitThreadCount + ", current wait Thread count " throw new SQLException("maxWaitThreadCount " + maxWaitThreadCount + ", current wait Thread count "
+ lock.getQueueLength()); + lock.getQueueLength());
} }
} }
@ -1235,7 +1263,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (holder == null) { if (holder == null) {
Throwable throwable = this.createError; Throwable throwable = this.createError;
if (throwable != null) { if (throwable != null) {
if(throwable instanceof SQLException){ if (throwable instanceof SQLException) {
throw (SQLException) throwable; throw (SQLException) throwable;
} }
throw new GetConnectionTimeoutException(throwable.getMessage(), throwable); throw new GetConnectionTimeoutException(throwable.getMessage(), throwable);
@ -1249,7 +1277,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
.append(", maxActive " + maxActive)// .append(", maxActive " + maxActive)//
; ;
JdbcDataSourceStat sourceStat = this.getDataSourceStat(); JdbcDataSourceStat sourceStat = this.getDataSourceStat();
if(sourceStat != null) { if (sourceStat != null) {
List<JdbcSqlStatValue> sqlList = sourceStat.getRuningSqlList(); List<JdbcSqlStatValue> sqlList = sourceStat.getRuningSqlList();
for (int i = 0; i < sqlList.size(); ++i) { for (int i = 0; i < sqlList.size(); ++i) {
if (i != 0) { if (i != 0) {
@ -1344,9 +1372,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
if (logDifferentThread // if (logDifferentThread //
&& (!isAsyncCloseConnectionEnable()) // && (!isAsyncCloseConnectionEnable()) //
&& pooledConnection.getOwnerThread() != Thread.currentThread()// && pooledConnection.getOwnerThread() != Thread.currentThread()//
) { ) {
LOG.warn("get/close not same thread"); LOG.warn("get/close not same thread");
} }
@ -1543,7 +1571,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
@Override @Override
public Object run() { public Object run() {
ObjectName objectName = DruidDataSourceStatManager.addDataSource(DruidDataSource.this, ObjectName objectName = DruidDataSourceStatManager.addDataSource(DruidDataSource.this,
DruidDataSource.this.name); DruidDataSource.this.name);
DruidDataSource.this.setObjectName(objectName); DruidDataSource.this.setObjectName(objectName);
DruidDataSource.this.mbeanRegistered = true; DruidDataSource.this.mbeanRegistered = true;
@ -1633,7 +1661,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private DruidConnectionHolder pollLast(long nanos) throws InterruptedException, SQLException { private DruidConnectionHolder pollLast(long nanos) throws InterruptedException, SQLException {
long estimate = nanos; long estimate = nanos;
for (;;) { for (; ; ) {
if (poolingCount == 0) { if (poolingCount == 0) {
emptySignal(); // send signal to CreateThread create connection emptySignal(); // send signal to CreateThread create connection
@ -1654,8 +1682,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
try { try {
long startEstimate = estimate; long startEstimate = estimate;
estimate = notEmpty.awaitNanos(estimate); // signal by estimate = notEmpty.awaitNanos(estimate); // signal by
// recycle or // recycle or
// creator // creator
notEmptyWaitCount++; notEmptyWaitCount++;
notEmptyWaitNanos += (startEstimate - estimate); notEmptyWaitNanos += (startEstimate - estimate);
@ -1926,7 +1954,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
createTaskCount--; createTaskCount--;
if (poolingCount + createTaskCount < notEmptyWaitThreadCount // if (poolingCount + createTaskCount < notEmptyWaitThreadCount //
&& activeCount + poolingCount + createTaskCount < maxActive) { && activeCount + poolingCount + createTaskCount < maxActive) {
emptySignal(); emptySignal();
} }
} }
@ -1946,7 +1974,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
private void runInternal() { private void runInternal() {
for (;;) { for (; ; ) {
// addLast // addLast
lock.lock(); lock.lock();
@ -2043,8 +2071,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
public class CreateConnectionThread extends Thread { public class CreateConnectionThread extends Thread {
private volatile boolean started = true;
public CreateConnectionThread(String name){ public CreateConnectionThread(String name) {
super(name); super(name);
this.setDaemon(true); this.setDaemon(true);
} }
@ -2054,7 +2083,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
long lastDiscardCount = 0; long lastDiscardCount = 0;
int errorCount = 0; int errorCount = 0;
for (;;) { for (; ; ) {
// addLast // addLast
try { try {
lock.lockInterruptibly(); lock.lockInterruptibly();
@ -2102,7 +2131,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
setFailContinuous(false); setFailContinuous(false);
} catch (SQLException e) { } catch (SQLException e) {
LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + e.getErrorCode() LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + e.getErrorCode()
+ ", state " + e.getSQLState(), e); + ", state " + e.getSQLState(), e);
errorCount++; errorCount++;
if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) { if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) {
@ -2126,6 +2155,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} catch (InterruptedException interruptEx) { } catch (InterruptedException interruptEx) {
break; break;
} }
DruidDataSource.this.createThreadChange();
break;
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOG.error("create connection error", e); LOG.error("create connection error", e);
@ -2150,11 +2181,20 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
errorCount = 0; // reset errorCount errorCount = 0; // reset errorCount
} }
} }
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
this.started = started;
}
} }
public class DestroyConnectionThread extends Thread { public class DestroyConnectionThread extends Thread {
private volatile boolean started = true;
public DestroyConnectionThread(String name){ public DestroyConnectionThread(String name) {
super(name); super(name);
this.setDaemon(true); this.setDaemon(true);
} }
@ -2162,7 +2202,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public void run() { public void run() {
initedLatch.countDown(); initedLatch.countDown();
for (;;) { for (; ; ) {
// 从前面开始删除 // 从前面开始删除
try { try {
if (closed) { if (closed) {
@ -2186,6 +2226,13 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
} }
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
this.started = started;
}
} }
public class DestroyTask implements Runnable { public class DestroyTask implements Runnable {
@ -2203,14 +2250,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public class LogStatsThread extends Thread { public class LogStatsThread extends Thread {
public LogStatsThread(String name){ public LogStatsThread(String name) {
super(name); super(name);
this.setDaemon(true); this.setDaemon(true);
} }
public void run() { public void run() {
try { try {
for (;;) { for (; ; ) {
try { try {
logStats(); logStats();
} catch (Exception e) { } catch (Exception e) {
@ -2236,7 +2283,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
try { try {
Iterator<DruidPooledConnection> iter = activeConnections.keySet().iterator(); Iterator<DruidPooledConnection> iter = activeConnections.keySet().iterator();
for (; iter.hasNext();) { for (; iter.hasNext(); ) {
DruidPooledConnection pooledConnection = iter.next(); DruidPooledConnection pooledConnection = iter.next();
if (pooledConnection.isRunning()) { if (pooledConnection.isRunning()) {
@ -2288,7 +2335,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
buf.append("ownerThread current state is " + pooledConnection.getOwnerThread().getState() buf.append("ownerThread current state is " + pooledConnection.getOwnerThread().getState()
+ ", current stackTrace\n"); + ", current stackTrace\n");
trace = pooledConnection.getOwnerThread().getStackTrace(); trace = pooledConnection.getOwnerThread().getStackTrace();
for (int i = 0; i < trace.length; i++) { for (int i = 0; i < trace.length; i++) {
buf.append("\tat "); buf.append("\tat ");
@ -2304,7 +2351,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
return removeCount; return removeCount;
} }
/** Instance key */ /**
* Instance key
*/
protected String instanceKey = null; protected String instanceKey = null;
public Reference getReference() throws NamingException { public Reference getReference() throws NamingException {
@ -2938,7 +2987,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
if (this.statLogger != null if (this.statLogger != null
&& (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) { && (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) {
return true; return true;
} }
@ -2954,7 +3003,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
if (this.statLogger != null if (this.statLogger != null
&& (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) { && (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) {
return (T) statLogger; return (T) statLogger;
} }
@ -2998,7 +3047,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} }
int fillCount = 0; int fillCount = 0;
for (;;) { for (; ; ) {
try { try {
lock.lockInterruptibly(); lock.lockInterruptibly();
} catch (InterruptedException e) { } catch (InterruptedException e) {

2
fine-druid/src/com/fr/third/alibaba/druid/stat/JdbcStatManagerFactoryBean.java

@ -15,7 +15,7 @@
*/ */
package com.fr.third.alibaba.druid.stat; package com.fr.third.alibaba.druid.stat;
import org.springframework.beans.factory.FactoryBean; import com.fr.third.springframework.beans.factory.FactoryBean;
public class JdbcStatManagerFactoryBean implements FactoryBean<JdbcStatManager> { public class JdbcStatManagerFactoryBean implements FactoryBean<JdbcStatManager> {

4
fine-druid/src/com/fr/third/alibaba/druid/support/ibatis/SpringIbatisBeanNameAutoProxyCreator.java

@ -20,8 +20,8 @@ import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource; import com.fr.third.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator; import com.fr.third.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient; import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;

12
fine-druid/src/com/fr/third/alibaba/druid/support/ibatis/SpringIbatisBeanTypeAutoProxyCreator.java

@ -19,11 +19,11 @@ import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient; import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource; import com.fr.third.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator; import com.fr.third.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.factory.BeanFactory; import com.fr.third.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean; import com.fr.third.springframework.beans.factory.FactoryBean;
import org.springframework.util.PatternMatchUtils; import com.fr.third.springframework.util.PatternMatchUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -95,7 +95,7 @@ public class SpringIbatisBeanTypeAutoProxyCreator extends AbstractAutoProxyCreat
* @param beanName the bean name to check * @param beanName the bean name to check
* @param mappedName the name in the configured list of names * @param mappedName the name in the configured list of names
* @return if the names match * @return if the names match
* @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String) * @see com.fr.third.springframework.util.PatternMatchUtils#simpleMatch(String, String)
*/ */
protected boolean isMatch(String beanName, String mappedName) { protected boolean isMatch(String beanName, String mappedName) {
return PatternMatchUtils.simpleMatch(mappedName, beanName); return PatternMatchUtils.simpleMatch(mappedName, beanName);

2
fine-druid/src/com/fr/third/alibaba/druid/support/spring/MBeanServerFactoryBean.java

@ -19,7 +19,7 @@ import java.lang.management.ManagementFactory;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import org.springframework.beans.factory.FactoryBean; import com.fr.third.springframework.beans.factory.FactoryBean;
public class MBeanServerFactoryBean implements FactoryBean<MBeanServer> { public class MBeanServerFactoryBean implements FactoryBean<MBeanServer> {

10
fine-druid/src/com/fr/third/alibaba/druid/support/spring/mvc/StatHandlerInterceptor.java

@ -24,11 +24,11 @@ import javax.servlet.http.HttpServletResponse;
import com.fr.third.alibaba.druid.filter.stat.StatFilterContext; import com.fr.third.alibaba.druid.filter.stat.StatFilterContext;
import com.fr.third.alibaba.druid.support.http.stat.WebSessionStat; import com.fr.third.alibaba.druid.support.http.stat.WebSessionStat;
import com.fr.third.alibaba.druid.support.http.stat.WebURIStat; import com.fr.third.alibaba.druid.support.http.stat.WebURIStat;
import org.springframework.beans.factory.DisposableBean; import com.fr.third.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import com.fr.third.springframework.beans.factory.InitializingBean;
import org.springframework.web.servlet.HandlerInterceptor; import com.fr.third.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping; import com.fr.third.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView; import com.fr.third.springframework.web.servlet.ModelAndView;
import com.fr.third.alibaba.druid.support.http.AbstractWebStatImpl; import com.fr.third.alibaba.druid.support.http.AbstractWebStatImpl;
import com.fr.third.alibaba.druid.support.http.stat.WebAppStat; import com.fr.third.alibaba.druid.support.http.stat.WebAppStat;

20
fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/BeanTypeAutoProxyCreator.java

@ -15,15 +15,15 @@
*/ */
package com.fr.third.alibaba.druid.support.spring.stat; package com.fr.third.alibaba.druid.support.spring.stat;
import org.springframework.aop.TargetSource; import com.fr.third.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator; import com.fr.third.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.factory.BeanFactory; import com.fr.third.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean; import com.fr.third.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import com.fr.third.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext; import com.fr.third.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import com.fr.third.springframework.context.ApplicationContextAware;
import org.springframework.util.Assert; import com.fr.third.springframework.util.Assert;
import org.springframework.util.PatternMatchUtils; import com.fr.third.springframework.util.PatternMatchUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -83,7 +83,7 @@ public class BeanTypeAutoProxyCreator extends AbstractAutoProxyCreator implement
* @param beanName the bean name to check * @param beanName the bean name to check
* @param mappedName the name in the configured list of names * @param mappedName the name in the configured list of names
* @return if the names match * @return if the names match
* @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String) * @see com.fr.third.springframework.util.PatternMatchUtils#simpleMatch(String, String)
*/ */
protected boolean isMatch(String beanName, String mappedName) { protected boolean isMatch(String beanName, String mappedName) {
return PatternMatchUtils.simpleMatch(mappedName, beanName); return PatternMatchUtils.simpleMatch(mappedName, beanName);

10
fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/DruidStatInterceptor.java

@ -21,9 +21,9 @@ import com.fr.third.alibaba.druid.support.logging.Log;
import com.fr.third.alibaba.druid.support.logging.LogFactory; import com.fr.third.alibaba.druid.support.logging.LogFactory;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.TargetSource; import com.fr.third.springframework.aop.TargetSource;
import org.springframework.beans.factory.DisposableBean; import com.fr.third.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import com.fr.third.springframework.beans.factory.InitializingBean;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -123,8 +123,8 @@ public class DruidStatInterceptor implements MethodInterceptor, InitializingBean
try { try {
// 最多支持10层代理 // 最多支持10层代理
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
if (thisObject instanceof org.springframework.aop.framework.Advised) { if (thisObject instanceof com.fr.third.springframework.aop.framework.Advised) {
TargetSource targetSource = ((org.springframework.aop.framework.Advised) thisObject).getTargetSource(); TargetSource targetSource = ((com.fr.third.springframework.aop.framework.Advised) thisObject).getTargetSource();
if (targetSource == null) { if (targetSource == null) {
break; break;

14
fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/annotation/StatAnnotationAdvisor.java

@ -17,13 +17,13 @@ package com.fr.third.alibaba.druid.support.spring.stat.annotation;
import com.fr.third.alibaba.druid.support.spring.stat.DruidStatInterceptor; import com.fr.third.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import org.aopalliance.aop.Advice; import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut; import com.fr.third.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor; import com.fr.third.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.ComposablePointcut; import com.fr.third.springframework.aop.support.ComposablePointcut;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut; import com.fr.third.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.beans.BeansException; import com.fr.third.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory; import com.fr.third.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware; import com.fr.third.springframework.beans.factory.BeanFactoryAware;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class StatAnnotationAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware { public class StatAnnotationAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware {

8
fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/annotation/StatAnnotationBeanPostProcessor.java

@ -18,10 +18,10 @@ package com.fr.third.alibaba.druid.support.spring.stat.annotation;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.fr.third.alibaba.druid.support.spring.stat.DruidStatInterceptor; import com.fr.third.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor; import com.fr.third.springframework.aop.framework.AbstractAdvisingBeanPostProcessor;
import org.springframework.beans.BeansException; import com.fr.third.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory; import com.fr.third.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware; import com.fr.third.springframework.beans.factory.BeanFactoryAware;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class StatAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor implements BeanFactoryAware { public class StatAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor implements BeanFactoryAware {

16
fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/config/DruidStatBeanDefinitionParser.java

@ -15,14 +15,14 @@
*/ */
package com.fr.third.alibaba.druid.support.spring.stat.config; package com.fr.third.alibaba.druid.support.spring.stat.config;
import org.springframework.beans.factory.config.BeanDefinition; import com.fr.third.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder; import com.fr.third.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.parsing.BeanComponentDefinition; import com.fr.third.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.parsing.CompositeComponentDefinition; import com.fr.third.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder; import com.fr.third.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import com.fr.third.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.xml.BeanDefinitionParser; import com.fr.third.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext; import com.fr.third.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element; import org.w3c.dom.Element;
public class DruidStatBeanDefinitionParser implements BeanDefinitionParser { public class DruidStatBeanDefinitionParser implements BeanDefinitionParser {

2
fine-druid/src/com/fr/third/alibaba/druid/support/spring/stat/config/DruidStatNamespaceHandler.java

@ -15,7 +15,7 @@
*/ */
package com.fr.third.alibaba.druid.support.spring.stat.config; package com.fr.third.alibaba.druid.support.spring.stat.config;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport; import com.fr.third.springframework.beans.factory.xml.NamespaceHandlerSupport;
public class DruidStatNamespaceHandler extends NamespaceHandlerSupport { public class DruidStatNamespaceHandler extends NamespaceHandlerSupport {

18
fine-hibernate/pom.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.third</groupId>
<artifactId>base-third-code</artifactId>
<version>10.0-RELEASE-SNAPSHOT</version>
</parent>
<groupId>com.fr.third</groupId>
<artifactId>fine-hibernate</artifactId>
<version>10.0-RELEASE-SNAPSHOT</version>
</project>

9
fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java

@ -61,9 +61,12 @@ public class BatchBuilderImpl implements BatchBuilder, Configurable, Manageable,
@Override @Override
public Batch buildBatch(BatchKey key, JdbcCoordinator jdbcCoordinator) { public Batch buildBatch(BatchKey key, JdbcCoordinator jdbcCoordinator) {
LOG.tracef( "Building batch [size=%s]", size ); int batchSize = jdbcCoordinator.getJdbcSessionOwner().getJdbcBatchSize() > 1
return size > 1 ? jdbcCoordinator.getJdbcSessionOwner().getJdbcBatchSize()
? new BatchingBatch( key, jdbcCoordinator, size ) : size;
LOG.tracef( "Building batch [size=%s]", batchSize );
return batchSize > 1
? new BatchingBatch( key, jdbcCoordinator, batchSize )
: new NonBatchingBatch( key, jdbcCoordinator ); : new NonBatchingBatch( key, jdbcCoordinator );
} }

65
fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java

@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.fr.third.org.jboss.logging.Logger; import com.fr.third.org.jboss.logging.Logger;
@ -187,10 +188,14 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
LOG.tracev( "Closing JDBC container [{0}]", this ); LOG.tracev( "Closing JDBC container [{0}]", this );
Connection connection; Connection connection;
try { try {
if ( currentBatch != null ) { LOG.closingUnreleasedBatch();
LOG.closingUnreleasedBatch(); for(Map.Entry<BatchKey, Batch> e : batchMap.entrySet()){
currentBatch.release(); e.getValue().release();
} }
// if ( currentBatch != null ) {
// LOG.closingUnreleasedBatch();
// currentBatch.release();
// }
cleanup(); cleanup();
} }
finally { finally {
@ -199,35 +204,55 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
return connection; return connection;
} }
private Map<BatchKey, Batch> batchMap = new ConcurrentHashMap<BatchKey, Batch>();
@Override @Override
public Batch getBatch(BatchKey key) { public Batch getBatch(BatchKey key) {
if ( currentBatch != null ) { Batch batch = batchMap.get(key);
if ( currentBatch.getKey().equals( key ) ) { if(batch == null) {
return currentBatch; batch = batchBuilder().buildBatch( key, this );
} batchMap.put(key, batch);
else { }
currentBatch.execute(); return batch;
currentBatch.release();
} //
} // if ( currentBatch != null ) {
currentBatch = batchBuilder().buildBatch( key, this ); // if ( currentBatch.getKey().equals( key ) ) {
return currentBatch; // return currentBatch;
// }
// else {
// currentBatch.execute();
// currentBatch.release();
// }
// }
// currentBatch = batchBuilder().buildBatch( key, this );
// return currentBatch;
} }
@Override @Override
public void executeBatch() { public void executeBatch() {
if ( currentBatch != null ) { for(Map.Entry<BatchKey, Batch> e : batchMap.entrySet()){
currentBatch.execute(); e.getValue().execute();
// needed? e.getValue().release();
currentBatch.release();
} }
// if ( currentBatch != null ) {
// currentBatch.execute();
// // needed?
// currentBatch.release();
// }
} }
@Override @Override
public void abortBatch() { public void abortBatch() {
if ( currentBatch != null ) {
currentBatch.release(); for(Map.Entry<BatchKey, Batch> e : batchMap.entrySet()){
e.getValue().release();
} }
// if ( currentBatch != null ) {
// currentBatch.release();
// }
} }
private transient StatementPreparer statementPreparer; private transient StatementPreparer statementPreparer;

2
fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java

@ -74,7 +74,7 @@ class StatementPreparerImpl implements StatementPreparer {
@Override @Override
public PreparedStatement prepareStatement(String sql, final boolean isCallable) { public PreparedStatement prepareStatement(String sql, final boolean isCallable) {
jdbcCoordinator.executeBatch(); //jdbcCoordinator.executeBatch();
return buildPreparedStatementPreparationTemplate( sql, isCallable ).prepareStatement(); return buildPreparedStatementPreparationTemplate( sql, isCallable ).prepareStatement();
} }

11
fine-hibernate/src/com/fr/third/org/hibernate/internal/AbstractSessionImpl.java

@ -71,6 +71,7 @@ public abstract class AbstractSessionImpl
protected transient SessionFactoryImpl factory; protected transient SessionFactoryImpl factory;
private final String tenantIdentifier; private final String tenantIdentifier;
private boolean closed; private boolean closed;
private int jdbcBatchSize;
protected transient Transaction currentHibernateTransaction; protected transient Transaction currentHibernateTransaction;
protected transient WrapperOptionsImpl wrapperOptions; protected transient WrapperOptionsImpl wrapperOptions;
@ -609,4 +610,14 @@ public abstract class AbstractSessionImpl
return wrapperOptions; return wrapperOptions;
} }
@Override
public int getJdbcBatchSize() {
return jdbcBatchSize;
}
@Override
public void setJdbcBatchSize(int jdbcBatchSize) {
this.jdbcBatchSize = jdbcBatchSize;
}
} }

3
fine-hibernate/src/com/fr/third/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java

@ -15,6 +15,7 @@ import com.fr.third.org.hibernate.property.access.spi.PropertyAccess;
import com.fr.third.org.hibernate.property.access.spi.PropertyAccessStrategy; import com.fr.third.org.hibernate.property.access.spi.PropertyAccessStrategy;
import com.fr.third.org.hibernate.property.access.spi.Setter; import com.fr.third.org.hibernate.property.access.spi.Setter;
import com.fr.third.org.hibernate.property.access.spi.SetterFieldImpl; import com.fr.third.org.hibernate.property.access.spi.SetterFieldImpl;
import com.fr.third.org.hibernate.property.access.spi.UnsafeGetterFieldImpl;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -32,7 +33,7 @@ public class PropertyAccessFieldImpl implements PropertyAccess {
this.strategy = strategy; this.strategy = strategy;
final Field field = ReflectHelper.findField( containerJavaType, propertyName ); final Field field = ReflectHelper.findField( containerJavaType, propertyName );
this.getter = new GetterFieldImpl( containerJavaType, propertyName, field ); this.getter = new UnsafeGetterFieldImpl( containerJavaType, propertyName, field );
this.setter = new SetterFieldImpl( containerJavaType, propertyName, field ); this.setter = new SetterFieldImpl( containerJavaType, propertyName, field );
} }

116
fine-hibernate/src/com/fr/third/org/hibernate/property/access/spi/UnsafeGetterFieldImpl.java

@ -0,0 +1,116 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package com.fr.third.org.hibernate.property.access.spi;
import com.fr.third.org.hibernate.engine.spi.SessionImplementor;
import com.fr.third.org.hibernate.property.access.internal.AbstractFieldSerialForm;
import sun.misc.Unsafe;
import sun.reflect.FieldAccessor;
import sun.reflect.ReflectionFactory;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.util.Locale;
import java.util.Map;
/**
* Field-based implementation of Getter
*
* @author Steve Ebersole
*/
public class UnsafeGetterFieldImpl implements Getter {
private final Class containerClass;
private final String propertyName;
private final Field field;
private final FieldAccessor accessor;
static ReflectionFactory reflectionFactory =
AccessController.doPrivileged(
new sun.reflect.ReflectionFactory.GetReflectionFactoryAction());
public UnsafeGetterFieldImpl(Class containerClass, String propertyName, Field field) {
this.containerClass = containerClass;
this.propertyName = propertyName;
this.field = field;
accessor = reflectionFactory.newFieldAccessor(field, false);
}
@Override
public Object get(Object owner) {
if(accessor != null){
return accessor.get(owner);
}
try {
return field.get( owner );
}
catch (Exception e) {
throw new PropertyAccessException(
String.format(
Locale.ROOT,
"Error accessing field [%s] by reflection for persistent property [%s#%s] : %s",
field.toGenericString(),
containerClass.getName(),
propertyName,
owner
),
e
);
}
}
@Override
public Object getForInsert(Object owner, Map mergeMap, SessionImplementor session) {
return get( owner );
}
@Override
public Class getReturnType() {
return field.getType();
}
@Override
public Member getMember() {
return field;
}
@Override
public String getMethodName() {
return null;
}
@Override
public Method getMethod() {
return null;
}
private Object writeReplace() throws ObjectStreamException {
return new SerialForm( containerClass, propertyName, field );
}
private static class SerialForm extends AbstractFieldSerialForm implements Serializable {
private final Class containerClass;
private final String propertyName;
private SerialForm(Class containerClass, String propertyName, Field field) {
super( field );
this.containerClass = containerClass;
this.propertyName = propertyName;
}
private Object readResolve() {
return new UnsafeGetterFieldImpl( containerClass, propertyName, resolveField() );
}
}
}

160
fine-hibernate/src/com/fr/third/org/hibernate/property/access/spi/UnsafeSetterMethodImpl.java

@ -0,0 +1,160 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package com.fr.third.org.hibernate.property.access.spi;
import com.fr.third.org.hibernate.PropertyAccessException;
import com.fr.third.org.hibernate.PropertySetterAccessException;
import com.fr.third.org.hibernate.engine.spi.SessionFactoryImplementor;
import com.fr.third.org.hibernate.internal.CoreMessageLogger;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import static com.fr.third.org.hibernate.internal.CoreLogging.messageLogger;
/**
* @author Steve Ebersole
*/
public class UnsafeSetterMethodImpl implements Setter {
private static final CoreMessageLogger LOG = messageLogger( UnsafeSetterMethodImpl.class );
private final Class containerClass;
private final String propertyName;
private final Method setterMethod;
private final boolean isPrimitive;
public UnsafeSetterMethodImpl(Class containerClass, String propertyName, Method setterMethod) {
this.containerClass = containerClass;
this.propertyName = propertyName;
this.setterMethod = setterMethod;
this.isPrimitive = setterMethod.getParameterTypes()[0].isPrimitive();
}
@Override
public void set(Object target, Object value, SessionFactoryImplementor factory) {
try {
setterMethod.invoke( target, value );
}
catch (NullPointerException npe) {
if ( value == null && isPrimitive ) {
throw new PropertyAccessException(
npe,
"Null value was assigned to a property of primitive type",
true,
containerClass,
propertyName
);
}
else {
throw new PropertyAccessException(
npe,
"NullPointerException occurred while calling",
true,
containerClass,
propertyName
);
}
}
catch (InvocationTargetException ite) {
throw new PropertyAccessException(
ite,
"Exception occurred inside",
true,
containerClass,
propertyName
);
}
catch (IllegalAccessException iae) {
throw new PropertyAccessException(
iae,
"IllegalAccessException occurred while calling",
true,
containerClass,
propertyName
);
//cannot occur
}
catch (IllegalArgumentException iae) {
if ( value == null && isPrimitive ) {
throw new PropertyAccessException(
iae,
"Null value was assigned to a property of primitive type",
true,
containerClass,
propertyName
);
}
else {
final Class expectedType = setterMethod.getParameterTypes()[0];
LOG.illegalPropertySetterArgument( containerClass.getName(), propertyName );
LOG.expectedType( expectedType.getName(), value == null ? null : value.getClass().getName() );
throw new PropertySetterAccessException(
iae,
containerClass,
propertyName,
expectedType,
target,
value
);
}
}
}
@Override
public String getMethodName() {
return setterMethod.getName();
}
@Override
public Method getMethod() {
return setterMethod;
}
private Object writeReplace() throws ObjectStreamException {
return new SerialForm( containerClass, propertyName, setterMethod );
}
private static class SerialForm implements Serializable {
private final Class containerClass;
private final String propertyName;
private final Class declaringClass;
private final String methodName;
private final Class argumentType;
private SerialForm(Class containerClass, String propertyName, Method method) {
this.containerClass = containerClass;
this.propertyName = propertyName;
this.declaringClass = method.getDeclaringClass();
this.methodName = method.getName();
this.argumentType = method.getParameterTypes()[0];
}
private Object readResolve() {
return new UnsafeSetterMethodImpl( containerClass, propertyName, resolveMethod() );
}
@SuppressWarnings("unchecked")
private Method resolveMethod() {
try {
final Method method = declaringClass.getDeclaredMethod( methodName, argumentType );
method.setAccessible( true );
return method;
}
catch (NoSuchMethodException e) {
throw new PropertyAccessSerializationException(
"Unable to resolve setter method on deserialization : " + declaringClass.getName() + "#"
+ methodName + "(" + argumentType.getName() + ")"
);
}
}
}
}

4
fine-hibernate/src/com/fr/third/org/hibernate/resource/jdbc/spi/JdbcSessionOwner.java

@ -43,4 +43,8 @@ public interface JdbcSessionOwner {
public void afterTransactionCompletion(boolean successful, boolean delayed); public void afterTransactionCompletion(boolean successful, boolean delayed);
public void flushBeforeTransactionCompletion(); public void flushBeforeTransactionCompletion();
public int getJdbcBatchSize();
public void setJdbcBatchSize(int jdbcBatchSize);
} }

7
fine-spring/resources/META-INF/spring.schemas

@ -33,3 +33,10 @@ http\://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd=com/fr/third/sprin
http\://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd=com/fr/third/springframework/web/servlet/config/spring-mvc-4.0.xsd http\://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd=com/fr/third/springframework/web/servlet/config/spring-mvc-4.0.xsd
http\://www.springframework.org/schema/mvc/spring-mvc.xsd=com/fr/third/springframework/web/servlet/config/spring-mvc-4.0.xsd http\://www.springframework.org/schema/mvc/spring-mvc.xsd=com/fr/third/springframework/web/servlet/config/spring-mvc-4.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.2.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-3.2.xsd
http\://www.springframework.org/schema/beans/spring-beans-4.0.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-4.0.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=com/fr/third/springframework/beans/factory/xml/spring-beans-4.0.xsd

Loading…
Cancel
Save