Search in sources :

Example 16 with ODatabaseSession

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();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORID(com.orientechnologies.orient.core.id.ORID) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with ODatabaseSession

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();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 18 with ODatabaseSession

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();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODocumentHookAbstract(com.orientechnologies.orient.core.hook.ODocumentHookAbstract) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with ODatabaseSession

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()));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with ODatabaseSession

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();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ODatabaseSession (com.orientechnologies.orient.core.db.ODatabaseSession)31 Test (org.junit.Test)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)21 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)19 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)17 Ignore (org.junit.Ignore)10 ORID (com.orientechnologies.orient.core.id.ORID)6 ODocumentHookAbstract (com.orientechnologies.orient.core.hook.ODocumentHookAbstract)5 OResultSet (com.orientechnologies.orient.core.sql.executor.OResultSet)4 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)3 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OSchemaHelper (ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper)2 Function (com.google.common.base.Function)1 Maps (com.google.common.collect.Maps)1 OResettable (com.orientechnologies.common.util.OResettable)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseRecordThreadLocal (com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal)1 OrientDB (com.orientechnologies.orient.core.db.OrientDB)1