Search in sources :

Example 16 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class ObjectTreeTestSchemaFull method iteratorShouldTerminate.

@Test
public void iteratorShouldTerminate() {
    OObjectDatabaseTx db = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    try {
        db.getEntityManager().registerEntityClass(Profile.class);
        db.begin();
        Profile person = new Profile();
        person.setNick("Guy1");
        person.setName("Guy");
        person.setSurname("Ritchie");
        person = db.save(person);
        db.commit();
        db.begin();
        db.delete(person);
        db.commit();
        db.begin();
        Profile person2 = new Profile();
        person2.setNick("Guy2");
        person2.setName("Guy");
        person2.setSurname("Brush");
        person2 = db.save(person2);
        OObjectIteratorClass<Profile> it = db.browseClass(Profile.class);
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        db.commit();
    } finally {
        db.close();
    }
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test)

Example 17 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class ObjectTreeTestSchemaFull method childMapUpdateTest.

@Test(dependsOnMethods = "childNLevelUpdateTest")
public void childMapUpdateTest() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    Planet p = database.newInstance(Planet.class);
    p.setName("Earth");
    p.setDistanceSun(1000);
    Satellite sat = database.newInstance(Satellite.class);
    sat.setDiameter(50);
    sat.setName("Moon");
    p.addSatelliteMap(sat);
    database.save(p);
    Assert.assertEquals(p.getDistanceSun(), 1000);
    Assert.assertEquals(p.getName(), "Earth");
    ORID rid = database.getIdentity(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.load(rid);
    sat = p.getSatellitesMap().get("Moon");
    Assert.assertEquals(p.getDistanceSun(), 1000);
    Assert.assertEquals(p.getName(), "Earth");
    Assert.assertEquals(sat.getDiameter(), 50);
    sat.setDiameter(500);
    database.save(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.load(rid);
    sat = p.getSatellitesMap().get("Moon");
    Assert.assertEquals(sat.getDiameter(), 500);
    Assert.assertEquals(p.getDistanceSun(), 1000);
    Assert.assertEquals(p.getName(), "Earth");
    database.close();
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) Satellite(com.orientechnologies.orient.test.domain.base.Satellite) Planet(com.orientechnologies.orient.test.domain.base.Planet) ORID(com.orientechnologies.orient.core.id.ORID) Test(org.testng.annotations.Test)

Example 18 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class BaseTest method createBasicTestSchema.

protected void createBasicTestSchema() {
    ODatabase database = this.database;
    if (database instanceof OObjectDatabaseTx)
        database = ((OObjectDatabaseTx) database).getUnderlying();
    if (database.getMetadata().getSchema().existsClass("Whiz"))
        return;
    database.addCluster("csv");
    database.addCluster("flat");
    database.addCluster("binary");
    //    database.addBlobCluster("blobCluster");
    OClass account = database.getMetadata().getSchema().createClass("Account", 1, null);
    account.createProperty("id", OType.INTEGER);
    account.createProperty("birthDate", OType.DATE);
    account.createProperty("binary", OType.BINARY);
    database.getMetadata().getSchema().createClass("Company", account);
    OClass profile = database.getMetadata().getSchema().createClass("Profile", 1, null);
    profile.createProperty("nick", OType.STRING).setMin("3").setMax("30").createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
    profile.createProperty("name", OType.STRING).setMin("3").setMax("30").createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    profile.createProperty("surname", OType.STRING).setMin("3").setMax("30");
    profile.createProperty("registeredOn", OType.DATETIME).setMin("2010-01-01 00:00:00");
    profile.createProperty("lastAccessOn", OType.DATETIME).setMin("2010-01-01 00:00:00");
    profile.createProperty("photo", OType.TRANSIENT);
    OClass whiz = database.getMetadata().getSchema().createClass("Whiz", 1, null);
    whiz.createProperty("id", OType.INTEGER);
    whiz.createProperty("account", OType.LINK, account);
    whiz.createProperty("date", OType.DATE).setMin("2010-01-01");
    whiz.createProperty("text", OType.STRING).setMandatory(true).setMin("1").setMax("140").createIndex(OClass.INDEX_TYPE.FULLTEXT);
    whiz.createProperty("replyTo", OType.LINK, account);
    OClass strictTest = database.getMetadata().getSchema().createClass("StrictTest", 1, null);
    strictTest.setStrictMode(true);
    strictTest.createProperty("id", OType.INTEGER).isMandatory();
    strictTest.createProperty("name", OType.STRING);
    OClass animalRace = database.getMetadata().getSchema().createClass("AnimalRace", 1, null);
    animalRace.createProperty("name", OType.STRING);
    OClass animal = database.getMetadata().getSchema().createClass("Animal", 1, null);
    animal.createProperty("races", OType.LINKSET, animalRace);
    animal.createProperty("name", OType.STRING);
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabase(com.orientechnologies.orient.core.db.ODatabase) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 19 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class CRUDObjectInheritanceTestSchemaFull method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    database.close();
    database = new OObjectDatabaseTx(url + "_objectschema");
    ODatabaseHelper.dropDatabase(database, getStorageType());
    ODatabaseHelper.createDatabase(database, url + "_objectschema", getStorageType());
    try {
        ODatabaseDocumentTx exportDatabase = new ODatabaseDocumentTx(url);
        exportDatabase.open("admin", "admin");
        OCommandOutputListener listener = new OCommandOutputListener() {

            @Override
            public void onMessage(String iText) {
            }
        };
        ODatabaseExport export = new ODatabaseExport(exportDatabase, EXPORT_DIR, listener);
        export.exportDatabase();
        export.close();
        exportDatabase.close();
        ODatabaseDocumentTx importDatabase = new ODatabaseDocumentTx(url + "_objectschema");
        if (url.startsWith("remote")) {
            importDatabase.open("root", ODatabaseHelper.getServerRootPassword());
        } else {
            importDatabase.open("admin", "admin");
        }
        ODatabaseImport impor = new ODatabaseImport(importDatabase, EXPORT_DIR, listener);
        // UNREGISTER ALL THE HOOKS
        for (ORecordHook hook : new ArrayList<ORecordHook>(importDatabase.getHooks().keySet())) {
            importDatabase.unregisterHook(hook);
        }
        impor.setDeleteRIDMapping(true);
        impor.importDatabase();
        impor.close();
        importDatabase.close();
        final File importDir = new File(EXPORT_DIR);
        importDir.delete();
    } catch (IOException e) {
        Assert.fail("Export import didn't go as expected", e);
    }
    database.open("admin", "admin");
    if (database.getMetadata().getSchema().existsClass("Company"))
        database.command(new OCommandSQL("delete from Company")).execute();
    if (database.getMetadata().getSchema().existsClass("Account"))
        database.command(new OCommandSQL("delete from Account")).execute();
    if (database.getMetadata().getSchema().existsClass("JavaComplexTestClass"))
        database.command(new OCommandSQL("delete from JavaComplexTestClass")).execute();
    if (database.getMetadata().getSchema().existsClass("Profile"))
        database.command(new OCommandSQL("delete from Profile")).execute();
    if (database.getMetadata().getSchema().existsClass("IdentityChild"))
        database.command(new OCommandSQL("delete from IdentityChild")).execute();
    database.close();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) IOException(java.io.IOException) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) File(java.io.File) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) BeforeClass(org.testng.annotations.BeforeClass)

Example 20 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class ObjectDetachingTest method testNonProxiedAttachDetach.

public void testNonProxiedAttachDetach() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");
    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);
    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);
    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);
    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());
    JavaAttachDetachTestClass savedJavaObj = database.save(attach);
    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();
    database = new OObjectDatabaseTx(url).open("admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    loadedJavaObj = database.detach(loadedJavaObj, true);
    Assert.assertTrue(!(loadedJavaObj instanceof Proxy));
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
    Assert.assertEquals(loadedJavaObj.floatSimple, 123.45f);
    Assert.assertEquals(loadedJavaObj.longSimple, 12345678l);
    Assert.assertEquals(loadedJavaObj.byteSimple, (byte) 1);
    Assert.assertEquals(loadedJavaObj.flagSimple, true);
    Assert.assertEquals(loadedJavaObj.enumeration, EnumTest.ENUM1);
    Assert.assertEquals(loadedJavaObj.enumList.size(), 2);
    Assert.assertEquals(loadedJavaObj.enumList.get(0), EnumTest.ENUM1);
    Assert.assertEquals(loadedJavaObj.enumList.get(1), EnumTest.ENUM2);
    Assert.assertEquals(loadedJavaObj.enumSet.size(), 2);
    it = loadedJavaObj.enumSet.iterator();
    EnumTest next = (EnumTest) it.next();
    Assert.assertTrue(next.equals(EnumTest.ENUM1) || next.equals(EnumTest.ENUM3));
    next = (EnumTest) it.next();
    Assert.assertTrue(next.equals(EnumTest.ENUM1) || next.equals(EnumTest.ENUM3));
    ;
    Assert.assertEquals(loadedJavaObj.enumMap.size(), 2);
    Assert.assertEquals(loadedJavaObj.enumMap.get("1"), EnumTest.ENUM2);
    Assert.assertEquals(loadedJavaObj.enumMap.get("2"), EnumTest.ENUM3);
    ODocument serializedDoc = database.getRecordByUserObject(loadedJavaObj, false);
    Assert.assertTrue(serializedDoc.equals(doc));
    Assert.assertTrue(serializedDoc.hasSameContentOf(doc));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Proxy(javassist.util.proxy.Proxy) JavaAttachDetachTestClass(com.orientechnologies.orient.test.domain.base.JavaAttachDetachTestClass) Child(com.orientechnologies.orient.test.domain.business.Child) LazyChild(com.orientechnologies.orient.test.domain.lazy.LazyChild) CycleChild(com.orientechnologies.orient.test.domain.cycle.CycleChild) GrandChild(com.orientechnologies.orient.test.domain.cycle.GrandChild) HashMap(java.util.HashMap) Map(java.util.Map) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)48 Test (org.testng.annotations.Test)25 ORID (com.orientechnologies.orient.core.id.ORID)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 Map (java.util.Map)9 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 EnumTest (com.orientechnologies.orient.test.domain.base.EnumTest)8 JavaAttachDetachTestClass (com.orientechnologies.orient.test.domain.base.JavaAttachDetachTestClass)8 Planet (com.orientechnologies.orient.test.domain.base.Planet)8 Satellite (com.orientechnologies.orient.test.domain.base.Satellite)8 Child (com.orientechnologies.orient.test.domain.business.Child)8 Set (java.util.Set)8 ArrayList (java.util.ArrayList)5 Proxy (javassist.util.proxy.Proxy)5 BeforeClass (org.testng.annotations.BeforeClass)5 CycleChild (com.orientechnologies.orient.test.domain.cycle.CycleChild)4 GrandChild (com.orientechnologies.orient.test.domain.cycle.GrandChild)4 LazyChild (com.orientechnologies.orient.test.domain.lazy.LazyChild)4