Search in sources :

Example 1 with CoherenceRegionValue

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);
}
Also used : CoherenceRegionValue(com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue) PutFromLoadProcessor(com.oracle.coherence.hibernate.cache.v53.access.processor.PutFromLoadProcessor)

Example 2 with CoherenceRegionValue

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;
}
Also used : CoherenceRegionValue(com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue) SoftLockItemProcessor(com.oracle.coherence.hibernate.cache.v53.access.processor.SoftLockItemProcessor)

Example 3 with CoherenceRegionValue

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();
}
Also used : CoherenceRegionValue(com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue) Coherence(com.tangosol.net.Coherence) Session(com.tangosol.net.Session) Test(org.junit.Test)

Example 4 with CoherenceRegionValue

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;
    }
}
Also used : CoherenceRegionValue(com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue)

Example 5 with CoherenceRegionValue

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;
}
Also used : CoherenceRegionValue(com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue)

Aggregations

CoherenceRegionValue (com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue)8 AfterUpdateProcessor (com.oracle.coherence.hibernate.cache.v53.access.processor.AfterUpdateProcessor)1 PutFromLoadProcessor (com.oracle.coherence.hibernate.cache.v53.access.processor.PutFromLoadProcessor)1 ReadWritePutFromLoadProcessor (com.oracle.coherence.hibernate.cache.v53.access.processor.ReadWritePutFromLoadProcessor)1 SoftLockItemProcessor (com.oracle.coherence.hibernate.cache.v53.access.processor.SoftLockItemProcessor)1 Coherence (com.tangosol.net.Coherence)1 Session (com.tangosol.net.Session)1 Test (org.junit.Test)1