Search in sources :

Example 71 with ORecord

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

Example 72 with ORecord

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

Example 73 with ORecord

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordHookAbstract(com.orientechnologies.orient.core.hook.ORecordHookAbstract) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 74 with ORecord

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);
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 75 with ORecord

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

Aggregations

ORecord (com.orientechnologies.orient.core.record.ORecord)177 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)80 ORecordId (com.orientechnologies.orient.core.id.ORecordId)37 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)35 ORID (com.orientechnologies.orient.core.id.ORID)24 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)19 IOException (java.io.IOException)18 Test (org.junit.Test)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)14 OException (com.orientechnologies.common.exception.OException)13 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)13 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)12 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)11 ArrayList (java.util.ArrayList)10 Test (org.testng.annotations.Test)8 OIOException (com.orientechnologies.common.io.OIOException)7 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)7 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)7 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)6 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)6