use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testTransactions2.
@Test
@Ignore
public void testTransactions2() throws Exception {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
try {
assertFalse(db.getTransaction().isActive());
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TransB");
classA.createProperty("name", OType.STRING);
ODocument doc = new ODocument(classA);
doc.field("name", "test1");
doc.save();
ORID orid = doc.getIdentity();
db.begin();
assertTrue(db.getTransaction().isActive());
doc = orid.getRecord();
assertEquals("test1", doc.field("name"));
doc.field("name", "test2");
doc.save();
doc = orid.getRecord();
assertEquals("test2", doc.field("name"));
doc.field("name", "test3");
assertEquals("test3", doc.field("name"));
// There is NO SAVE!
db.commit();
db.getLocalCache().clear();
/* COMMENT START */
// db.close();
// db = wicket.getTester().getDatabase();
/* COMMENT STOP */
doc = orid.getRecord();
assertEquals("test2", doc.field("name"));
} finally {
db.commit();
}
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testRemovingReadonlyField2.
@Test
public void testRemovingReadonlyField2() {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TestRemovingField2");
classA.createProperty("name", OType.STRING);
OProperty property = classA.createProperty("property", OType.STRING);
property.setReadonly(true);
ODocument doc = new ODocument(classA);
doc.field("name", "My Name");
doc.field("property", "value1");
doc.save();
doc.field("name", "My Name 2");
doc.field("property", "value2");
doc.undo();
doc.field("name", "My Name 3");
doc.save();
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testDocumentTrackingComplex.
@Test
@Ignore
public void testDocumentTrackingComplex() {
final String className = "TestDocumentTrackingComplex";
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
final OClass classA = schema.createClass(className);
classA.createProperty("a", OType.STRING);
classA.createProperty("b", OType.STRING);
db.registerHook(new ODocumentHookAbstract(db) {
{
setIncludeClasses(className);
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
@Override
public void onRecordAfterCreate(ODocument iDocument) {
System.out.println("onRecordAfterCreate");
iDocument.field("a", "onRecordAfterCreate");
}
@Override
public void onRecordAfterUpdate(ODocument iDocument) {
System.out.println("onRecordAfterUpdate");
iDocument.field("a", "onRecordAfterUpdate");
}
@Override
public RESULT onRecordBeforeUpdate(ODocument iDocument) {
System.out.println("onRecordAfterUpdate before undo: " + iDocument.field("a"));
iDocument.undo("a");
System.out.println("onRecordAfterUpdate after undo: " + iDocument.field("a"));
return RESULT.RECORD_CHANGED;
}
@Override
public void onRecordAfterRead(ODocument iDocument) {
assertEquals("original", iDocument.field("a"));
}
});
db.commit();
ODocument doc = new ODocument(classA);
doc.field("a", "original");
doc.save();
doc.field("b", "other change");
doc.save();
doc.reload();
doc.field("a", "updated");
doc.save();
doc.field("b", "other change");
doc.save();
doc.reload();
doc.delete();
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testSerialization.
@Test
@Ignore
public void testSerialization() throws Exception {
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("SerA");
OClass classB = schema.createClass("SerB");
classA.createProperty("name", OType.STRING);
classB.createProperty("name", OType.STRING);
classA.createProperty("child", OType.LINKLIST, classB);
classB.createProperty("parent", OType.LINK, classA);
ODocument docA = new ODocument(classA);
docA.field("name", "Doc A");
doSerialization(docA);
assertEquals(0, db.countClass(docA.getClassName()));
ODocument docB = new ODocument(classB);
docB.field("name", "Doc B");
doSerialization(docB);
assertEquals(0, db.countClass(docB.getClassName()));
docA.field("child", Arrays.asList(docB));
doSerialization(docA);
assertEquals(0, db.countClass(docA.getClassName()));
assertEquals(0, db.countClass(docB.getClassName()));
doSerialization(docB);
assertEquals(0, db.countClass(docA.getClassName()));
assertEquals(0, db.countClass(docB.getClassName()));
docB.field("parent", Arrays.asList(docA));
doSerialization(docA);
assertEquals(0, db.countClass(docA.getClassName()));
assertEquals(0, db.countClass(docB.getClassName()));
doSerialization(docB);
assertEquals(0, db.countClass(docA.getClassName()));
assertEquals(0, db.countClass(docB.getClassName()));
}
use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testDocumentTrackingSimple.
@Test
public void testDocumentTrackingSimple() {
final String className = "TestDocumentTrackingSimple";
ODatabaseSession db = wicket.getTester().getDatabaseSession();
OSchema schema = db.getMetadata().getSchema();
final OClass classA = schema.createClass(className);
classA.createProperty("a", OType.STRING);
db.registerHook(new ORecordHook() {
@Override
public void onUnregister() {
// NOP
}
@Override
public RESULT onTrigger(TYPE iType, ORecord iRecord) {
if (iRecord instanceof ODocument) {
ODocument doc = (ODocument) iRecord;
if (classA.isSuperClassOf(doc.getSchemaClass())) {
// System.out.println("During "+iType+" document should track changes: "+doc.isTrackingChanges());
assertTrue("During " + iType + " document should track changes", doc.isTrackingChanges());
}
}
return RESULT.RECORD_NOT_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
db.commit();
ODocument doc = new ODocument(classA);
doc.field("a", "test");
doc.save();
doc.reload();
doc.field("a", "test2");
doc.save();
doc.reload();
doc.delete();
}
Aggregations