Search in sources :

Example 26 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTest method mapObjectsLinkUpdateDatabaseNewInstanceTest.

@Test(dependsOnMethods = "mapObjectsLinkTest")
public void mapObjectsLinkUpdateDatabaseNewInstanceTest() {
    // TEST WITH NEW INSTANCE
    JavaComplexTestClass p = database.newInstance(JavaComplexTestClass.class);
    p.setName("Fringe");
    Child c = database.newInstance(Child.class);
    c.setName("Peter");
    Child c1 = database.newInstance(Child.class);
    c1.setName("Walter");
    Child c2 = database.newInstance(Child.class);
    c2.setName("Olivia");
    Child c3 = database.newInstance(Child.class);
    c3.setName("Astrid");
    p.getChildren().put(c.getName(), c);
    p.getChildren().put(c1.getName(), c1);
    p.getChildren().put(c2.getName(), c2);
    p.getChildren().put(c3.getName(), c3);
    // database.begin();
    database.save(p);
    // database.commit();
    ORID rid = new ORecordId(p.getId());
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaComplexTestClass loaded = database.load(rid);
    for (String key : loaded.getChildren().keySet()) {
        Assert.assertTrue(key.equals("Peter") || key.equals("Walter") || key.equals("Olivia") || key.equals("Astrid"));
        Assert.assertTrue(loaded.getChildren().get(key) instanceof Child);
        Assert.assertTrue(loaded.getChildren().get(key).getName().equals(key));
        if (key.equals("Peter")) {
            Assert.assertTrue(loaded.getChildren().get(key).getName().equals("Peter"));
        } else if (key.equals("Walter")) {
            Assert.assertTrue(loaded.getChildren().get(key).getName().equals("Walter"));
        } else if (key.equals("Olivia")) {
            Assert.assertTrue(loaded.getChildren().get(key).getName().equals("Olivia"));
        } else if (key.equals("Astrid")) {
            Assert.assertTrue(loaded.getChildren().get(key).getName().equals("Astrid"));
        }
    }
    database.setLazyLoading(false);
    for (JavaComplexTestClass reloaded : database.browseClass(JavaComplexTestClass.class).setFetchPlan("*:-1")) {
        database.reload(reloaded);
        Child c4 = database.newInstance(Child.class);
        c4.setName("The Observer");
        reloaded.getChildren().put(c4.getName(), c4);
        database.save(reloaded);
    }
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    for (JavaComplexTestClass reloaded : database.browseClass(JavaComplexTestClass.class).setFetchPlan("*:-1")) {
        database.reload(reloaded);
        Assert.assertTrue(reloaded.getChildren().containsKey("The Observer"));
        Assert.assertTrue(reloaded.getChildren().get("The Observer") != null);
        Assert.assertEquals(reloaded.getChildren().get("The Observer").getName(), "The Observer");
        Assert.assertTrue(database.getIdentity(reloaded.getChildren().get("The Observer")).isPersistent() && database.getIdentity(reloaded.getChildren().get("The Observer")).isValid());
    }
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) Child(com.orientechnologies.orient.test.domain.business.Child) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 27 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTest method queryWithRidAsParameters.

@Test
public void queryWithRidAsParameters() {
    database.getMetadata().getSchema().reload();
    Profile profile = (Profile) database.browseClass("Profile").next();
    final OSQLSynchQuery<Profile> query = new OSQLSynchQuery<Profile>("select from Profile where @rid = ?");
    List<Profile> result = database.query(query, new ORecordId(profile.getId()));
    Assert.assertEquals(result.size(), 1);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 28 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class CRUDObjectPhysicalTest method mapObjectsListEmbeddedTest.

@Test(dependsOnMethods = "listObjectsIterationTest")
public void mapObjectsListEmbeddedTest() {
    List<Child> cresult = database.query(new OSQLSynchQuery<Child>("select * from Child"));
    int childSize = cresult.size();
    JavaComplexTestClass p = database.newInstance(JavaComplexTestClass.class);
    p.setName("Silvester");
    Child c = database.newInstance(Child.class);
    c.setName("John");
    Child c1 = database.newInstance(Child.class);
    c1.setName("Jack");
    Child c2 = database.newInstance(Child.class);
    c2.setName("Bob");
    Child c3 = database.newInstance(Child.class);
    c3.setName("Sam");
    Child c4 = database.newInstance(Child.class);
    c4.setName("Dean");
    p.getEmbeddedList().add(c1);
    p.getEmbeddedList().add(c2);
    p.getEmbeddedList().add(c3);
    p.getEmbeddedList().add(c4);
    database.save(p);
    cresult = database.query(new OSQLSynchQuery<Child>("select * from Child"));
    Assert.assertTrue(cresult.size() == childSize);
    ORID rid = new ORecordId(p.getId());
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaComplexTestClass loaded = database.load(rid);
    Assert.assertEquals(loaded.getEmbeddedList().size(), 4);
    Assert.assertTrue(database.getRecordByUserObject(loaded.getEmbeddedList().get(0), false).isEmbedded());
    Assert.assertTrue(database.getRecordByUserObject(loaded.getEmbeddedList().get(1), false).isEmbedded());
    Assert.assertTrue(database.getRecordByUserObject(loaded.getEmbeddedList().get(2), false).isEmbedded());
    Assert.assertTrue(database.getRecordByUserObject(loaded.getEmbeddedList().get(3), false).isEmbedded());
    Assert.assertTrue(loaded.getEmbeddedList().get(0) instanceof Child);
    Assert.assertTrue(loaded.getEmbeddedList().get(1) instanceof Child);
    Assert.assertTrue(loaded.getEmbeddedList().get(2) instanceof Child);
    Assert.assertTrue(loaded.getEmbeddedList().get(3) instanceof Child);
    Assert.assertEquals(loaded.getEmbeddedList().get(0).getName(), "Jack");
    Assert.assertEquals(loaded.getEmbeddedList().get(1).getName(), "Bob");
    Assert.assertEquals(loaded.getEmbeddedList().get(2).getName(), "Sam");
    Assert.assertEquals(loaded.getEmbeddedList().get(3).getName(), "Dean");
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ORID(com.orientechnologies.orient.core.id.ORID) Child(com.orientechnologies.orient.test.domain.business.Child) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 29 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class CRUDDocumentPhysicalTest method testInvalidFetchplanLoad.

@Test
public void testInvalidFetchplanLoad() {
    ODocument doc = database.newInstance();
    doc.field("test", "test");
    doc.save();
    ORID docRid = doc.getIdentity().copy();
    try {
        // RELOAD THE DOCUMENT, THIS WILL PUT IT IN L1 CACHE
        doc = database.load(docRid, "*:-1");
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, docRid);
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(1, 0));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(1, 1));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(1, 2));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(2, 0));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(2, 1));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(2, 2));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(3, 0));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(3, 1));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(3, 2));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(4, 0));
        doc = testInvalidFetchPlanInvalidateL1Cache(doc, new ORecordId(4, 1));
    // CLOSE DB AND RE-TEST THE LOAD TO MAKE SURE
    } finally {
        database.close();
    }
    database.open("admin", "admin");
    doc = testInvalidFetchPlanClearL1Cache(doc, docRid);
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(1, 0));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(1, 1));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(1, 2));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(2, 0));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(2, 1));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(2, 2));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(3, 0));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(3, 1));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(3, 2));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(4, 0));
    doc = testInvalidFetchPlanClearL1Cache(doc, new ORecordId(4, 1));
    doc = database.load(docRid);
    doc.delete();
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 30 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class CRUDDocumentPhysicalTest method testNestedEmbeddedMap.

@SuppressWarnings("unchecked")
@Test
public void testNestedEmbeddedMap() {
    ODocument newDoc = new ODocument();
    final Map<String, HashMap<?, ?>> map1 = new HashMap<String, HashMap<?, ?>>();
    newDoc.field("map1", map1, OType.EMBEDDEDMAP);
    final Map<String, HashMap<?, ?>> map2 = new HashMap<String, HashMap<?, ?>>();
    map1.put("map2", (HashMap<?, ?>) map2);
    final Map<String, HashMap<?, ?>> map3 = new HashMap<String, HashMap<?, ?>>();
    map2.put("map3", (HashMap<?, ?>) map3);
    final ORecordId rid = (ORecordId) newDoc.save().getIdentity();
    final ODocument loadedDoc = database.load(rid);
    Assert.assertTrue(newDoc.hasSameContentOf(loadedDoc));
    Assert.assertTrue(loadedDoc.containsField("map1"));
    Assert.assertTrue(loadedDoc.field("map1") instanceof Map<?, ?>);
    final Map<String, ODocument> loadedMap1 = loadedDoc.field("map1");
    Assert.assertEquals(loadedMap1.size(), 1);
    Assert.assertTrue(loadedMap1.containsKey("map2"));
    Assert.assertTrue(loadedMap1.get("map2") instanceof Map<?, ?>);
    final Map<String, ODocument> loadedMap2 = (Map<String, ODocument>) loadedMap1.get("map2");
    Assert.assertEquals(loadedMap2.size(), 1);
    Assert.assertTrue(loadedMap2.containsKey("map3"));
    Assert.assertTrue(loadedMap2.get("map3") instanceof Map<?, ?>);
    final Map<String, ODocument> loadedMap3 = (Map<String, ODocument>) loadedMap2.get("map3");
    Assert.assertEquals(loadedMap3.size(), 0);
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

ORecordId (com.orientechnologies.orient.core.id.ORecordId)431 Test (org.testng.annotations.Test)153 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)139 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)120 ORID (com.orientechnologies.orient.core.id.ORID)71 HashSet (java.util.HashSet)63 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)42 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)37 ORecord (com.orientechnologies.orient.core.record.ORecord)37 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)34 OIndexTxAwareMultiValue (com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue)30 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)30 HashMap (java.util.HashMap)29 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)28 IOException (java.io.IOException)25 Child (com.orientechnologies.orient.test.domain.business.Child)24 OException (com.orientechnologies.common.exception.OException)23 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)23 Map (java.util.Map)22 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)21