Example usage for org.hibernate.cache.spi.entry CacheEntry getVersion

List of usage examples for org.hibernate.cache.spi.entry CacheEntry getVersion

Introduction

In this page you can find the example usage for org.hibernate.cache.spi.entry CacheEntry getVersion.

Prototype

Object getVersion();

Source Link

Document

Retrieves the version (optimistic locking) associated with this cache entry.

Usage

From source file:com.hazelcast.hibernate.serialization.Hibernate42CacheEntrySerializer.java

License:Open Source License

private static void writeDisassembled(ObjectDataOutput out, CacheEntry object) throws IOException {

    Serializable[] disassembledState = object.getDisassembledState();
    out.writeInt(disassembledState.length);
    for (Serializable state : disassembledState) {
        out.writeObject(state);/*from www.j  av  a 2s. c o  m*/
    }

    out.writeUTF(object.getSubclass());
    out.writeBoolean(object.areLazyPropertiesUnfetched());
    out.writeObject(object.getVersion());

}

From source file:com.hazelcast.hibernate.serialization.Hibernate51CacheEntrySerializer.java

License:Open Source License

private static void writeDisassembled(final ObjectDataOutput out, final CacheEntry object) throws IOException {

    Serializable[] disassembledState = object.getDisassembledState();
    out.writeInt(disassembledState.length);
    for (Serializable state : disassembledState) {
        out.writeObject(state);//www  .  j  a  v  a2 s  .co  m
    }

    out.writeUTF(object.getSubclass());
    out.writeObject(object.getVersion());
}

From source file:com.hazelcast.hibernate.serialization.Hibernate5CacheEntrySerializer.java

License:Open Source License

private static void writeDisassembled(final ObjectDataOutput out, final CacheEntry object) throws IOException {

    Serializable[] disassembledState = object.getDisassembledState();
    out.writeInt(disassembledState.length);
    for (Serializable state : disassembledState) {
        out.writeObject(state);/* ww w.  j a v a 2 s .com*/
    }

    out.writeUTF(object.getSubclass());
    out.writeBoolean(object.areLazyPropertiesUnfetched());
    out.writeObject(object.getVersion());
}

From source file:com.hazelcast.hibernate.VersionAwareMapMergePolicy.java

License:Open Source License

public Object merge(String mapName, EntryView mergingEntry, EntryView existingEntry) {
    final Object existingValue = existingEntry != null ? existingEntry.getValue() : null;
    final Object mergingValue = mergingEntry.getValue();
    if (existingValue != null && existingValue instanceof CacheEntry && mergingValue != null
            && mergingValue instanceof CacheEntry) {

        final CacheEntry existingCacheEntry = (CacheEntry) existingValue;
        final CacheEntry mergingCacheEntry = (CacheEntry) mergingValue;
        final Object mergingVersionObject = mergingCacheEntry.getVersion();
        final Object existingVersionObject = existingCacheEntry.getVersion();
        if (mergingVersionObject != null && existingVersionObject != null
                && mergingVersionObject instanceof Comparable && existingVersionObject instanceof Comparable) {

            final Comparable mergingVersion = (Comparable) mergingVersionObject;
            final Comparable existingVersion = (Comparable) existingVersionObject;

            if (mergingVersion.compareTo(existingVersion) > 0) {
                return mergingValue;
            } else {
                return existingValue;
            }/*ww  w  .  j  a  v  a  2s  . c o  m*/
        }
    }
    return mergingValue;
}

From source file:com.hazelcast.hibernate4.distributed.IMapRegionCache.java

License:Open Source License

public boolean update(final Object key, final Object value, final Object currentVersion,
        final Object previousVersion, final SoftLock lock) {
    if (lock == LOCK_FAILURE) {
        logger.log(Level.WARNING, "Cache lock could not be acquired!");
        return false;
    }//  w  ww  . j  ava 2  s .  co  m
    if (versionComparator != null && currentVersion != null) {
        if (explicitVersionCheckEnabled && value instanceof CacheEntry) {
            try {
                final CacheEntry currentEntry = (CacheEntry) value;
                final CacheEntry previousEntry = (CacheEntry) map.tryLockAndGet(key, tryLockAndGetTimeout,
                        TimeUnit.MILLISECONDS);
                if (previousEntry == null || versionComparator.compare(currentEntry.getVersion(),
                        previousEntry.getVersion()) > 0) {
                    map.putAndUnlock(key, value);
                    return true;
                } else {
                    map.unlock(key);
                    return false;
                }
            } catch (TimeoutException e) {
                return false;
            }
        } else if (previousVersion == null || versionComparator.compare(currentVersion, previousVersion) > 0) {
            map.set(key, value, 0, TimeUnit.MILLISECONDS);
        }
        return false;
    } else {
        map.set(key, value, 0, TimeUnit.MILLISECONDS);
        return true;
    }
}

From source file:com.hazelcast.hibernate4.VersionAwareMergePolicy.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
public Object merge(String mapName, MapEntry mergingEntry, MapEntry existingEntry) {
    DataRecordEntry mergingDataEntry = (DataRecordEntry) mergingEntry;
    if (!mergingDataEntry.isValid()) {
        return REMOVE_EXISTING;
    } else {/*from ww w  . j av a  2  s .  c  om*/
        final Object existingObject = existingEntry != null ? existingEntry.getValue() : null;
        final Object mergingObject = mergingEntry.getValue();
        if (existingObject != null && existingObject instanceof CacheEntry && mergingObject != null
                && mergingObject instanceof CacheEntry) {
            final CacheEntry existing = (CacheEntry) existingObject;
            final CacheEntry merging = (CacheEntry) mergingObject;
            final Object mergingVersionObject = merging.getVersion();
            final Object existingVersionObject = existing.getVersion();
            if (mergingVersionObject != null && existingVersionObject != null
                    && mergingVersionObject instanceof Comparable
                    && existingVersionObject instanceof Comparable) {
                final Comparable mergingVersion = (Comparable) mergingVersionObject;
                final Comparable existingVersion = (Comparable) existingVersionObject;
                if (mergingVersion.compareTo(existingVersion) > 0) {
                    return mergingDataEntry.getValueData();
                } else {
                    return ((DataRecordEntry) existingEntry).getValueData();
                }
            }
        }
        return mergingDataEntry.getValueData();
    }
}