use of com.orientechnologies.orient.core.id.OContextualRecordId in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelect method executeSearchRecord.
protected boolean executeSearchRecord(final OIdentifiable id, final OCommandContext iContext, boolean callHooks) {
if (id == null)
return false;
final ORID identity = id.getIdentity();
if (uniqueResult != null) {
if (uniqueResult.containsKey(identity))
return true;
if (identity.isValid())
uniqueResult.put(identity, identity);
}
if (!checkInterruption())
return false;
final LOCKING_STRATEGY contextLockingStrategy = iContext.getVariable("$locking") != null ? (LOCKING_STRATEGY) iContext.getVariable("$locking") : null;
final LOCKING_STRATEGY localLockingStrategy = contextLockingStrategy != null ? contextLockingStrategy : lockingStrategy;
if (localLockingStrategy != null && !(localLockingStrategy == LOCKING_STRATEGY.DEFAULT || localLockingStrategy == LOCKING_STRATEGY.NONE || localLockingStrategy == LOCKING_STRATEGY.EXCLUSIVE_LOCK || localLockingStrategy == LOCKING_STRATEGY.SHARED_LOCK))
throw new IllegalStateException("Unsupported locking strategy " + localLockingStrategy);
if (localLockingStrategy == LOCKING_STRATEGY.SHARED_LOCK) {
id.lock(false);
if (id instanceof ORecord) {
final ORecord record = (ORecord) id;
record.reload(null, true, false);
}
} else if (localLockingStrategy == LOCKING_STRATEGY.EXCLUSIVE_LOCK) {
id.lock(true);
if (id instanceof ORecord) {
final ORecord record = (ORecord) id;
record.reload(null, true, false);
}
}
ORecord record = null;
try {
if (!(id instanceof ORecord)) {
record = getDatabase().load(id.getIdentity(), null, !isUseCache());
if (id instanceof OContextualRecordId && ((OContextualRecordId) id).getContext() != null) {
Map<String, Object> ridContext = ((OContextualRecordId) id).getContext();
for (String key : ridContext.keySet()) {
context.setVariable(key, ridContext.get(key));
}
}
} else {
record = (ORecord) id;
}
iContext.updateMetric("recordReads", +1);
if (record == null)
// SKIP IT
return true;
if (ORecordInternal.getRecordType(record) != ODocument.RECORD_TYPE && checkSkipBlob())
// SKIP binary records in case of projection.
return true;
iContext.updateMetric("documentReads", +1);
iContext.setVariable("current", record);
if (filter(record, iContext)) {
if (callHooks) {
((ODatabaseDocumentInternal) getDatabase()).callbackHooks(ORecordHook.TYPE.BEFORE_READ, record);
((ODatabaseDocumentInternal) getDatabase()).callbackHooks(ORecordHook.TYPE.AFTER_READ, record);
}
if (parallel) {
try {
applyGroupBy(record, iContext);
resultQueue.put(new AsyncResult(record, iContext));
} catch (InterruptedException e) {
Thread.interrupted();
return false;
}
tmpQueueOffer.incrementAndGet();
} else {
applyGroupBy(record, iContext);
if (!handleResult(record, iContext)) {
// LIMIT REACHED
return false;
}
}
}
} finally {
if (localLockingStrategy != null && record != null && record.isLocked()) {
// CONTEXT LOCK: lock must be released (no matter if filtered or not)
if (localLockingStrategy == LOCKING_STRATEGY.EXCLUSIVE_LOCK || localLockingStrategy == LOCKING_STRATEGY.SHARED_LOCK) {
record.unlock();
}
}
}
return true;
}
Aggregations