HHH-11356 - Adjust the 2nd-Cache SPIs to better reflect supported uses

Fix-ups from Radim's review
This commit is contained in:
Steve Ebersole 2018-03-26 14:37:56 -05:00
parent 93d9162243
commit fbe32f162a
8 changed files with 51 additions and 28 deletions

View File

@ -77,7 +77,7 @@ task ciBuild {
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
gradleVersion = '4.6'
distributionType = 'ALL'
}

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -93,7 +93,7 @@ public class QueryResultRegionAccessImpl implements QueryResultRegionAccess {
try {
session.getEventListenerManager().cachePutStart();
cacheRegion.getStorageAccess().putIntoCache( key, cacheItem );
cacheRegion.putIntoCache( key, cacheItem );
}
finally {
session.getEventListenerManager().cachePutEnd();
@ -189,7 +189,7 @@ public class QueryResultRegionAccessImpl implements QueryResultRegionAccess {
CacheItem cachedItem = null;
try {
session.getEventListenerManager().cacheGetStart();
cachedItem = (CacheItem) cacheRegion.getStorageAccess().getFromCache( key );
cachedItem = (CacheItem) cacheRegion.getFromCache( key );
}
finally {
session.getEventListenerManager().cacheGetEnd( cachedItem != null );
@ -286,11 +286,6 @@ public class QueryResultRegionAccessImpl implements QueryResultRegionAccess {
return "QueryResultsCache(" + cacheRegion.getName() + ')';
}
@Override
public void clear() throws CacheException {
cacheRegion.getStorageAccess().clearCache();
}
public static class CacheItem implements Serializable {
private final long timestamp;
private final List results;

View File

@ -9,8 +9,8 @@ package org.hibernate.cache.internal;
import java.io.Serializable;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.TimestampsRegionAccess;
import org.hibernate.cache.spi.TimestampsRegion;
import org.hibernate.cache.spi.TimestampsRegionAccess;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -57,7 +57,7 @@ public class TimestampsRegionAccessEnabledImpl implements TimestampsRegionAccess
//put() has nowait semantics, is this really appropriate?
//note that it needs to be async replication, never local or sync
timestampsRegion.getStorageAccess().putIntoCache( space, ts );
timestampsRegion.putIntoCache( space, ts );
}
finally {
session.getEventListenerManager().cachePutEnd();
@ -84,7 +84,7 @@ public class TimestampsRegionAccessEnabledImpl implements TimestampsRegionAccess
try {
session.getEventListenerManager().cachePutStart();
timestampsRegion.getStorageAccess().putIntoCache( space, ts );
timestampsRegion.putIntoCache( space, ts );
}
finally {
session.getEventListenerManager().cachePutEnd();
@ -135,7 +135,7 @@ public class TimestampsRegionAccessEnabledImpl implements TimestampsRegionAccess
Long ts = null;
try {
session.getEventListenerManager().cacheGetStart();
ts = (Long) timestampsRegion.getStorageAccess().getFromCache( space );
ts = (Long) timestampsRegion.getFromCache( space );
}
finally {
session.getEventListenerManager().cacheGetEnd( ts != null );

View File

@ -6,25 +6,20 @@
*/
package org.hibernate.cache.spi;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.support.StorageAccess;
/**
* Specialized Region whose data is accessed directly - not requiring
* key wrapping, e.g.
* key/item wrapping, e.g.
*
* @author Steve Ebersole
*/
public interface DirectAccessRegion extends Region {
StorageAccess getStorageAccess();
@Override
default void clear() {
getStorageAccess().clearCache();
default boolean contains(Object key) {
return getFromCache( key ) != null;
}
@Override
default void destroy() throws CacheException {
getStorageAccess().release();
}
Object getFromCache(Object key);
void putIntoCache(Object key, Object value);
void removeFromCache(Object key);
}

View File

@ -36,7 +36,7 @@ public interface QueryResultRegionAccess extends QueryCache {
*/
@Override
default void clear() throws CacheException {
getRegion().getStorageAccess().clearCache();
getRegion().clear();
}
/**

View File

@ -95,7 +95,7 @@ public interface TimestampsRegionAccess extends UpdateTimestampsCache {
@Override
default void clear() throws CacheException {
getRegion().getStorageAccess().clearCache();
getRegion().clear();
}
@Override

View File

@ -16,4 +16,37 @@ public abstract class DirectAccessRegionTemplate extends AbstractRegion implemen
public DirectAccessRegionTemplate(String name, RegionFactory regionFactory) {
super( name, regionFactory );
}
public abstract StorageAccess getStorageAccess();
@Override
public boolean contains(Object key) {
return getStorageAccess().contains( key );
}
@Override
public Object getFromCache(Object key) {
return getStorageAccess().getFromCache( key );
}
@Override
public void putIntoCache(Object key, Object value) {
getStorageAccess().putIntoCache( key, value );
}
@Override
public void removeFromCache(Object key) {
getStorageAccess().removeFromCache( key );
}
@Override
public void clear() {
getStorageAccess().clearCache();
}
@Override
public void destroy() {
getStorageAccess().release();
}
}