use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method loadRecordOrNull.
@Override
public Record loadRecordOrNull(Data key, boolean backup) {
Record record = null;
final Object value = mapDataStore.load(key);
if (value != null) {
record = createRecord(value, DEFAULT_TTL, getNow());
storage.put(key, record);
if (!backup) {
saveIndex(record, null);
}
evictEntries(key);
}
// otherwise query-caches cannot see loaded entries
if (!backup && record != null && hasQueryCache()) {
addEventToQueryCache(record);
}
return record;
}
use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method getAll.
@Override
public MapEntries getAll(Set<Data> keys) {
checkIfLoaded();
final long now = getNow();
final MapEntries mapEntries = new MapEntries(keys.size());
final Iterator<Data> iterator = keys.iterator();
while (iterator.hasNext()) {
final Data key = iterator.next();
final Record record = getRecordOrNull(key, now, false);
if (record != null) {
addMapEntrySet(key, record.getValue(), mapEntries);
accessRecord(record, now);
iterator.remove();
}
}
Map loadedEntries = loadEntries(keys);
addMapEntrySet(loadedEntries, mapEntries);
return mapEntries;
}
use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method putInternal.
protected Object putInternal(Data key, Object value, long ttl, boolean loadFromStore) {
checkIfLoaded();
long now = getNow();
markRecordStoreExpirable(ttl);
Record record = getRecordOrNull(key, now, false);
Object oldValue = record == null ? (loadFromStore ? mapDataStore.load(key) : null) : record.getValue();
value = mapServiceContext.interceptPut(name, oldValue, value);
value = mapDataStore.add(key, value, now);
onStore(record);
if (record == null) {
record = createRecord(value, ttl, now);
storage.put(key, record);
} else {
updateRecord(key, record, value, now);
updateExpiryTime(record, ttl, mapContainer.getMapConfig());
}
saveIndex(record, oldValue);
return oldValue;
}
use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method merge.
@Override
public boolean merge(Data key, EntryView mergingEntry, MapMergePolicy mergePolicy) {
checkIfLoaded();
final long now = getNow();
Record record = getRecordOrNull(key, now, false);
mergingEntry = EntryViews.convertToLazyEntryView(mergingEntry, serializationService, mergePolicy);
Object newValue;
Object oldValue = null;
if (record == null) {
final Object notExistingKey = mapServiceContext.toObject(key);
final EntryView nullEntryView = EntryViews.createNullEntryView(notExistingKey);
newValue = mergePolicy.merge(name, mergingEntry, nullEntryView);
if (newValue == null) {
return false;
}
newValue = mapDataStore.add(key, newValue, now);
record = createRecord(newValue, DEFAULT_TTL, now);
mergeRecordExpiration(record, mergingEntry);
storage.put(key, record);
} else {
oldValue = record.getValue();
EntryView existingEntry = EntryViews.createLazyEntryView(record.getKey(), record.getValue(), record, serializationService, mergePolicy);
newValue = mergePolicy.merge(name, mergingEntry, existingEntry);
// existing entry will be removed
if (newValue == null) {
removeIndex(record);
mapDataStore.remove(key, now);
onStore(record);
storage.removeRecord(record);
updateStatsOnRemove(record.getHits());
return true;
}
if (newValue == mergingEntry.getValue()) {
mergeRecordExpiration(record, mergingEntry);
}
// same with the existing entry so no need to map-store etc operations.
if (recordFactory.isEquals(newValue, oldValue)) {
return true;
}
newValue = mapDataStore.add(key, newValue, now);
onStore(record);
storage.updateRecordValue(key, record, newValue);
}
saveIndex(record, oldValue);
return newValue != null;
}
use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method remove.
@Override
public Object remove(Data key) {
checkIfLoaded();
final long now = getNow();
final Record record = getRecordOrNull(key, now, false);
Object oldValue;
if (record == null) {
oldValue = mapDataStore.load(key);
if (oldValue != null) {
mapDataStore.remove(key, now);
}
} else {
oldValue = removeRecord(key, record, now);
}
return oldValue;
}
Aggregations