Search in sources :

Example 1 with ORID

use of com.orientechnologies.orient.core.id.ORID in project jphp by jphp-compiler.

the class ODocument method getId.

@Getter
public String getId() {
    ORID identity = getWrappedObject().getIdentity();
    if (identity.isNew()) {
        return null;
    }
    StringBuilder buffer = new StringBuilder();
    return identity.toString(buffer).toString();
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) Getter(php.runtime.annotation.Reflection.Getter)

Example 2 with ORID

use of com.orientechnologies.orient.core.id.ORID in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testTransactions.

@Test
public void testTransactions() throws Exception {
    ODatabaseDocument db = wicket.getTester().getDatabase();
    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) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 3 with ORID

use of com.orientechnologies.orient.core.id.ORID in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testOFunctions.

@Test
public void testOFunctions() throws Exception {
    ODatabaseDocument db = wicket.getTester().getDatabase();
    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().getDatabase();
        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
            }
        }
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORID(com.orientechnologies.orient.core.id.ORID) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 4 with ORID

use of com.orientechnologies.orient.core.id.ORID 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() {
    ODatabaseDocument db = wicket.getTester().getDatabase();
    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("#5:0");
    ODocument doc = new ODocument(classA);
    wicket.getTester().signIn("writer", "writer");
    db = wicket.getTester().getDatabase();
    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) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORID(com.orientechnologies.orient.core.id.ORID) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with ORID

use of com.orientechnologies.orient.core.id.ORID in project wicket-orientdb by OrienteerBAP.

the class TestRestApi method testGetDocument.

@Test
public void testGetDocument() throws Exception {
    ODocument doc = (ODocument) wicket.getTester().getDatabase().browseClass(TEST_REST_CLASS).current();
    ORID id = doc.getIdentity();
    String ret = wicket.getTester().executeUrl("orientdb/document/db/" + id.getClusterId() + ":" + id.getClusterPosition(), "GET", null);
    assertEquals(doc.toJSON(), ret);
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ORID (com.orientechnologies.orient.core.id.ORID)391 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)215 Test (org.testng.annotations.Test)123 ORecordId (com.orientechnologies.orient.core.id.ORecordId)77 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)65 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)60 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)40 HashMap (java.util.HashMap)39 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)36 Child (com.orientechnologies.orient.test.domain.business.Child)36 Test (org.junit.Test)30 ORecord (com.orientechnologies.orient.core.record.ORecord)28 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)27 HashSet (java.util.HashSet)23 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)22 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)21 ArrayList (java.util.ArrayList)19 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)17 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)14 IdentityChild (com.orientechnologies.orient.test.domain.business.IdentityChild)12