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