Search in sources :

Example 16 with ORecordNotFoundException

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);
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with ORecordNotFoundException

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;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException)

Example 18 with ORecordNotFoundException

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;
}
Also used : BytesContainer(com.orientechnologies.orient.core.serialization.serializer.record.binary.BytesContainer) OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) ORecord(com.orientechnologies.orient.core.record.ORecord) OBinaryField(com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException)

Example 19 with ORecordNotFoundException

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();
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 20 with ORecordNotFoundException

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();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Aggregations

ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)27 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)15 ORecord (com.orientechnologies.orient.core.record.ORecord)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)5 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)3 OException (com.orientechnologies.common.exception.OException)3 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)3 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)3 ORID (com.orientechnologies.orient.core.id.ORID)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 Collection (java.util.Collection)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OPlaceholder (com.orientechnologies.orient.core.db.record.OPlaceholder)1 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)1