Skip to content

Commit 2ddefd6

Browse files
chrisdennissebersole
authored andcommitted
HHH-10770 JCache provider updates
* Steer away from EntryProcessor * Add tests
1 parent a872885 commit 2ddefd6

32 files changed

+2143
-183
lines changed

hibernate-jcache/src/main/java/org/hibernate/cache/jcache/JCacheMessageLogger.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.hibernate.internal.CoreMessageLogger;
1414

15+
import static org.jboss.logging.Logger.Level.ERROR;
1516
import static org.jboss.logging.Logger.Level.WARN;
1617

1718
/**
@@ -36,4 +37,12 @@ public interface JCacheMessageLogger extends CoreMessageLogger {
3637
id = NAMESPACE + 2
3738
)
3839
void attemptToRestopAlreadyStoppedJCacheProvider();
40+
41+
@LogMessage(level = ERROR)
42+
@Message(
43+
value = "Cache: %s Key: %s Lockable: %s. A soft-locked cache entry was missing. This is either"
44+
+ " out of balance lock/unlock sequences, or an eagerly evicting cache.",
45+
id = NAMESPACE + 3
46+
)
47+
void missingLock(JCacheRegion region, Object key, Object value);
3948
}

hibernate-jcache/src/main/java/org/hibernate/cache/jcache/JCacheRegionFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.hibernate.boot.spi.SessionFactoryOptions;
2424
import org.hibernate.cache.CacheException;
25+
import org.hibernate.cache.jcache.time.Timestamper;
2526
import org.hibernate.cache.spi.CacheDataDescription;
2627
import org.hibernate.cache.spi.CollectionRegion;
2728
import org.hibernate.cache.spi.EntityRegion;
@@ -187,11 +188,11 @@ CacheManager getCacheManager() {
187188
}
188189

189190
static long nextTS() {
190-
return System.currentTimeMillis() / 100;
191+
return Timestamper.next();
191192
}
192193

193194
static int timeOut() {
194-
return (int) (TimeUnit.SECONDS.toMillis(60) / 100);
195+
return (int) TimeUnit.SECONDS.toMillis( 60 ) * Timestamper.ONE_MS;
195196
}
196197

197198
private String getProp(Properties properties, String prop) {

hibernate-jcache/src/main/java/org/hibernate/cache/jcache/JCacheTransactionalDataRegion.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.EnumSet;
1010
import java.util.Set;
1111
import javax.cache.Cache;
12-
import javax.cache.processor.EntryProcessor;
1312

1413
import org.hibernate.boot.spi.SessionFactoryOptions;
1514
import org.hibernate.cache.spi.CacheDataDescription;
@@ -33,17 +32,19 @@ public JCacheTransactionalDataRegion(Cache<Object, Object> cache, CacheDataDescr
3332
this.options = options;
3433
}
3534

35+
@Override
3636
public boolean isTransactionAware() {
3737
return false;
3838
}
3939

40+
@Override
4041
public CacheDataDescription getCacheDataDescription() {
4142
return metadata;
4243
}
4344

4445
protected void throwIfAccessTypeUnsupported(AccessType accessType) {
45-
if ( supportedAccessTypes().contains( accessType ) ) {
46-
throw new UnsupportedOperationException( "This doesn't JCacheTransactionalDataRegion doesn't support " + accessType );
46+
if ( !supportedAccessTypes().contains( accessType ) ) {
47+
throw new UnsupportedOperationException( "JCacheTransactionalDataRegion doesn't support " + accessType );
4748
}
4849
}
4950

@@ -67,12 +68,15 @@ public void put(Object key, Object value) {
6768
cache.put( key, value );
6869
}
6970

70-
public SessionFactoryOptions getSessionFactoryOptions() {
71-
return options;
71+
public boolean putIfAbsent(Object key, Object value) {
72+
return cache.putIfAbsent( key, value );
7273
}
7374

74-
public <T> T invoke(Object key, EntryProcessor<Object, Object, T> entryProcessor, Object... args) {
75-
return cache.invoke( key, entryProcessor, args);
75+
public boolean replace(Object key, Object expected, Object value) {
76+
return cache.replace( key, expected, value );
7677
}
7778

79+
public SessionFactoryOptions getSessionFactoryOptions() {
80+
return options;
81+
}
7882
}

0 commit comments

Comments
 (0)