Author: steve.ebersole(a)jboss.com
Date: 2010-09-30 13:47:19 -0400 (Thu, 30 Sep 2010)
New Revision: 20760
Modified:
core/trunk/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java
core/trunk/core/src/main/java/org/hibernate/action/EntityInsertAction.java
core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java
core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java
core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
core/trunk/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java
core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
Log:
HHH-5609 - Move SessionImplementor#wasInsertedDuringTransaction to PersistenceContext
Modified:
core/trunk/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-30
15:18:21 UTC (rev 20759)
+++
core/trunk/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-30
17:47:19 UTC (rev 20760)
@@ -75,7 +75,7 @@
//need to do that here rather than in the save event listener to let
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
persister.setIdentifier( instance, generatedId, session );
- getSession().registerInsertedKey( getPersister(), generatedId );
+ getSession().getPersistenceContext().registerInsertedKey( getPersister(), generatedId
);
}
Modified: core/trunk/core/src/main/java/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/EntityInsertAction.java 2010-09-30
15:18:21 UTC (rev 20759)
+++ core/trunk/core/src/main/java/org/hibernate/action/EntityInsertAction.java 2010-09-30
17:47:19 UTC (rev 20760)
@@ -93,7 +93,7 @@
entry.postUpdate(instance, state, version);
}
- getSession().registerInsertedKey( getPersister(), getId() );
+ getSession().getPersistenceContext().registerInsertedKey( getPersister(), getId() );
}
final SessionFactoryImplementor factory = getSession().getFactory();
Modified: core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2010-09-30
15:18:21 UTC (rev 20759)
+++ core/trunk/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2010-09-30
17:47:19 UTC (rev 20760)
@@ -583,4 +583,22 @@
* @param parent
*/
public void removeChildParent(Object child);
+
+ /**
+ * Register keys inserted during the current transaction
+ *
+ * @param persister The entity persister
+ * @param id The id
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id);
+
+ /**
+ * Allows callers to check to see if the identified entity was inserted during the
current transaction.
+ *
+ * @param persister The entity persister
+ * @param id The id
+ *
+ * @return True if inserted during this transaction, false otherwise.
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable
id);
}
Modified: core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java 2010-09-30
15:18:21 UTC (rev 20759)
+++ core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java 2010-09-30
17:47:19 UTC (rev 20760)
@@ -365,22 +365,4 @@
* should never be null.
*/
public LoadQueryInfluencers getLoadQueryInfluencers();
-
- /**
- * Register keys inserted during the current transaction
- *
- * @param persister The entity persister
- * @param id The id
- */
- public void registerInsertedKey(EntityPersister persister, Serializable id);
-
- /**
- * Allows callers to check to see if the identified entity was inserted during the
current transaction.
- *
- * @param persister The entity persister
- * @param id The id
- *
- * @return True if inserted during this transaction, false otherwise.
- */
- public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable
id);
}
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2010-09-30
15:18:21 UTC (rev 20759)
+++
core/trunk/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2010-09-30
17:47:19 UTC (rev 20760)
@@ -269,6 +269,7 @@
}
public void afterTransactionCompletion() {
+ cleanUpInsertedKeysAfterTransaction();
// Downgrade locks
Iterator iter = entityEntries.values().iterator();
while ( iter.hasNext() ) {
@@ -1622,4 +1623,49 @@
public void removeChildParent(Object child) {
parentsByChild.remove(child);
}
+
+
+ private HashMap<String,List<Serializable>> insertedKeysMap;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // we only are about regsitering these if the persister defines caching
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap == null ) {
+ insertedKeysMap = new HashMap<String, List<Serializable>>();
+ }
+ final String rootEntityName = persister.getRootEntityName();
+ List<Serializable> insertedEntityIds = insertedKeysMap.get( rootEntityName );
+ if ( insertedEntityIds == null ) {
+ insertedEntityIds = new ArrayList<Serializable>();
+ insertedKeysMap.put( rootEntityName, insertedEntityIds );
+ }
+ insertedEntityIds.add( id );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id)
{
+ // again, we only really care if the entity is cached
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap != null ) {
+ List<Serializable> insertedEntityIds = insertedKeysMap.get(
persister.getRootEntityName() );
+ if ( insertedEntityIds != null ) {
+ return insertedEntityIds.contains( id );
+ }
+ }
+ }
+ return false;
+ }
+
+ private void cleanUpInsertedKeysAfterTransaction() {
+ if ( insertedKeysMap != null ) {
+ insertedKeysMap.clear();
+ }
+ }
+
}
Modified: core/trunk/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java 2010-09-30
15:18:21 UTC (rev 20759)
+++ core/trunk/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java 2010-09-30
17:47:19 UTC (rev 20760)
@@ -183,7 +183,7 @@
// 2) Session#clear + some form of load
//
// we need to be careful not to clobber the lock here in the cache so that it can be
rolled back if need be
- if ( session.wasInsertedDuringTransaction( persister, id ) ) {
+ if ( session.getPersistenceContext().wasInsertedDuringTransaction( persister, id ) )
{
persister.getCacheAccessStrategy().update(
cacheKey,
persister.getCacheEntryStructure().structure( entry ),
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2010-09-30 15:18:21
UTC (rev 20759)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java 2010-09-30 17:47:19
UTC (rev 20760)
@@ -598,7 +598,6 @@
public void afterTransactionCompletion(boolean success, Transaction tx) {
log.trace( "after transaction completion" );
- cleanUpInsertedKeysAfterTransaction();
persistenceContext.afterTransactionCompletion();
actionQueue.afterTransactionCompletion(success);
if ( rootSession == null && tx != null ) {
@@ -2017,49 +2016,6 @@
return loadQueryInfluencers;
}
- private HashMap<String,List<Serializable>> insertedKeysMap;
-
- /**
- * {@inheritDoc}
- */
- public void registerInsertedKey(EntityPersister persister, Serializable id) {
- // we only are about regsitering these if the persister defines caching
- if ( persister.hasCache() ) {
- if ( insertedKeysMap == null ) {
- insertedKeysMap = new HashMap<String, List<Serializable>>();
- }
- final String rootEntityName = persister.getRootEntityName();
- List<Serializable> insertedEntityIds = insertedKeysMap.get( rootEntityName );
- if ( insertedEntityIds == null ) {
- insertedEntityIds = new ArrayList<Serializable>();
- insertedKeysMap.put( rootEntityName, insertedEntityIds );
- }
- insertedEntityIds.add( id );
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id)
{
- // again, we only really care if the entity is cached
- if ( persister.hasCache() ) {
- if ( insertedKeysMap != null ) {
- List<Serializable> insertedEntityIds = insertedKeysMap.get(
persister.getRootEntityName() );
- if ( insertedEntityIds != null ) {
- return insertedEntityIds.contains( id );
- }
- }
- }
- return false;
- }
-
- private void cleanUpInsertedKeysAfterTransaction() {
- if ( insertedKeysMap != null ) {
- insertedKeysMap.clear();
- }
- }
-
// filter support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**