Skip to content

Commit

Permalink
HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager i…
Browse files Browse the repository at this point in the history
…nto hibernate-core (HEM tests - JPA requirements around access to Transaction delegate after EntityManager is closed; also its requirement that the same Transaction delegate be available across all calls to its commit/rollback methods)
  • Loading branch information
sebersole authored and galderz committed Jul 5, 2017
1 parent 19467aa commit d52f9de
Show file tree
Hide file tree
Showing 27 changed files with 244 additions and 222 deletions.
Expand Up @@ -8,7 +8,7 @@

import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;

/**
* Defines the strategy for access to entity or collection data in a Infinispan instance.
Expand All @@ -20,7 +20,7 @@
* @author Radim Vansa <rvansa@redhat.com>
*/
public interface AccessDelegate {
Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException;
Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException;

/**
* Attempt to cache an object, afterQuery loading from the database.
Expand All @@ -32,7 +32,7 @@ public interface AccessDelegate {
* @param version the item version number
* @return <tt>true</tt> if the object was successfully cached
*/
boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version);
boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version);

/**
* Attempt to cache an object, afterQuery loading from the database, explicitly
Expand All @@ -47,7 +47,7 @@ public interface AccessDelegate {
* @return <tt>true</tt> if the object was successfully cached
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
*/
boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException;

/**
Expand All @@ -61,7 +61,7 @@ boolean putFromLoad(SessionImplementor session, Object key, Object value, long t
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException if the insert fails
*/
boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException;
boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException;

/**
* Called afterQuery an item has been updated (beforeQuery the transaction completes),
Expand All @@ -75,7 +75,7 @@ boolean putFromLoad(SessionImplementor session, Object key, Object value, long t
* @return Whether the contents of the cache actual changed by this operation
* @throws CacheException if the update fails
*/
boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException;

/**
Expand All @@ -85,7 +85,7 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @param key The key of the item to remove
* @throws CacheException if removing the cached item fails
*/
void remove(SessionImplementor session, Object key) throws CacheException;
void remove(SharedSessionContractImplementor session, Object key) throws CacheException;

/**
* Called to evict data from the entire region
Expand Down Expand Up @@ -121,7 +121,7 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @param key The item key
* @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
*/
void unlockItem(SessionImplementor session, Object key) throws CacheException;
void unlockItem(SharedSessionContractImplementor session, Object key) throws CacheException;

/**
* Called afterQuery an item has been inserted (afterQuery the transaction completes),
Expand All @@ -136,7 +136,7 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
boolean afterInsert(SessionImplementor session, Object key, Object value, Object version);
boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version);

/**
* Called afterQuery an item has been updated (afterQuery the transaction completes),
Expand All @@ -153,5 +153,5 @@ boolean update(SessionImplementor session, Object key, Object value, Object curr
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock);
boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock);
}
Expand Up @@ -10,7 +10,7 @@
import org.hibernate.cache.infinispan.impl.BaseRegion;
import org.hibernate.cache.infinispan.util.Caches;
import org.hibernate.cache.infinispan.util.InfinispanMessageLogger;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;

import org.infinispan.AdvancedCache;

Expand Down Expand Up @@ -54,7 +54,7 @@ protected InvalidationCacheAccessDelegate(BaseRegion region, PutFromLoadValidato
*/
@Override
@SuppressWarnings("UnusedParameters")
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException {
public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException {
if ( !region.checkValid() ) {
return null;
}
Expand All @@ -66,7 +66,7 @@ public Object get(SessionImplementor session, Object key, long txTimestamp) thro
}

@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version) {
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version) {
return putFromLoad(session, key, value, txTimestamp, version, false );
}

Expand All @@ -85,7 +85,7 @@ public boolean putFromLoad(SessionImplementor session, Object key, Object value,
*/
@Override
@SuppressWarnings("UnusedParameters")
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException {
if ( !region.checkValid() ) {
if ( TRACE_ENABLED ) {
Expand Down Expand Up @@ -122,7 +122,7 @@ public boolean putFromLoad(SessionImplementor session, Object key, Object value,
}

@Override
public void remove(SessionImplementor session, Object key) throws CacheException {
public void remove(SharedSessionContractImplementor session, Object key) throws CacheException {
if ( !putValidator.beginInvalidatingKey(session, key)) {
throw log.failedInvalidatePendingPut(key, region.getName());
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public void evictAll() throws CacheException {
}

@Override
public void unlockItem(SessionImplementor session, Object key) throws CacheException {
public void unlockItem(SharedSessionContractImplementor session, Object key) throws CacheException {
if ( !putValidator.endInvalidatingKey(session, key) ) {
log.failedEndInvalidating(key, region.getName());
}
Expand Down
Expand Up @@ -16,7 +16,7 @@
import org.hibernate.cache.infinispan.util.VersionedEntry;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cache.spi.entry.CacheEntry;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;

import org.infinispan.AdvancedCache;
Expand Down Expand Up @@ -60,7 +60,7 @@ public NonStrictAccessDelegate(BaseTransactionalDataRegion region) {
}

@Override
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException {
public Object get(SharedSessionContractImplementor session, Object key, long txTimestamp) throws CacheException {
if (txTimestamp < region.getLastRegionInvalidation() ) {
return null;
}
Expand All @@ -72,12 +72,12 @@ public Object get(SessionImplementor session, Object key, long txTimestamp) thro
}

@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version) {
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version) {
return putFromLoad(session, key, value, txTimestamp, version, false);
}

@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException {
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException {
long lastRegionInvalidation = region.getLastRegionInvalidation();
if (txTimestamp < lastRegionInvalidation) {
log.tracef("putFromLoad not executed since tx started at %d, beforeQuery last region invalidation finished = %d", txTimestamp, lastRegionInvalidation);
Expand Down Expand Up @@ -116,17 +116,17 @@ else if (prev instanceof VersionedEntry && txTimestamp <= ((VersionedEntry) prev
}

@Override
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException {
return false;
}

@Override
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
return false;
}

@Override
public void remove(SessionImplementor session, Object key) throws CacheException {
public void remove(SharedSessionContractImplementor session, Object key) throws CacheException {
// there's no 'afterRemove', so we have to use our own synchronization
// the API does not provide version of removed item but we can't load it from the cache
// as that would be prone to race conditions - if the entry was updated in the meantime
Expand Down Expand Up @@ -165,17 +165,17 @@ public void evictAll() throws CacheException {
}

@Override
public void unlockItem(SessionImplementor session, Object key) throws CacheException {
public void unlockItem(SharedSessionContractImplementor session, Object key) throws CacheException {
}

@Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object version) {
public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) {
writeCache.put(key, getVersioned(value, version, session.getTimestamp()));
return true;
}

@Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) {
public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) {
writeCache.put(key, getVersioned(value, currentVersion, session.getTimestamp()));
return true;
}
Expand Down
Expand Up @@ -13,7 +13,7 @@
import org.hibernate.cache.CacheException;
import org.hibernate.cache.infinispan.impl.BaseRegion;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
import org.hibernate.resource.transaction.spi.TransactionStatus;

Expand All @@ -29,7 +29,7 @@ public NonTxInvalidationCacheAccessDelegate(BaseRegion region, PutFromLoadValida

@Override
@SuppressWarnings("UnusedParameters")
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException {
if ( !region.checkValid() ) {
return false;
}
Expand All @@ -52,7 +52,7 @@ public boolean insert(SessionImplementor session, Object key, Object value, Obje

@Override
@SuppressWarnings("UnusedParameters")
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
// We update whether or not the region is valid. Other nodes
// may have already restored the region so they need to
Expand All @@ -74,7 +74,7 @@ public boolean update(SessionImplementor session, Object key, Object value, Obje
return true;
}

protected boolean isCommitted(SessionImplementor session) {
protected boolean isCommitted(SharedSessionContractImplementor session) {
if (session.isClosed()) {
// If the session has been closed beforeQuery transaction ends, so we cannot find out
// if the transaction was successful and if we can do the PFER.
Expand Down Expand Up @@ -102,22 +102,22 @@ protected boolean isCommitted(SessionImplementor session) {
}

@Override
public void unlockItem(SessionImplementor session, Object key) throws CacheException {
public void unlockItem(SharedSessionContractImplementor session, Object key) throws CacheException {
if ( !putValidator.endInvalidatingKey(session, key, isCommitted(session)) ) {
log.failedEndInvalidating(key, region.getName());
}
}

@Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object version) {
public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) {
if ( !putValidator.endInvalidatingKey(session, key, isCommitted(session)) ) {
log.failedEndInvalidating(key, region.getName());
}
return false;
}

@Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) {
public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) {
if ( !putValidator.endInvalidatingKey(session, key, isCommitted(session)) ) {
log.failedEndInvalidating(key, region.getName());
}
Expand Down

0 comments on commit d52f9de

Please sign in to comment.