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());
}
}
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);
}
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");
}
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();
}
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);
}
Aggregations