Search in sources :

Example 11 with OObjectDatabaseTx

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

the class ObjectTreeTest 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 12 with OObjectDatabaseTx

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

the class ObjectTreeTest method testEnumListWithCustomTypes.

@Test(dependsOnMethods = "testCustomTypesDatabaseNewInstance")
public void testEnumListWithCustomTypes() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    ORID rid = null;
    try {
        OObjectSerializerContext serializerContext = new OObjectSerializerContext();
        serializerContext.bind(new OObjectSerializer<SecurityRole, String>() {

            @Override
            public Object serializeFieldValue(Class<?> type, SecurityRole role) {
                return role.name();
            }

            @Override
            public Object unserializeFieldValue(Class<?> type, String str) {
                return SecurityRole.getByName(str);
            }
        }, database);
        OObjectSerializerHelper.bindSerializerContext(null, serializerContext);
        database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.customserialization");
        Sec s = new Sec();
        s.getSecurityRoleList().add(SecurityRole.LOGIN);
        Assert.assertTrue(s.getSecurityRoleList().contains(SecurityRole.LOGIN));
        s = database.save(s);
        rid = database.getRecordByUserObject(s, false).getIdentity();
        database.close();
        database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
        s = database.load(rid);
        Assert.assertTrue(s.getSecurityRoleList().contains(SecurityRole.LOGIN));
    } finally {
        database.close();
    }
}
Also used : Sec(com.orientechnologies.orient.test.domain.customserialization.Sec) OObjectSerializerContext(com.orientechnologies.orient.object.serialization.OObjectSerializerContext) SecurityRole(com.orientechnologies.orient.test.domain.customserialization.SecurityRole) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) OSchemaProxyObject(com.orientechnologies.orient.object.metadata.schema.OSchemaProxyObject) ORID(com.orientechnologies.orient.core.id.ORID) Test(org.testng.annotations.Test)

Example 13 with OObjectDatabaseTx

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

the class ObjectTreeTest 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 14 with OObjectDatabaseTx

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

the class ObjectTreeTestSchemaFull method childMapNLevelUpdateTest.

@Test(dependsOnMethods = "childMapUpdateTest")
public void childMapNLevelUpdateTest() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    Planet jupiter = database.newInstance(Planet.class);
    jupiter.setName("Jupiter");
    jupiter.setDistanceSun(3000);
    Planet mercury = database.newInstance(Planet.class);
    mercury.setName("Mercury");
    mercury.setDistanceSun(5000);
    Satellite jupiterMoon = database.newInstance(Satellite.class);
    Satellite mercuryMoon = database.newInstance(Satellite.class);
    jupiterMoon.setDiameter(50);
    jupiterMoon.setNear(mercury);
    jupiterMoon.setName("JupiterMoon");
    mercuryMoon.setDiameter(10);
    mercuryMoon.setName("MercuryMoon");
    mercury.addSatelliteMap(mercuryMoon);
    jupiter.addSatelliteMap(jupiterMoon);
    database.save(jupiter);
    ORID rid = database.getIdentity(jupiter);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    jupiter = database.load(rid);
    jupiterMoon = jupiter.getSatellitesMap().get("JupiterMoon");
    mercury = jupiterMoon.getNear();
    mercuryMoon = mercury.getSatellitesMap().get("MercuryMoon");
    Assert.assertEquals(mercuryMoon.getDiameter(), 10);
    Assert.assertEquals(mercuryMoon.getName(), "MercuryMoon");
    Assert.assertEquals(jupiterMoon.getDiameter(), 50);
    Assert.assertEquals(jupiterMoon.getName(), "JupiterMoon");
    Assert.assertEquals(jupiter.getName(), "Jupiter");
    Assert.assertEquals(jupiter.getDistanceSun(), 3000);
    Assert.assertEquals(mercury.getName(), "Mercury");
    Assert.assertEquals(mercury.getDistanceSun(), 5000);
    mercuryMoon.setDiameter(100);
    // p.addSatellite(new Satellite("Moon", 70));
    // db.save(sat);
    database.save(jupiter);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    jupiter = database.load(rid);
    jupiterMoon = jupiter.getSatellitesMap().get("JupiterMoon");
    mercury = jupiterMoon.getNear();
    mercuryMoon = mercury.getSatellitesMap().get("MercuryMoon");
    Assert.assertEquals(mercuryMoon.getDiameter(), 100);
    Assert.assertEquals(mercuryMoon.getName(), "MercuryMoon");
    Assert.assertEquals(jupiterMoon.getDiameter(), 50);
    Assert.assertEquals(jupiterMoon.getName(), "JupiterMoon");
    Assert.assertEquals(jupiter.getName(), "Jupiter");
    Assert.assertEquals(jupiter.getDistanceSun(), 3000);
    Assert.assertEquals(mercury.getName(), "Mercury");
    Assert.assertEquals(mercury.getDistanceSun(), 5000);
    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 15 with OObjectDatabaseTx

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

the class ObjectTreeTestSchemaFull method testCustomTypesDatabaseNewInstance.

@Test(dependsOnMethods = "testCustomTypes")
public void testCustomTypesDatabaseNewInstance() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    ORID rid = null;
    try {
        // init counters
        serialized = 0;
        unserialized = 0;
        List<CustomType> customTypesList = new ArrayList<CustomType>();
        customTypesList.add(new CustomType(102L));
        Set<CustomType> customTypeSet = new HashSet<CustomType>();
        customTypeSet.add(new CustomType(103L));
        Map<Long, CustomType> customTypeMap = new HashMap<Long, CustomType>();
        customTypeMap.put(1L, new CustomType(104L));
        CustomClass pojo = database.newInstance(CustomClass.class, "test", 33L, new CustomType(101L), customTypesList, customTypeSet, customTypeMap);
        Assert.assertEquals(serialized, 4);
        Assert.assertEquals(unserialized, 0);
        pojo = database.save(pojo);
        rid = database.getIdentity(pojo);
        database.close();
        database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
        pojo = database.load(rid);
        Assert.assertEquals(unserialized, 0);
        pojo.getCustom();
        Assert.assertEquals(unserialized, 1);
        Assert.assertTrue(pojo.getCustom() instanceof CustomType);
        pojo.getCustomTypeList().iterator().next();
        Assert.assertEquals(unserialized, 2);
        Assert.assertTrue(pojo.getCustomTypeList().iterator().next() instanceof CustomType);
        unserialized--;
        pojo.getCustomTypeSet().iterator().next();
        Assert.assertEquals(unserialized, 3);
        Assert.assertTrue(pojo.getCustomTypeSet().iterator().next() instanceof CustomType);
        unserialized--;
        pojo.getCustomTypeMap().get(1L);
        Assert.assertEquals(serialized, 4);
        Assert.assertEquals(unserialized, 4);
        Assert.assertTrue(pojo.getCustomTypeMap().get(1L) instanceof CustomType);
    } finally {
        database.close();
    }
}
Also used : HashMap(java.util.HashMap) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ArrayList(java.util.ArrayList) ORID(com.orientechnologies.orient.core.id.ORID) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

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