use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testValidationAndHooksOrder.
@Test
@Ignore
public void testValidationAndHooksOrder() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass(TEST_VALIDATION_AND_HOOKS_CLASS);
classA.createProperty("property1", OType.STRING).setNotNull(true);
classA.createProperty("property2", OType.STRING).setReadonly(true);
classA.createProperty("property3", OType.STRING).setMandatory(true);
db.registerHook(new ODocumentHookAbstract(db) {
@Override
public RESULT onRecordBeforeCreate(ODocument doc) {
doc.field("property1", "value1-create");
doc.field("property2", "value2-create");
doc.field("property3", "value3-create");
return RESULT.RECORD_CHANGED;
}
@Override
public RESULT onRecordBeforeUpdate(ODocument doc) {
doc.undo("property2");
if (doc.field("property3") == null)
doc.field("property3", "value3-update");
return RESULT.RECORD_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
ODocument doc = new ODocument(classA);
// doc.field("property3", "value3-create"); //Magic line #1
doc.save();
assertEquals("value1-create", doc.field("property1"));
assertEquals("value2-create", doc.field("property2"));
assertEquals("value3-create", doc.field("property3"));
doc.field("property1", "value1-update");
doc.field("property2", "value2-update");
doc.removeField("property3");
// doc.undo("property2"); //Magic line #2
// doc.field("property3", "value3-update"); //Magic line #3
doc.save();
assertEquals("value1-update", doc.field("property1"));
assertEquals("value2-create", doc.field("property2"));
assertEquals("value3-update", doc.field("property3"));
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testUpdatesInHooks.
@Test
@Ignore
public void testUpdatesInHooks() {
final String className = "TestUpdatesInHook";
ODatabaseSession db = wicket.getTester().getDatabaseSession();
db.registerHook(new ODocumentHookAbstract(db) {
{
setIncludeClasses(className);
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
@Override
public RESULT onRecordBeforeCreate(ODocument iDocument) {
return onRecordBeforeUpdate(iDocument);
}
@Override
public RESULT onRecordBeforeUpdate(ODocument iDocument) {
iDocument.undo("b");
return RESULT.RECORD_CHANGED;
}
@Override
public void onRecordAfterCreate(ODocument iDocument) {
onRecordAfterUpdate(iDocument);
}
@Override
public void onRecordAfterUpdate(ODocument iDocument) {
onRecordAfterRead(iDocument);
}
@Override
public void onRecordAfterRead(ODocument iDocument) {
if (!iDocument.containsField("b"))
iDocument.field("b", (Object) iDocument.field("a"));
}
});
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass(className);
classA.createProperty("a", OType.STRING);
classA.createProperty("b", OType.STRING);
db.commit();
ODocument doc = new ODocument(classA);
/*doc.field("a", "test1");
doc.save();
doc.reload();
assertEquals(doc.field("a"), doc.field("b"));
doc.field("a", "test2");
doc.save();
doc.reload();
assertEquals(doc.field("a"), doc.field("b"));*/
db.begin();
doc.field("a", "test3");
doc.save();
doc.reload();
// doc = db.reload(doc, null, true);
assertEquals((Object) doc.field("a"), (Object) doc.field("b"));
doc.field("a", "test4");
doc.save();
doc.reload();
// doc = db.reload(doc, null, true);
assertEquals((Object) doc.field("a"), (Object) doc.field("b"));
db.commit();
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testLoosingLinkedClass.
@Test
@Ignore
public void testLoosingLinkedClass() throws Exception {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = wicket.getTester().getSchema();
OClass mainClass = schema.createClass("LMainClass");
OClass embeddedClass = schema.createClass("LEmbeddedClass");
mainClass.createProperty("name", OType.STRING);
mainClass.createProperty("embedded", OType.EMBEDDED).setLinkedClass(embeddedClass);
embeddedClass.createProperty("name", OType.STRING);
db.begin();
ODocument main = new ODocument(mainClass);
main.field("name", "main");
ODocument embedded = new ODocument(embeddedClass);
// embedded.field("name", "embedded");
main.field("embedded", embedded);
// NO Save here!
db.commit();
db.close();
main.fromStream(main.toStream());
db = wicket.getTester().getDatabaseSession();
db.begin();
assertEmbeddedIsCorrect(main);
main.save();
ORID recordId = main.getIdentity();
db.commit();
db.close();
db = wicket.getTester().getDatabaseSession();
db.begin();
main = recordId.getRecord();
assertEmbeddedIsCorrect(main);
db.commit();
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testClassChange.
@Test
@Ignore
public void testClassChange() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TestClassChangeA");
OClass classB = schema.createClass("TestClassChangeB");
ODocument doc = new ODocument(classA);
doc.save();
doc = doc.getIdentity().getRecord();
doc.setClassName(classB.getName());
assertEquals(classB.getName(), doc.getClassName());
doc = doc.getIdentity().getRecord();
assertEquals(classB.getName(), doc.getClassName());
ORID id = doc.getIdentity();
db.commit(true);
db.close();
db = wicket.getTester().getDatabaseSession();
doc = id.getRecord();
assertEquals(classB.getName(), doc.getClassName());
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class OrientDbWebSession method authenticate.
@Override
public boolean authenticate(String username, String password) {
ODatabaseSession currentDB = getDatabaseSession();
try {
boolean inTransaction = currentDB.getTransaction().isActive();
IOrientDbSettings settings = OrientDbWebApplication.get().getOrientDbSettings();
ODatabaseSession newDB = settings.getContext().cachedPool(settings.getDbName(), username, password).acquire();
if (newDB != currentDB) {
currentDB.activateOnCurrentThread();
currentDB.commit();
currentDB.close();
newDB.activateOnCurrentThread();
}
setUser(username, password);
userModel.setObject(newDB.getUser().getDocument());
if (inTransaction && !newDB.getTransaction().isActive()) {
newDB.begin();
}
return true;
} catch (OSecurityAccessException e) {
currentDB.activateOnCurrentThread();
return false;
}
}
Aggregations