Search in sources :

Example 36 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class HookSaveTest method testCreatedLinkedInHook.

@Test
public void testCreatedLinkedInHook() {
    database.registerHook(new ORecordHook() {

        @Override
        public void onUnregister() {
        }

        @Override
        public RESULT onTrigger(TYPE iType, ORecord iRecord) {
            if (iType != TYPE.BEFORE_CREATE)
                return RESULT.RECORD_NOT_CHANGED;
            ODocument doc = (ODocument) iRecord;
            if (doc.containsField("test"))
                return RESULT.RECORD_NOT_CHANGED;
            ODocument doc1 = new ODocument();
            doc1.field("test", "value");
            doc.field("testNewLinkedRecord", doc1);
            return RESULT.RECORD_CHANGED;
        }

        @Override
        public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
            return null;
        }
    });
    ODocument doc = database.save(new ODocument("test"));
    ODocument newRef = doc.field("testNewLinkedRecord");
    assertNotNull(newRef);
    assertNotNull(newRef.getIdentity().isPersistent());
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 37 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class HookSaveTest method testCreatedBackLinkedInHook.

@Test
public void testCreatedBackLinkedInHook() {
    database.registerHook(new ORecordHook() {

        @Override
        public void onUnregister() {
        }

        @Override
        public RESULT onTrigger(TYPE iType, ORecord iRecord) {
            if (iType != TYPE.BEFORE_CREATE)
                return RESULT.RECORD_NOT_CHANGED;
            ODocument doc = (ODocument) iRecord;
            if (doc.containsField("test"))
                return RESULT.RECORD_NOT_CHANGED;
            ODocument doc1 = new ODocument();
            doc1.field("test", "value");
            doc.field("testNewLinkedRecord", doc1);
            doc1.field("backLink", doc);
            return RESULT.RECORD_CHANGED;
        }

        @Override
        public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
            return null;
        }
    });
    ODocument doc = database.save(new ODocument("test"));
    ODocument newRef = doc.field("testNewLinkedRecord");
    assertNotNull(newRef);
    assertNotNull(newRef.getIdentity().isPersistent());
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 38 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class TestBinaryRecordsQuery method testSelectRidBinary.

@Test
public void testSelectRidBinary() {
    ORecord rec = database.save(new ORecordBytes("blabla".getBytes()), "BlobCluster");
    List<ORecord> res = database.query(new OSQLSynchQuery<Object>("select @rid from cluster:BlobCluster"));
    assertEquals(1, res.size());
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) Test(org.junit.Test)

Example 39 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class TestBinaryRecordsQuery method testDeleteBinary.

@Test
public void testDeleteBinary() {
    ORecord rec = database.save(new ORecordBytes("blabla".getBytes()), "BlobCluster");
    Integer res = database.command(new OCommandSQL("delete from (select from cluster:BlobCluster)")).execute();
    database.getLocalCache().clear();
    assertEquals(1, res.intValue());
    rec = database.load(rec.getIdentity());
    assertNull(rec);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) Test(org.junit.Test)

Example 40 with ORecord

use of com.orientechnologies.orient.core.record.ORecord in project orientdb by orientechnologies.

the class TestBinaryRecordsQuery method testDeleteFromSelectBinary.

@Test
public void testDeleteFromSelectBinary() {
    ORecord rec = database.save(new ORecordBytes("blabla".getBytes()), "BlobCluster");
    ORecord rec1 = database.save(new ORecordBytes("blabla".getBytes()), "BlobCluster");
    database.getMetadata().getSchema().createClass("RecordPointer");
    ODocument doc = new ODocument("RecordPointer");
    doc.field("ref", rec);
    database.save(doc);
    ODocument doc1 = new ODocument("RecordPointer");
    doc1.field("ref", rec1);
    database.save(doc1);
    Integer res = database.command(new OCommandSQL("delete from (select expand(ref) from RecordPointer)")).execute();
    database.getLocalCache().clear();
    assertEquals(2, res.intValue());
    rec = database.load(rec.getIdentity());
    assertNull(rec);
    rec = database.load(rec1.getIdentity());
    assertNull(rec);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ORecord (com.orientechnologies.orient.core.record.ORecord)194 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)91 ORecordId (com.orientechnologies.orient.core.id.ORecordId)40 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)36 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)27 ORID (com.orientechnologies.orient.core.id.ORID)27 IOException (java.io.IOException)21 OException (com.orientechnologies.common.exception.OException)17 Test (org.junit.Test)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)15 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)15 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)15 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)8 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)8 Test (org.testng.annotations.Test)8 OIOException (com.orientechnologies.common.io.OIOException)7