use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.
the class OFetchHelper method fetchMap.
@SuppressWarnings("unchecked")
private static void fetchMap(final ODocument iRootRecord, final Object iUserObject, final OFetchPlan iFetchPlan, Object fieldValue, String fieldName, final int iCurrentLevel, final int iLevelFromRoot, final int iFieldDepthLevel, final Map<ORID, Integer> parsedRecords, final String iFieldPathFromRoot, final OFetchListener iListener, final OFetchContext iContext) throws IOException {
final Map<String, ODocument> linked = (Map<String, ODocument>) fieldValue;
iContext.onBeforeMap(iRootRecord, fieldName, iUserObject);
for (Object key : linked.keySet()) {
final Object o = linked.get(key);
if (o instanceof OIdentifiable) {
ORecord r = null;
try {
r = ((OIdentifiable) o).getRecord();
} catch (ORecordNotFoundException notFound) {
}
if (r != null) {
if (r instanceof ODocument) {
// GO RECURSIVELY
final ODocument d = (ODocument) r;
final Integer fieldDepthLevel = parsedRecords.get(d.getIdentity());
if (!d.getIdentity().isValid() || (fieldDepthLevel != null && fieldDepthLevel.intValue() == iLevelFromRoot)) {
removeParsedFromMap(parsedRecords, d);
iContext.onBeforeDocument(iRootRecord, d, key.toString(), iUserObject);
final Object userObject = iListener.fetchLinkedMapEntry(iRootRecord, iUserObject, fieldName, key.toString(), d, iContext);
processRecord(d, userObject, iFetchPlan, iCurrentLevel, iLevelFromRoot, iFieldDepthLevel, parsedRecords, iFieldPathFromRoot, iListener, iContext, "");
iContext.onAfterDocument(iRootRecord, d, key.toString(), iUserObject);
} else {
iListener.parseLinked(iRootRecord, d, iUserObject, key.toString(), iContext);
}
} else
iListener.parseLinked(iRootRecord, r, iUserObject, key.toString(), iContext);
} else {
iListener.processStandardField(iRootRecord, o, key.toString(), iContext, iUserObject, "", null);
}
} else if (o instanceof Map) {
fetchMap(iRootRecord, iUserObject, iFetchPlan, o, key.toString(), iCurrentLevel + 1, iLevelFromRoot, iFieldDepthLevel, parsedRecords, iFieldPathFromRoot, iListener, iContext);
} else if (OMultiValue.isMultiValue(o)) {
fetchCollection(iRootRecord, iUserObject, iFetchPlan, o, key.toString(), iCurrentLevel + 1, iLevelFromRoot, iFieldDepthLevel, parsedRecords, iFieldPathFromRoot, iListener, iContext);
} else
iListener.processStandardField(iRootRecord, o, key.toString(), iContext, iUserObject, "", null);
}
iContext.onAfterMap(iRootRecord, fieldName, iUserObject);
}
use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.
the class ORecordSerializerBinaryV0 method writeOptimizedLink.
private int writeOptimizedLink(final BytesContainer bytes, OIdentifiable link) {
if (!link.getIdentity().isPersistent()) {
try {
final ORecord real = link.getRecord();
if (real != null)
link = real;
} catch (ORecordNotFoundException ex) {
// IGNORE IT WILL FAIL THE ASSERT IN CASE
}
}
if (link.getIdentity().getClusterId() < 0 && ORecordSerializationContext.getContext() != null)
throw new ODatabaseException("Impossible to serialize invalid link " + link.getIdentity());
final int pos = OVarIntSerializer.write(bytes, link.getIdentity().getClusterId());
OVarIntSerializer.write(bytes, link.getIdentity().getClusterPosition());
return pos;
}
use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.
the class OSQLFilterCondition method evaluate.
protected Object evaluate(OIdentifiable iCurrentRecord, final ODocument iCurrentResult, final Object iValue, final OCommandContext iContext, final boolean binaryEvaluation) {
if (iValue == null)
return null;
if (iValue instanceof BytesContainer)
return iValue;
if (iCurrentRecord != null) {
iCurrentRecord = iCurrentRecord.getRecord();
if (iCurrentRecord != null && ((ORecord) iCurrentRecord).getInternalStatus() == ORecordElement.STATUS.NOT_LOADED) {
try {
iCurrentRecord = iCurrentRecord.getRecord().load();
} catch (ORecordNotFoundException e) {
return null;
}
}
}
if (binaryEvaluation && iValue instanceof OSQLFilterItemField) {
final OBinaryField bField = ((OSQLFilterItemField) iValue).getBinaryField(iCurrentRecord);
if (bField != null)
return bField;
}
if (iValue instanceof OSQLFilterItem) {
return ((OSQLFilterItem) iValue).getValue(iCurrentRecord, iCurrentResult, iContext);
}
if (iValue instanceof OSQLFilterCondition) {
// NESTED CONDITION: EVALUATE IT RECURSIVELY
return ((OSQLFilterCondition) iValue).evaluate(iCurrentRecord, iCurrentResult, iContext);
}
if (iValue instanceof OSQLFunctionRuntime) {
// STATELESS FUNCTION: EXECUTE IT
final OSQLFunctionRuntime f = (OSQLFunctionRuntime) iValue;
return f.execute(iCurrentRecord, iCurrentRecord, iCurrentResult, iContext);
}
if (OMultiValue.isMultiValue(iValue)) {
final Iterable<?> multiValue = OMultiValue.getMultiValueIterable(iValue, false);
// MULTI VALUE: RETURN A COPY
final ArrayList<Object> result = new ArrayList<Object>(OMultiValue.getSize(iValue));
for (final Object value : multiValue) {
if (value instanceof OSQLFilterItem) {
result.add(((OSQLFilterItem) value).getValue(iCurrentRecord, iCurrentResult, iContext));
} else {
result.add(value);
}
}
return result;
}
// SIMPLE VALUE: JUST RETURN IT
return iValue;
}
use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.
the class OCommandExecutorSQLUpdate method execute.
public Object execute(final Map<Object, Object> iArgs) {
if (subjectName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
parameters = new OCommandParameters(iArgs);
Map<Object, Object> queryArgs;
if (parameters.size() > 0 && parameters.getByName(0) != null) {
queryArgs = new HashMap<Object, Object>();
for (int i = parameterCounter; i < parameters.size(); i++) {
if (parameters.getByName(i) != null)
queryArgs.put(i - parameterCounter, parameters.getByName(i));
}
} else {
queryArgs = iArgs;
}
query.setContext(context);
returnHandler.reset();
if (lockStrategy.equals("RECORD"))
query.getContext().setVariable("$locking", OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK);
getDatabase().query(query, queryArgs);
if (upsertMode && !updated) {
// IF UPDATE DOES NOT PRODUCE RESULTS AND UPSERT MODE IS ENABLED, CREATE DOCUMENT AND APPLY SET/ADD/PUT/MERGE and so on
final ODocument doc = subjectName != null ? new ODocument(subjectName) : new ODocument();
final String suspendedLockStrategy = lockStrategy;
// New record hasn't been created under exclusive lock - just to avoid releasing locks by result(doc)
lockStrategy = "NONE";
try {
result(doc);
} catch (ORecordDuplicatedException e) {
if (upsertMode)
// UPDATE THE NEW RECORD
getDatabase().query(query, queryArgs);
else
throw e;
} catch (ORecordNotFoundException e) {
if (upsertMode)
// UPDATE THE NEW RECORD
getDatabase().query(query, queryArgs);
else
throw e;
} catch (OConcurrentModificationException e) {
if (upsertMode)
// UPDATE THE NEW RECORD
getDatabase().query(query, queryArgs);
else
throw e;
}
lockStrategy = suspendedLockStrategy;
}
return returnHandler.ret();
}
use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.
the class OPaginatedCluster method readRecordIfVersionIsNotLatest.
@Override
public ORawBuffer readRecordIfVersionIsNotLatest(long clusterPosition, final int recordVersion) throws IOException, ORecordNotFoundException {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
OClusterPositionMapBucket.PositionEntry positionEntry = clusterPositionMap.get(clusterPosition, 1);
if (positionEntry == null)
throw new ORecordNotFoundException(new ORecordId(id, clusterPosition), "Record for cluster with id " + id + " and position " + clusterPosition + " is absent.");
int recordPosition = positionEntry.getRecordPosition();
long pageIndex = positionEntry.getPageIndex();
if (getFilledUpTo(atomicOperation, fileId) <= pageIndex)
throw new ORecordNotFoundException(new ORecordId(id, clusterPosition), "Record for cluster with id " + id + " and position " + clusterPosition + " is absent.");
int loadedRecordVersion;
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
try {
final OClusterPage localPage = new OClusterPage(cacheEntry, false, getChanges(atomicOperation, cacheEntry));
if (localPage.isDeleted(recordPosition))
throw new ORecordNotFoundException(new ORecordId(id, clusterPosition), "Record for cluster with id " + id + " and position " + clusterPosition + " is absent.");
loadedRecordVersion = localPage.getRecordVersion(recordPosition);
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
if (loadedRecordVersion > recordVersion)
return readRecord(clusterPosition, false);
return null;
} finally {
releaseSharedLock();
}
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
Aggregations