Search in sources :

Example 6 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testLinkListAndODocumentConversion.

@Test
@Ignore
public // TODO: Enable when https://github.com/orientechnologies/orientdb/issues/9421 will be in OrientDB
void testLinkListAndODocumentConversion() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchemaHelper helper = OSchemaHelper.bind(db);
    helper.oClass("TestODocumentConverstion").oProperty("name", OType.STRING).oProperty("items", OType.LINKLIST);
    ODocument mainDoc = helper.oDocument("name", "document").saveDocument().getODocument();
    helper.oClass("TestODocumentConverstionItems").oProperty("name", OType.STRING);
    ODocument doc1 = helper.oDocument("name", "item1").saveDocument().getODocument();
    ODocument doc2 = helper.oDocument("name", "item2").saveDocument().getODocument();
    ODocument doc3 = helper.oDocument("name", "item3").saveDocument().getODocument();
    List<ODocument> items = Arrays.asList(doc1, doc2, doc3);
    mainDoc.field("items", items);
    mainDoc.save();
    db.commit();
    db.begin();
    mainDoc = (ODocument) mainDoc.reload();
    items = mainDoc.field("items", List.class);
    Iterator<ODocument> it = items.iterator();
    it.next();
    if (it instanceof OResettable)
        ((OResettable) it).reset();
    assertTrue(items.get(0) instanceof ODocument);
    assertEquals(doc1, items.get(0));
    assertTrue(items.get(1) instanceof ODocument);
    assertEquals(doc2, items.get(1));
    assertTrue(items.get(2) instanceof ODocument);
    assertEquals(doc3, items.get(2));
    db.commit();
}
Also used : OSchemaHelper(ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper) OResettable(com.orientechnologies.common.util.OResettable) List(java.util.List) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testTransactions.

@Test
public void testTransactions() throws Exception {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    try {
        assertFalse(db.getTransaction().isActive());
        OSchema schema = db.getMetadata().getSchema();
        OClass classA = schema.createClass("TransA");
        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 = orid.getRecord();
        assertEquals("test2", 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("test1", 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) Test(org.junit.Test)

Example 8 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testPropertyRenaming.

@Test
public void testPropertyRenaming() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchema schema = db.getMetadata().getSchema();
    OClass classA = schema.createClass("TestPropertyRenaming");
    OProperty property = classA.createProperty("propertyOld", OType.STRING);
    assertEquals(property, classA.getProperty("propertyOld"));
    assertNull(classA.getProperty("propertyNew"));
    property.setName("propertyNew");
    schema.reload();
    classA = schema.getClass("TestPropertyRenaming");
    assertNull(classA.getProperty("propertyOld"));
    assertEquals(property, classA.getProperty("propertyNew"));
}
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) Test(org.junit.Test)

Example 9 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testDeletionOfDependentClass.

@Test
@Ignore
public void testDeletionOfDependentClass() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchema schema = db.getMetadata().getSchema();
    OClass oRestricted = schema.getClass(OSecurityShared.RESTRICTED_CLASSNAME);
    OClass classA = schema.createClass("TestDeletionOfDependentClassA", oRestricted);
    OClass classB = schema.createClass("TestDeletionOfDependentClassB", classA);
    schema.dropClass(classB.getName());
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testLinkToOUser.

// TODO: Uncomment when OrientDB issue will be fixed: https://github.com/orientechnologies/orientdb/issues/8067
@Ignore
@Test
public void testLinkToOUser() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchema schema = db.getMetadata().getSchema();
    final OClass classA = schema.createClass("TestLinkToOUser");
    classA.createProperty("name", OType.STRING);
    classA.createProperty("user", OType.LINK).setLinkedClass(schema.getClass("OUser"));
    ORID userRid = new ORecordId("#6:0");
    ODocument doc = new ODocument(classA);
    wicket.getTester().signIn("writer", "writer");
    db = wicket.getTester().getDatabaseSession();
    db.begin();
    ODocument userDoc = userRid.getRecord();
    userDoc.field("roles");
    doc.field("Admin");
    doc.field("user", userDoc);
    doc.save();
    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) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) 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