use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method putIfAbsent.
@Override
public Object putIfAbsent(Data key, Object value, long ttl) {
checkIfLoaded();
final long now = getNow();
markRecordStoreExpirable(ttl);
Record record = getRecordOrNull(key, now, false);
Object oldValue;
if (record == null) {
oldValue = mapDataStore.load(key);
if (oldValue != null) {
record = createRecord(oldValue, DEFAULT_TTL, now);
storage.put(key, record);
}
} else {
accessRecord(record, now);
oldValue = record.getValue();
}
if (oldValue == null) {
value = mapServiceContext.interceptPut(name, null, value);
value = mapDataStore.add(key, value, now);
onStore(record);
record = createRecord(value, ttl, now);
storage.put(key, record);
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 containsKey.
@Override
public boolean containsKey(Data key) {
checkIfLoaded();
final long now = getNow();
Record record = getRecordOrNull(key, now, false);
if (record == null) {
record = loadRecordOrNull(key, false);
}
boolean contains = record != null;
if (contains) {
accessRecord(record, now);
}
return contains;
}
use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method loadEntries.
protected Map<Data, Object> loadEntries(Set<Data> keys) {
Map loadedEntries = mapDataStore.loadAll(keys);
if (loadedEntries == null || loadedEntries.isEmpty()) {
return Collections.emptyMap();
}
// holds serialized keys and if values are serialized, also holds them in serialized format.
Map<Data, Object> resultMap = createHashMap(loadedEntries.size());
// add loaded key-value pairs to this record-store.
Set entrySet = loadedEntries.entrySet();
for (Object object : entrySet) {
Map.Entry entry = (Map.Entry) object;
Data key = toData(entry.getKey());
Object value = entry.getValue();
resultMap.put(key, value);
putFromLoad(key, value);
}
if (hasQueryCache()) {
for (Data key : resultMap.keySet()) {
Record record = storage.get(key);
// here we are only publishing events for loaded entries. This is required for notifying query-caches
// otherwise query-caches cannot see loaded entries
addEventToQueryCache(record);
}
}
return resultMap;
}
use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class DefaultRecordStore method putFromLoadInternal.
private Object putFromLoadInternal(Data key, Object value, long ttl, boolean backup) {
if (!isKeyAndValueLoadable(key, value)) {
return null;
}
final long now = getNow();
if (shouldEvict()) {
return null;
}
markRecordStoreExpirable(ttl);
Record record = getRecordOrNull(key, now, false);
Object oldValue = null;
if (record == null) {
value = mapServiceContext.interceptPut(name, null, value);
record = createRecord(value, ttl, now);
storage.put(key, record);
} else {
oldValue = record.getValue();
value = mapServiceContext.interceptPut(name, oldValue, value);
updateRecord(key, record, value, now);
updateExpiryTime(record, ttl, mapContainer.getMapConfig());
}
if (!backup) {
saveIndex(record, oldValue);
}
return oldValue;
}
use of com.hazelcast.map.impl.record.Record in project hazelcast by hazelcast.
the class TxnLockAndGetOperation method run.
@Override
public void run() throws Exception {
if (!recordStore.txnLock(getKey(), ownerUuid, getThreadId(), getCallId(), ttl, blockReads)) {
throw new TransactionException("Transaction couldn't obtain lock.");
}
Record record = recordStore.getRecordOrNull(dataKey);
if (record == null && shouldLoad) {
record = recordStore.loadRecordOrNull(dataKey, false);
}
Data value = record == null ? null : mapServiceContext.toData(record.getValue());
response = new VersionedValue(value, record == null ? 0 : record.getVersion());
}
Aggregations