use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class ODeleteRecordTask method executeRecordTask.
@Override
public Object executeRecordTask(ODistributedRequestId requestId, final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentInternal database) throws Exception {
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), null, DIRECTION.IN, "Deleting record %s/%s v.%d", database.getName(), rid.toString(), version);
prepareUndoOperation();
if (previousRecord == null)
// ALREADY DELETED
return true;
final ORecord loadedRecord = previousRecord.copy();
if (loadedRecord != null)
loadedRecord.delete();
return true;
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class OResurrectRecordTask method executeRecordTask.
@Override
public Object executeRecordTask(ODistributedRequestId requestId, final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentInternal database) throws Exception {
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Resurrecting deleted record %s/%s v.%d reqId=%s", database.getName(), rid.toString(), version, requestId);
try {
database.getStorage().recyclePosition(rid, new byte[] {}, version, recordType);
// CREATE A RECORD TO CALL ALL THE HOOKS (LIKE INDEXES FOR UNIQUE CONSTRAINTS)
final ORecord loadedRecordInstance = Orient.instance().getRecordFactoryManager().newInstance(recordType);
ORecordInternal.fill(loadedRecordInstance, rid, version, content, true);
loadedRecordInstance.save();
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "+-> resurrected deleted record");
return Boolean.TRUE;
} catch (OPaginatedClusterException e) {
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "+-> no resurrection, because the record was not deleted");
return Boolean.TRUE;
} catch (Exception e) {
ODistributedServerLog.error(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "+-> error on resurrecting deleted record: the record is already deleted");
}
return Boolean.FALSE;
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class HookTxTest method testHookCannotBeginTx.
@Test(dependsOnMethods = "testHookCallsDelete")
public void testHookCannotBeginTx() throws IOException {
final AtomicBoolean exc = new AtomicBoolean(false);
database.activateOnCurrentThread();
database.registerHook(new ORecordHookAbstract() {
@Override
public RESULT onRecordBeforeCreate(ORecord iRecord) {
try {
database.activateOnCurrentThread();
database.begin();
} catch (IllegalStateException e) {
exc.set(true);
}
return null;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.BOTH;
}
});
Assert.assertFalse(exc.get());
new ODocument().field("test-hook", true).save();
Assert.assertTrue(exc.get());
database.activateOnCurrentThread();
database.close();
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class DictionaryTest method testDictionaryMassiveCreate.
@Test(dependsOnMethods = "testDictionaryDelete")
public void testDictionaryMassiveCreate() throws IOException {
final long originalSize = database.getDictionary().size();
// ASSURE TO STORE THE PAGE-SIZE + 3 FORCING THE CREATION OF LEFT AND RIGHT
final int total = 1000;
for (int i = total; i > 0; --i) {
database.getDictionary().put("key-" + (originalSize + i), new ODocument().field("test", "test-dictionary-" + i));
}
for (int i = total; i > 0; --i) {
ORecord record = database.getDictionary().get("key-" + (originalSize + i));
record.toString().equals("test-dictionary-" + i);
}
Assert.assertEquals(database.getDictionary().size(), originalSize + total);
}
use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.
the class SQLInsertTest method getValidPositions.
private List<Long> getValidPositions(int clusterId) {
final List<Long> positions = new ArrayList<Long>();
final ORecordIteratorCluster<?> iteratorCluster = database.browseCluster(database.getClusterNameById(clusterId));
for (int i = 0; i < 100; i++) {
if (!iteratorCluster.hasNext())
break;
ORecord doc = iteratorCluster.next();
positions.add(doc.getIdentity().getClusterPosition());
}
return positions;
}
Aggregations