From 99c5ad25e03bf14e877c17b157dfe52d78a32628 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 5 Jul 2018 14:15:03 +0800 Subject: [PATCH] hibernate batch --- .../jdbc/internal/JdbcCoordinatorImpl.java | 65 +++++++++++++------ .../jdbc/internal/StatementPreparerImpl.java | 2 +- .../internal/PropertyAccessFieldImpl.java | 3 +- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java b/fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java index 25c84d2b9..c7538cd2e 100644 --- a/fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java +++ b/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 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 batchMap = new ConcurrentHashMap(); + @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 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 e : batchMap.entrySet()){ + e.getValue().release(); } +// if ( currentBatch != null ) { +// currentBatch.release(); +// } + } private transient StatementPreparer statementPreparer; diff --git a/fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java b/fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java index f15a71410..29c739ccc 100644 --- a/fine-hibernate/src/com/fr/third/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java +++ b/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(); } diff --git a/fine-hibernate/src/com/fr/third/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java b/fine-hibernate/src/com/fr/third/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java index 5bf9486ee..a72bedd28 100644 --- a/fine-hibernate/src/com/fr/third/org/hibernate/property/access/internal/PropertyAccessFieldImpl.java +++ b/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 ); }