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: 'maven-publish'
def classesDir='build/classes/main'
tasks.withType(JavaCompile){
options.encoding = 'UTF-8'
destinationDir = file('build/classes/main')
destinationDir = file(classesDir)
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
//jdk版本
sourceCompatibility=1.5
def jarname="fine-third-10.0.jar"
def classesDir='build/classes/main'
//lib下的jar到classes文件夹
version='10.0'
jar{
baseName="fine-third-10.0"
baseName="fine-third"
}
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 branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+1)
def srcDir="."
def maven_version="${version}-RELEASE-SNAPSHOT"
def jar_version = version
configurations {
thirdjar
@ -39,12 +49,34 @@ configurations {
}
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"
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) {
delete 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-quartz/lib",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')
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-spring/lib",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')
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{
compile fileTree(dir:"${srcDir}/fine-jboss-logging/lib",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')
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{
compile fileTree(dir:"${srcDir}/fine-hibernate/lib",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')
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:'**/*.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')
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-socketio/lib",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')
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 {
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
private final AtomicLong recycleErrorCount = new AtomicLong();
private long connectCount = 0L;
private long closeCount = 0L;
private final AtomicLong connectErrorCount = new AtomicLong();
private long recycleCount = 0L;
private long removeAbandonedCount = 0L;
private long notEmptyWaitCount = 0L;
private long notEmptySignalCount = 0L;
private long notEmptyWaitNanos = 0L;
private int keepAliveCheckCount = 0;
private int activePeak = 0;
private long activePeakTime = 0;
private int poolingPeak = 0;
private long poolingPeakTime = 0;
private final AtomicLong recycleErrorCount = new AtomicLong();
private long connectCount = 0L;
private long closeCount = 0L;
private final AtomicLong connectErrorCount = new AtomicLong();
private long recycleCount = 0L;
private long removeAbandonedCount = 0L;
private long notEmptyWaitCount = 0L;
private long notEmptySignalCount = 0L;
private long notEmptyWaitNanos = 0L;
private int keepAliveCheckCount = 0;
private int activePeak = 0;
private long activePeakTime = 0;
private int poolingPeak = 0;
private long poolingPeakTime = 0;
// store
private volatile DruidConnectionHolder[] connections;
private int poolingCount = 0;
private int activeCount = 0;
private long discardCount = 0;
private int notEmptyWaitThreadCount = 0;
private int notEmptyWaitThreadPeak = 0;
private int poolingCount = 0;
private int activeCount = 0;
private long discardCount = 0;
private int notEmptyWaitThreadCount = 0;
private int notEmptyWaitThreadPeak = 0;
//
private DruidConnectionHolder[] evictConnections;
private DruidConnectionHolder[] keepAliveConnections;
private DruidConnectionHolder[] evictConnections;
private DruidConnectionHolder[] keepAliveConnections;
// threads
private ScheduledFuture<?> destroySchedulerFuture;
private DestroyTask destroyTask;
private ScheduledFuture<?> destroySchedulerFuture;
private DestroyTask destroyTask;
private CreateConnectionThread createConnectionThread;
private DestroyConnectionThread destroyConnectionThread;
private LogStatsThread logStatsThread;
private int createTaskCount;
private CreateConnectionThread createConnectionThread;
private DestroyConnectionThread destroyConnectionThread;
private LogStatsThread logStatsThread;
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 final AtomicLong resetCount = new AtomicLong();
private boolean resetStatEnable = true;
private final AtomicLong resetCount = new AtomicLong();
private String initStackTrace;
private String initStackTrace;
private volatile boolean closed = false;
private long closeTimeMillis = -1L;
private volatile boolean closed = false;
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);
}
public DruidDataSource(boolean fairLock){
public DruidDataSource(boolean fairLock) {
super(fairLock);
configFromPropety(System.getProperties());
@ -602,6 +602,34 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
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 {
if (inited) {
return;
@ -645,7 +673,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
if (JdbcConstants.MYSQL.equals(this.dbType) || //
JdbcConstants.MARIADB.equals(this.dbType)) {
JdbcConstants.MARIADB.equals(this.dbType)) {
boolean cacheServerConfigurationSet = false;
if (this.connectProperties.containsKey("cacheServerConfiguration")) {
cacheServerConfigurationSet = true;
@ -805,7 +833,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
period = 1000;
}
destroySchedulerFuture = destroyScheduler.scheduleAtFixedRate(destroyTask, period, period,
TimeUnit.MILLISECONDS);
TimeUnit.MILLISECONDS);
initedLatch.countDown();
return;
}
@ -817,7 +845,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
protected void createAndStartCreatorThread() {
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.start();
return;
@ -828,7 +856,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
/**
* load filters from SPI ServiceLoader
*
*
* @see ServiceLoader
*/
private void initFromSPIServiceLoader() {
@ -873,7 +901,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
/**
* 会去重复
*
*
* @param filter
*/
private void addFilter(Filter filter) {
@ -928,7 +956,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (driver.getMajorVersion() < 10) {
throw new SQLException("not support oracle driver " + driver.getMajorVersion() + "."
+ driver.getMinorVersion());
+ driver.getMinorVersion());
}
if (driver.getMajorVersion() == 10 && isUseOracleImplicitCache()) {
@ -965,7 +993,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (query instanceof SQLSelectQueryBlock) {
if (((SQLSelectQueryBlock) query).getFrom() == null) {
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 (((SQLSelectQueryBlock) query).getFrom() == null) {
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() {
String realDriverClassName = driver.getClass().getName();
if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER) //
|| realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) {
|| realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) {
this.validConnectionChecker = new MySqlValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER)
|| realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) {
this.validConnectionChecker = new OracleValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER)
|| realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_SQLJDBC4)
|| realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_JTDS)) {
|| realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_SQLJDBC4)
|| realDriverClassName.equals(JdbcConstants.SQL_SERVER_DRIVER_JTDS)) {
this.validConnectionChecker = new MSSQLValidConnectionChecker();
} else if (realDriverClassName.equals(JdbcConstants.POSTGRESQL_DRIVER)) {
this.validConnectionChecker = new PGValidConnectionChecker();
@ -1027,7 +1055,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
String realDriverClassName = driver.getClass().getName();
if (realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER) //
|| realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) {
|| realDriverClassName.equals(JdbcConstants.MYSQL_DRIVER_6)) {
this.exceptionSorter = new MySqlExceptionSorter();
} else if (realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER)
|| realDriverClassName.equals(JdbcConstants.ORACLE_DRIVER2)) {
@ -1055,7 +1083,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public DruidPooledConnection getConnection(long maxWaitMillis) throws SQLException {
init();
checkThread();
if (filters.size() > 0) {
FilterChainImpl filterChain = new FilterChainImpl(this);
return filterChain.dataSource_connect(this, maxWaitMillis);
@ -1076,7 +1104,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public DruidPooledConnection getConnectionDirect(long maxWaitMillis) throws SQLException {
int notFullTimeoutRetryCnt = 0;
for (;;) {
for (; ; ) {
// handle notFullTimeoutRetry
DruidPooledConnection poolableConnection;
try {
@ -1157,7 +1185,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
/**
* 抛弃连接不进行回收而是抛弃
*
*
* @param realConnection
*/
public void discardConnection(Connection realConnection) {
@ -1203,7 +1231,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
if (notEmptyWaitThreadCount >= maxWaitThreadCount) {
connectErrorCount.incrementAndGet();
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) {
Throwable throwable = this.createError;
if (throwable != null) {
if(throwable instanceof SQLException){
if (throwable instanceof SQLException) {
throw (SQLException) throwable;
}
throw new GetConnectionTimeoutException(throwable.getMessage(), throwable);
@ -1249,7 +1277,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
.append(", maxActive " + maxActive)//
;
JdbcDataSourceStat sourceStat = this.getDataSourceStat();
if(sourceStat != null) {
if (sourceStat != null) {
List<JdbcSqlStatValue> sqlList = sourceStat.getRuningSqlList();
for (int i = 0; i < sqlList.size(); ++i) {
if (i != 0) {
@ -1344,9 +1372,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
if (logDifferentThread //
&& (!isAsyncCloseConnectionEnable()) //
&& pooledConnection.getOwnerThread() != Thread.currentThread()//
) {
&& (!isAsyncCloseConnectionEnable()) //
&& pooledConnection.getOwnerThread() != Thread.currentThread()//
) {
LOG.warn("get/close not same thread");
}
@ -1543,7 +1571,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
@Override
public Object run() {
ObjectName objectName = DruidDataSourceStatManager.addDataSource(DruidDataSource.this,
DruidDataSource.this.name);
DruidDataSource.this.name);
DruidDataSource.this.setObjectName(objectName);
DruidDataSource.this.mbeanRegistered = true;
@ -1633,7 +1661,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private DruidConnectionHolder pollLast(long nanos) throws InterruptedException, SQLException {
long estimate = nanos;
for (;;) {
for (; ; ) {
if (poolingCount == 0) {
emptySignal(); // send signal to CreateThread create connection
@ -1654,8 +1682,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
try {
long startEstimate = estimate;
estimate = notEmpty.awaitNanos(estimate); // signal by
// recycle or
// creator
// recycle or
// creator
notEmptyWaitCount++;
notEmptyWaitNanos += (startEstimate - estimate);
@ -1926,7 +1954,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
createTaskCount--;
if (poolingCount + createTaskCount < notEmptyWaitThreadCount //
&& activeCount + poolingCount + createTaskCount < maxActive) {
&& activeCount + poolingCount + createTaskCount < maxActive) {
emptySignal();
}
}
@ -1946,7 +1974,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
private void runInternal() {
for (;;) {
for (; ; ) {
// addLast
lock.lock();
@ -2043,8 +2071,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
public class CreateConnectionThread extends Thread {
private volatile boolean started = true;
public CreateConnectionThread(String name){
public CreateConnectionThread(String name) {
super(name);
this.setDaemon(true);
}
@ -2054,7 +2083,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
long lastDiscardCount = 0;
int errorCount = 0;
for (;;) {
for (; ; ) {
// addLast
try {
lock.lockInterruptibly();
@ -2102,7 +2131,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
setFailContinuous(false);
} catch (SQLException e) {
LOG.error("create connection error, url: " + jdbcUrl + ", errorCode " + e.getErrorCode()
+ ", state " + e.getSQLState(), e);
+ ", state " + e.getSQLState(), e);
errorCount++;
if (errorCount > connectionErrorRetryAttempts && timeBetweenConnectErrorMillis > 0) {
@ -2126,6 +2155,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
} catch (InterruptedException interruptEx) {
break;
}
DruidDataSource.this.createThreadChange();
break;
}
} catch (RuntimeException e) {
LOG.error("create connection error", e);
@ -2150,11 +2181,20 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
errorCount = 0; // reset errorCount
}
}
public boolean isStarted() {
return started;
}
public void setStarted(boolean started) {
this.started = started;
}
}
public class DestroyConnectionThread extends Thread {
private volatile boolean started = true;
public DestroyConnectionThread(String name){
public DestroyConnectionThread(String name) {
super(name);
this.setDaemon(true);
}
@ -2162,7 +2202,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public void run() {
initedLatch.countDown();
for (;;) {
for (; ; ) {
// 从前面开始删除
try {
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 {
@ -2203,14 +2250,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public class LogStatsThread extends Thread {
public LogStatsThread(String name){
public LogStatsThread(String name) {
super(name);
this.setDaemon(true);
}
public void run() {
try {
for (;;) {
for (; ; ) {
try {
logStats();
} catch (Exception e) {
@ -2236,7 +2283,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
try {
Iterator<DruidPooledConnection> iter = activeConnections.keySet().iterator();
for (; iter.hasNext();) {
for (; iter.hasNext(); ) {
DruidPooledConnection pooledConnection = iter.next();
if (pooledConnection.isRunning()) {
@ -2288,7 +2335,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
buf.append("ownerThread current state is " + pooledConnection.getOwnerThread().getState()
+ ", current stackTrace\n");
+ ", current stackTrace\n");
trace = pooledConnection.getOwnerThread().getStackTrace();
for (int i = 0; i < trace.length; i++) {
buf.append("\tat ");
@ -2304,7 +2351,9 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
return removeCount;
}
/** Instance key */
/**
* Instance key
*/
protected String instanceKey = null;
public Reference getReference() throws NamingException {
@ -2938,7 +2987,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
if (this.statLogger != null
&& (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) {
&& (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) {
return true;
}
@ -2954,7 +3003,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
if (this.statLogger != null
&& (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) {
&& (this.statLogger.getClass() == iface || DruidDataSourceStatLogger.class == iface)) {
return (T) statLogger;
}
@ -2998,7 +3047,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
int fillCount = 0;
for (;;) {
for (; ; ) {
try {
lock.lockInterruptibly();
} 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;
import org.springframework.beans.factory.FactoryBean;
import com.fr.third.springframework.beans.factory.FactoryBean;
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.LogFactory;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import com.fr.third.springframework.aop.TargetSource;
import com.fr.third.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import com.ibatis.sqlmap.client.SqlMapClient;
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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.PatternMatchUtils;
import com.fr.third.springframework.aop.TargetSource;
import com.fr.third.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import com.fr.third.springframework.beans.factory.BeanFactory;
import com.fr.third.springframework.beans.factory.FactoryBean;
import com.fr.third.springframework.util.PatternMatchUtils;
import java.util.ArrayList;
import java.util.List;
@ -95,7 +95,7 @@ public class SpringIbatisBeanTypeAutoProxyCreator extends AbstractAutoProxyCreat
* @param beanName the bean name to check
* @param mappedName the name in the configured list of names
* @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) {
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 org.springframework.beans.factory.FactoryBean;
import com.fr.third.springframework.beans.factory.FactoryBean;
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.support.http.stat.WebSessionStat;
import com.fr.third.alibaba.druid.support.http.stat.WebURIStat;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import com.fr.third.springframework.beans.factory.DisposableBean;
import com.fr.third.springframework.beans.factory.InitializingBean;
import com.fr.third.springframework.web.servlet.HandlerInterceptor;
import com.fr.third.springframework.web.servlet.HandlerMapping;
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.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;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.Assert;
import org.springframework.util.PatternMatchUtils;
import com.fr.third.springframework.aop.TargetSource;
import com.fr.third.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import com.fr.third.springframework.beans.factory.BeanFactory;
import com.fr.third.springframework.beans.factory.FactoryBean;
import com.fr.third.springframework.beans.factory.InitializingBean;
import com.fr.third.springframework.context.ApplicationContext;
import com.fr.third.springframework.context.ApplicationContextAware;
import com.fr.third.springframework.util.Assert;
import com.fr.third.springframework.util.PatternMatchUtils;
import java.util.ArrayList;
import java.util.Collections;
@ -83,7 +83,7 @@ public class BeanTypeAutoProxyCreator extends AbstractAutoProxyCreator implement
* @param beanName the bean name to check
* @param mappedName the name in the configured list of names
* @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) {
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 org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.TargetSource;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import com.fr.third.springframework.aop.TargetSource;
import com.fr.third.springframework.beans.factory.DisposableBean;
import com.fr.third.springframework.beans.factory.InitializingBean;
import java.lang.reflect.Method;
@ -123,8 +123,8 @@ public class DruidStatInterceptor implements MethodInterceptor, InitializingBean
try {
// 最多支持10层代理
for (int i = 0; i < 10; ++i) {
if (thisObject instanceof org.springframework.aop.framework.Advised) {
TargetSource targetSource = ((org.springframework.aop.framework.Advised) thisObject).getTargetSource();
if (thisObject instanceof com.fr.third.springframework.aop.framework.Advised) {
TargetSource targetSource = ((com.fr.third.springframework.aop.framework.Advised) thisObject).getTargetSource();
if (targetSource == null) {
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 org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.ComposablePointcut;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import com.fr.third.springframework.aop.Pointcut;
import com.fr.third.springframework.aop.support.AbstractPointcutAdvisor;
import com.fr.third.springframework.aop.support.ComposablePointcut;
import com.fr.third.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import com.fr.third.springframework.beans.BeansException;
import com.fr.third.springframework.beans.factory.BeanFactory;
import com.fr.third.springframework.beans.factory.BeanFactoryAware;
@SuppressWarnings("serial")
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 com.fr.third.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import com.fr.third.springframework.aop.framework.AbstractAdvisingBeanPostProcessor;
import com.fr.third.springframework.beans.BeansException;
import com.fr.third.springframework.beans.factory.BeanFactory;
import com.fr.third.springframework.beans.factory.BeanFactoryAware;
@SuppressWarnings("serial")
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;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import com.fr.third.springframework.beans.factory.config.BeanDefinition;
import com.fr.third.springframework.beans.factory.config.BeanDefinitionHolder;
import com.fr.third.springframework.beans.factory.parsing.BeanComponentDefinition;
import com.fr.third.springframework.beans.factory.parsing.CompositeComponentDefinition;
import com.fr.third.springframework.beans.factory.support.BeanDefinitionBuilder;
import com.fr.third.springframework.beans.factory.support.BeanDefinitionRegistry;
import com.fr.third.springframework.beans.factory.xml.BeanDefinitionParser;
import com.fr.third.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
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;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
import com.fr.third.springframework.beans.factory.xml.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
public Batch buildBatch(BatchKey key, JdbcCoordinator jdbcCoordinator) {
LOG.tracef( "Building batch [size=%s]", size );
return size > 1
? new BatchingBatch( key, jdbcCoordinator, size )
int batchSize = jdbcCoordinator.getJdbcSessionOwner().getJdbcBatchSize() > 1
? jdbcCoordinator.getJdbcSessionOwner().getJdbcBatchSize()
: size;
LOG.tracef( "Building batch [size=%s]", batchSize );
return batchSize > 1
? new BatchingBatch( key, jdbcCoordinator, batchSize )
: 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.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.fr.third.org.jboss.logging.Logger;
@ -187,10 +188,14 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
LOG.tracev( "Closing JDBC container [{0}]", this );
Connection connection;
try {
if ( currentBatch != null ) {
LOG.closingUnreleasedBatch();
currentBatch.release();
LOG.closingUnreleasedBatch();
for(Map.Entry<BatchKey, Batch> e : batchMap.entrySet()){
e.getValue().release();
}
// if ( currentBatch != null ) {
// LOG.closingUnreleasedBatch();
// currentBatch.release();
// }
cleanup();
}
finally {
@ -199,35 +204,55 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator {
return connection;
}
private Map<BatchKey, Batch> batchMap = new ConcurrentHashMap<BatchKey, Batch>();
@Override
public Batch getBatch(BatchKey key) {
if ( currentBatch != null ) {
if ( currentBatch.getKey().equals( key ) ) {
return currentBatch;
}
else {
currentBatch.execute();
currentBatch.release();
}
}
currentBatch = batchBuilder().buildBatch( key, this );
return currentBatch;
Batch batch = batchMap.get(key);
if(batch == null) {
batch = batchBuilder().buildBatch( key, this );
batchMap.put(key, batch);
}
return batch;
//
// if ( currentBatch != null ) {
// if ( currentBatch.getKey().equals( key ) ) {
// return currentBatch;
// }
// else {
// currentBatch.execute();
// currentBatch.release();
// }
// }
// currentBatch = batchBuilder().buildBatch( key, this );
// return currentBatch;
}
@Override
public void executeBatch() {
if ( currentBatch != null ) {
currentBatch.execute();
// needed?
currentBatch.release();
for(Map.Entry<BatchKey, Batch> e : batchMap.entrySet()){
e.getValue().execute();
e.getValue().release();
}
// if ( currentBatch != null ) {
// currentBatch.execute();
// // needed?
// currentBatch.release();
// }
}
@Override
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;

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

@ -74,7 +74,7 @@ class StatementPreparerImpl implements StatementPreparer {
@Override
public PreparedStatement prepareStatement(String sql, final boolean isCallable) {
jdbcCoordinator.executeBatch();
//jdbcCoordinator.executeBatch();
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;
private final String tenantIdentifier;
private boolean closed;
private int jdbcBatchSize;
protected transient Transaction currentHibernateTransaction;
protected transient WrapperOptionsImpl wrapperOptions;
@ -609,4 +610,14 @@ public abstract class AbstractSessionImpl
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.Setter;
import com.fr.third.org.hibernate.property.access.spi.SetterFieldImpl;
import com.fr.third.org.hibernate.property.access.spi.UnsafeGetterFieldImpl;
/**
* @author Steve Ebersole
@ -32,7 +33,7 @@ public class PropertyAccessFieldImpl implements PropertyAccess {
this.strategy = strategy;
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 );
}

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 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.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