Search in sources :

Example 1 with MVCCEntry

use of org.infinispan.container.entries.MVCCEntry in project hibernate-orm by hibernate.

the class TombstoneCallInterceptor method visitPutKeyValueCommand.

@Override
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
    MVCCEntry e = (MVCCEntry) ctx.lookupEntry(command.getKey());
    if (e == null) {
        return null;
    }
    log.tracef("In cache %s(%d) applying update %s to %s", cache.getName(), region.getLastRegionInvalidation(), command.getValue(), e.getValue());
    try {
        Object value = command.getValue();
        if (value instanceof TombstoneUpdate) {
            return handleTombstoneUpdate(e, (TombstoneUpdate) value, command);
        } else if (value instanceof Tombstone) {
            return handleTombstone(e, (Tombstone) value);
        } else if (value instanceof FutureUpdate) {
            return handleFutureUpdate(e, (FutureUpdate) value, command);
        } else {
            return super.visitPutKeyValueCommand(ctx, command);
        }
    } finally {
        log.tracef("Result is %s", e.getValue());
    }
}
Also used : TombstoneUpdate(org.hibernate.cache.infinispan.util.TombstoneUpdate) Tombstone(org.hibernate.cache.infinispan.util.Tombstone) MVCCEntry(org.infinispan.container.entries.MVCCEntry) FutureUpdate(org.hibernate.cache.infinispan.util.FutureUpdate)

Example 2 with MVCCEntry

use of org.infinispan.container.entries.MVCCEntry in project hibernate-orm by hibernate.

the class VersionedCallInterceptor method visitPutKeyValueCommand.

@Override
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
    MVCCEntry e = (MVCCEntry) ctx.lookupEntry(command.getKey());
    if (e == null) {
        return null;
    }
    Object oldValue = e.getValue();
    Object oldVersion = null;
    long oldTimestamp = Long.MIN_VALUE;
    if (oldValue instanceof VersionedEntry) {
        oldVersion = ((VersionedEntry) oldValue).getVersion();
        oldTimestamp = ((VersionedEntry) oldValue).getTimestamp();
        oldValue = ((VersionedEntry) oldValue).getValue();
    } else if (oldValue instanceof org.hibernate.cache.spi.entry.CacheEntry) {
        oldVersion = ((org.hibernate.cache.spi.entry.CacheEntry) oldValue).getVersion();
    }
    Object newValue = command.getValue();
    Object newVersion;
    long newTimestamp;
    Object actualNewValue = newValue;
    boolean isRemoval = false;
    if (newValue instanceof VersionedEntry) {
        VersionedEntry ve = (VersionedEntry) newValue;
        newVersion = ve.getVersion();
        newTimestamp = ve.getTimestamp();
        if (ve.getValue() == null) {
            isRemoval = true;
        } else if (ve.getValue() instanceof org.hibernate.cache.spi.entry.CacheEntry) {
            actualNewValue = ve.getValue();
        }
    } else {
        throw new IllegalArgumentException(String.valueOf(newValue));
    }
    if (newVersion == null) {
        // eviction or post-commit removal: we'll store it with given timestamp
        setValue(e, newValue, expiringMetadata);
        return null;
    }
    if (oldVersion == null) {
        assert oldValue == null || oldTimestamp != Long.MIN_VALUE;
        if (newTimestamp <= oldTimestamp) {
            // the invalid value
            assert oldValue == null;
        } else {
            setValue(e, actualNewValue, defaultMetadata);
        }
        return null;
    }
    int compareResult = versionComparator.compare(newVersion, oldVersion);
    if (isRemoval && compareResult >= 0) {
        setValue(e, actualNewValue, expiringMetadata);
    } else if (compareResult > 0) {
        setValue(e, actualNewValue, defaultMetadata);
    }
    return null;
}
Also used : VersionedEntry(org.hibernate.cache.infinispan.util.VersionedEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) MVCCEntry(org.infinispan.container.entries.MVCCEntry)

Aggregations

MVCCEntry (org.infinispan.container.entries.MVCCEntry)2 FutureUpdate (org.hibernate.cache.infinispan.util.FutureUpdate)1 Tombstone (org.hibernate.cache.infinispan.util.Tombstone)1 TombstoneUpdate (org.hibernate.cache.infinispan.util.TombstoneUpdate)1 VersionedEntry (org.hibernate.cache.infinispan.util.VersionedEntry)1 CacheEntry (org.infinispan.container.entries.CacheEntry)1