Search in sources :

Example 11 with ORecordNotFoundException

use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.

the class OServerCommandGetDictionary method execute.

@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
    iRequest.data.commandInfo = "Dictionary lookup";
    String[] urlParts = checkSyntax(iRequest.url, 3, "Syntax error: dictionary/<database>/<key>");
    ODatabaseDocument db = null;
    try {
        db = getProfiledDatabaseInstance(iRequest);
        final ORecord record = db.getDictionary().get(urlParts[2]);
        if (record == null)
            throw new ORecordNotFoundException(null, "Key '" + urlParts[2] + "' was not found in the database dictionary");
        iResponse.writeRecord(record);
    } finally {
        if (db != null)
            db.close();
    }
    return false;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException)

Example 12 with ORecordNotFoundException

use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.

the class LocalPaginatedStorageIncrementalSync method updateRecord.

private boolean updateRecord(Random random) {
    originalDB.activateOnCurrentThread();
    final int clusterId = originalDB.getClusterIdByName("Sample");
    final long[] rids = originalDB.getStorage().getClusterDataRange(clusterId);
    boolean updated = false;
    if (rids[0] == -1)
        return false;
    while (!updated) {
        final int deleteIndex = random.nextInt(rids.length);
        final ORecordId recordId = new ORecordId(clusterId, rids[deleteIndex]);
        try {
            final ODocument document = originalDB.load(recordId);
            if (document != null) {
                final byte[] data = new byte[256];
                random.nextBytes(data);
                document.field("data", data);
                document.save();
                updated = true;
            }
        } catch (ORecordNotFoundException e) {
            updated = false;
        }
    }
    return true;
}
Also used : ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 13 with ORecordNotFoundException

use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.

the class CRUDDocumentPhysicalTest method testRemoveAndReload.

public void testRemoveAndReload() {
    ODocument doc1;
    database.begin();
    {
        doc1 = new ODocument();
        doc1.save();
    }
    database.commit();
    database.begin();
    {
        database.delete(doc1);
    }
    database.commit();
    database.begin();
    {
        ODocument deletedDoc = database.load(doc1.getIdentity());
        // OK!
        Assert.assertNull(deletedDoc);
    }
    database.commit();
    database.begin();
    try {
        doc1.reload();
        // <=================== AssertionError
        Assert.fail();
    } catch (ORecordNotFoundException e) {
    // OK
    // The JavaDoc of #reload() is documented : "If the record does not exist a ORecordNotFoundException exception is thrown.".
    }
    database.commit();
}
Also used : ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 14 with ORecordNotFoundException

use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.

the class ORecordLazyList method convertLink2Record.

/**
   * Convert the item requested from link to record.
   * 
   * @param iIndex
   *          Position of the item to convert
   */
private void convertLink2Record(final int iIndex) {
    if (ridOnly || !autoConvertToRecord)
        // PRECONDITIONS
        return;
    final OIdentifiable o = super.get(iIndex);
    if (contentType == MULTIVALUE_CONTENT_TYPE.ALL_RECORDS && !o.getIdentity().isNew())
        // ALL RECORDS AND THE OBJECT IS NOT NEW, DO NOTHING
        return;
    if (o != null && o instanceof ORecordId) {
        final ORecordId rid = (ORecordId) o;
        marshalling = true;
        try {
            ORecord record = rid.getRecord();
            if (record != null) {
                ORecordInternal.unTrack(sourceRecord, rid);
                ORecordInternal.track(sourceRecord, record);
            }
            super.set(iIndex, record);
        } catch (ORecordNotFoundException e) {
        // IGNORE THIS
        } finally {
            marshalling = false;
        }
    }
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 15 with ORecordNotFoundException

use of com.orientechnologies.orient.core.exception.ORecordNotFoundException in project orientdb by orientechnologies.

the class ORecordLazyMap method convertLink2Record.

/**
   * Convert the item with the received key to a record.
   * 
   * @param iKey
   *          Key of the item to convert
   */
private void convertLink2Record(final Object iKey) {
    if (status == MULTIVALUE_CONTENT_TYPE.ALL_RECORDS)
        return;
    final Object value;
    if (iKey instanceof ORID)
        value = iKey;
    else
        value = super.get(iKey);
    if (value != null && value instanceof ORID) {
        final ORID rid = (ORID) value;
        marshalling = true;
        try {
            try {
                // OVERWRITE IT
                ORecord record = rid.getRecord();
                if (record != null) {
                    ORecordInternal.unTrack(sourceRecord, rid);
                    ORecordInternal.track(sourceRecord, record);
                }
                super.put(iKey, record);
            } catch (ORecordNotFoundException e) {
            // IGNORE THIS
            }
        } finally {
            marshalling = false;
        }
    }
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ORID(com.orientechnologies.orient.core.id.ORID)

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