use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestModels method testODocumentModel.
@Test
public void testODocumentModel() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
ORecordId recordId = new ORecordId("#6:0");
ODocumentModel model = new ODocumentModel(recordId);
assertModelObjectEquals(recordId.getRecord(), model);
recordId = new ORecordId("#6:1");
model.setObject((ODocument) recordId.getRecord());
assertModelObjectEquals(recordId.getRecord(), model);
model.setObject(null);
assertModelObjectEquals(null, model);
// Test persistence between calls
db.begin();
ODocument doc = new ODocument("ClassA");
doc.field("name", "test1");
model = new ODocumentModel(doc);
assertEquals("test1", model.getObject().field("name"));
interupt(db, model);
assertEquals("test1", model.getObject().field("name"));
model.getObject().save();
interupt(db, model);
// Test that document actually reloaded from DB after closing transaction
assertEquals("test1", model.getObject().field("name"));
model.getObject().field("name", "test2");
assertEquals("test2", model.getObject().field("name"));
interupt(db, model);
assertEquals("test1", model.getObject().field("name"));
// Test autoSave feature
model.getObject().field("name", "test3");
model.setAutoSave(true);
interupt(db, model);
assertEquals("test3", model.getObject().field("name"));
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class OrientDBSettingsTest method testInstallingHooks.
@Test
public void testInstallingHooks() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OClass clazz = db.getMetadata().getSchema().getClass("TestHooks");
assertNotNull(clazz);
try (OResultSet result = db.query("select from TestHooks")) {
assertTrue(result.hasNext());
ODocument doc = (ODocument) result.next().getElement().orElse(null);
assertNotNull(doc);
assertEquals("HOOK", doc.field("name"));
}
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestRegisterHooks method testRegisterHooks.
@Test
public void testRegisterHooks() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
IOrientDbSettings settings = wicket.getTester().getApplication().getOrientDbSettings();
settings.addORecordHooks(RegisterHook.class);
assertRegisteredHook(db, RegisterHook.class);
db = wicket.getTester().getDatabaseSession();
assertRegisteredHook(db, RegisterHook.class);
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testInHook.
@Test
public void testInHook() throws Exception {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass oClass = schema.createClass("TestInHook");
oClass.createProperty("a", OType.INTEGER);
oClass.createProperty("b", OType.INTEGER);
oClass.createProperty("c", OType.INTEGER);
ODocument doc = new ODocument(oClass);
doc.field("a", 2);
doc.field("b", 2);
doc.save();
doc.reload();
assertEquals(2, (Object) doc.field("a"));
assertEquals(2, (Object) doc.field("b"));
assertNull(doc.field("c"));
db.registerHook(new ODocumentHookAbstract(db) {
{
setIncludeClasses("TestInHook");
}
@Override
public void onRecordAfterCreate(ODocument iDocument) {
onRecordAfterRead(iDocument);
}
@Override
public void onRecordAfterRead(ODocument iDocument) {
String script = "select sum(a, b) as value from " + iDocument.getIdentity();
try (OResultSet result = database.query(script)) {
if (result.hasNext()) {
iDocument.field("c", (Object) result.next().getProperty("value"));
}
}
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
doc.reload();
assertEquals(2, (Object) doc.field("a"));
assertEquals(2, (Object) doc.field("b"));
assertEquals(4, (Object) doc.field("c"));
doc = new ODocument(oClass);
doc.field("a", 3);
doc.field("b", 3);
doc.save();
doc.reload();
assertEquals(3, (Object) doc.field("a"));
assertEquals(3, (Object) doc.field("b"));
assertEquals(6, (Object) doc.field("c"));
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testOFunctions.
@Test
public void testOFunctions() throws Exception {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
ODocument doc = new ODocument(OFunction.CLASS_NAME);
doc.field("name", "testResurection");
doc.field("language", "JavaScript");
doc.field("idempotent", true);
doc.save();
ORID orid = doc.getIdentity();
for (int i = 0; i < 10; i++) {
db = wicket.getTester().getDatabaseSession();
String signature = "signature" + RANDOM.nextLong();
boolean isGoodCall = (i + 1) % 3 != 0;
db.begin();
doc = orid.getRecord();
String code = isGoodCall ? "return \"" + signature + "\";" : "return nosuchvar;";
doc.field("code", code);
doc.save();
db.commit();
db.close();
if (isGoodCall) {
String result;
for (int j = 0; j < 3; j++) {
result = wicket.getTester().executeUrl("orientdb/function/db/testResurection", "GET", null);
assertContains(signature, result);
}
} else {
try {
wicket.getTester().executeUrl("orientdb/function/db/testResurection", "GET", null);
assertFalse("We should be there, because function should have 400 response", true);
} catch (Exception e) {
// NOP
}
}
}
}
Aggregations