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;
}
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;
}
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();
}
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;
}
}
}
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;
}
}
}
Aggregations