use of com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue in project coherence-hibernate by coherence-community.
the class AbstractCoherenceEntityDataAccess method putFromLoad.
/**
* {@inheritDoc}
*/
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, Object version, boolean minimalPutOverride) throws CacheException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("putFromLoad({}, {}, {}, {})", key, value, version, minimalPutOverride);
}
CoherenceRegionValue newCacheValue = newCacheValue(value, version);
PutFromLoadProcessor processor = new PutFromLoadProcessor(minimalPutOverride, newCacheValue);
return (Boolean) getCoherenceRegion().invoke(key, processor);
}
use of com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue in project coherence-hibernate by coherence-community.
the class AbstractReadWriteCoherenceEntityDataAccess method lockItem.
/**
* {@inheritDoc}
*/
@Override
public org.hibernate.cache.spi.access.SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version) throws CacheException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("lockItem({}, {})", key, version);
}
CoherenceRegionValue valueIfAbsent = newCacheValue(null, version);
CoherenceRegionValue.SoftLock newSoftLock = newSoftLock();
SoftLockItemProcessor processor = new SoftLockItemProcessor(valueIfAbsent, newSoftLock);
getCoherenceRegion().invoke(key, processor);
return newSoftLock;
}
use of com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue in project coherence-hibernate by coherence-community.
the class AfterInsertProcessorTests method insertValue.
@Test
public void insertValue() throws ExecutionException, InterruptedException {
// Create the Coherence instance from the configuration
final Coherence coherence = Coherence.clusterMember();
coherence.start().get();
final Session coherenceSession = coherence.getSession();
final NamedCache<Long, CoherenceRegionValue> fooCache = coherenceSession.getCache("foo");
assertThat(fooCache.size()).isEqualTo(0);
final CoherenceRegionValue coherenceRegionValue = new CoherenceRegionValue("bar", 1, Instant.now().toEpochMilli());
final AfterInsertProcessor afterInsertProcessor = new AfterInsertProcessor(coherenceRegionValue);
Boolean result = fooCache.<Boolean>invoke(1L, afterInsertProcessor);
assertThat(result).isTrue();
assertThat(fooCache.size()).isEqualTo(1);
assertThat(fooCache.get(1L)).isEqualTo(coherenceRegionValue);
coherence.close();
}
use of com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue in project coherence-hibernate by coherence-community.
the class AfterUpdateProcessor method process.
// ---- interface com.tangosol.util.InvocableMap.EntryProcessor
/**
* {@inheritDoc}
*/
@Override
public Object process(InvocableMap.Entry entry) {
if (entry.isPresent()) {
CoherenceRegionValue cacheValue = (CoherenceRegionValue) entry.getValue();
cacheValue.releaseSoftLock(softLock, timeOfSoftLockRelease);
if (cacheValue.isSoftLocked()) {
// The cache value being processed was soft-locked concurrently by multiple Hibernate transactions.
// Under this condition we will not replace the cache value with the updated one.
// But we need to save the mutation to the present value's state (i.e. the release of a soft lock).
entry.setValue(cacheValue);
return false;
} else {
// The cache value was soft-locked by only one Hibernate transaction.
// Under this condition we can replace it with the updated one.
entry.setValue(replacementValue);
return true;
}
} else {
// Perhaps the value whose presence was expected will but put back into cache by a future putFromLoad call.
return false;
}
}
use of com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue in project coherence-hibernate by coherence-community.
the class ReadWritePutFromLoadProcessor method process.
// ---- interface com.tangosol.util.InvocableMap.EntryProcessor
/**
* {@inheritDoc}
*/
@Override
public Object process(InvocableMap.Entry entry) {
boolean isReplaceable = true;
if (entry.isPresent()) {
if (minimalPutsInEffect)
return false;
CoherenceRegionValue presentValue = (CoherenceRegionValue) entry.getValue();
isReplaceable = presentValue.isReplaceableFromLoad(txTimestamp, replacementValue.getVersion(), versionComparator);
}
if (isReplaceable)
entry.setValue(replacementValue);
return isReplaceable;
}
Aggregations