Package com.orientechnologies.orient.object.db

Examples of com.orientechnologies.orient.object.db.OObjectDatabaseTx


    Assert.assertTrue(pojo.getCustomTypeMap().get(1L) instanceof CustomType);
  }

  @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();
    }
  }
View Full Code Here


    }
  }

  @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);
        }
      });

      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();
    }
  }
View Full Code Here

    }
  }

  @Test(dependsOnMethods = "testEnumListWithCustomTypes")
  public void childUpdateTest() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    Planet p = database.newInstance(Planet.class);
    Satellite sat = database.newInstance(Satellite.class);
    p.setName("Earth");
    p.setDistanceSun(1000);
    sat.setDiameter(50);
    p.addSatellite(sat);
    database.save(p);
    ORID rid = database.getIdentity(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.load(rid);
    sat = p.getSatellites().get(0);
    Assert.assertEquals(sat.getDiameter(), 50);
    Assert.assertEquals(p.getDistanceSun(), 1000);
    Assert.assertEquals(p.getName(), "Earth");
    sat.setDiameter(500);
    // p.addSatellite(new Satellite("Moon", 70));
    // db.save(sat);
    database.save(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.load(rid);
    sat = p.getSatellites().get(0);
    Assert.assertEquals(sat.getDiameter(), 500);
    Assert.assertEquals(p.getDistanceSun(), 1000);
    Assert.assertEquals(p.getName(), "Earth");
    database.close();
  }
View Full Code Here

    database.close();
  }

  @Test(dependsOnMethods = "childUpdateTest")
  public void childNLevelUpdateTest() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    Planet p = database.newInstance(Planet.class);
    Planet near = database.newInstance(Planet.class);
    Satellite sat = database.newInstance(Satellite.class);
    Satellite satNear = database.newInstance(Satellite.class);
    sat.setDiameter(50);
    sat.setNear(near);
    satNear.setDiameter(10);
    near.addSatellite(satNear);
    p.addSatellite(sat);
    database.save(p);
    ORID rid = database.getIdentity(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.load(rid);
    sat = p.getSatellites().get(0);
    near = sat.getNear();
    satNear = near.getSatellites().get(0);
    Assert.assertEquals(satNear.getDiameter(), 10);
    satNear.setDiameter(100);
    // p.addSatellite(new Satellite("Moon", 70));
    // db.save(sat);
    database.save(p);
    database.close();
    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    p = database.load(rid);
    sat = p.getSatellites().get(0);
    near = sat.getNear();
    satNear = near.getSatellites().get(0);
    Assert.assertEquals(satNear.getDiameter(), 100);
    database.close();
  }
View Full Code Here

    database.close();
  }

  @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();
  }
View Full Code Here

    database.close();
  }

  @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();
  }
View Full Code Here

    database.close();
  }

  @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();
    }
  }
View Full Code Here

    }
  }

  @Test(dependsOnMethods = "testDictionaryMassiveCreate")
  public void testDictionaryWithPOJOs() throws IOException {
    OObjectDatabaseTx database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    database.getEntityManager().registerEntityClass(ObjectDictionaryTest.class);

    Assert.assertNull(database.getDictionary().get("testKey"));
    database.getDictionary().put("testKey", new ObjectDictionaryTest());
    Assert.assertNotNull(database.getDictionary().get("testKey"));

    database.close();
  }
View Full Code Here

  private Map<String, Object> fieldsAndThereDefaultValue;

  @BeforeClass
  protected void setUp() throws Exception {
    databaseTx = new OObjectDatabaseTx("memory:OObjectEnumLazyListTest");
    databaseTx.create();

    databaseTx.getEntityManager().registerEntityClass(EntityWithDifferentFieldTypes.class);

    fieldsAndThereDefaultValue = new HashMap<String, Object>();
View Full Code Here

 
  private OObjectDatabaseTx databaseTx;
 
  @BeforeClass
  protected void setUp() throws Exception {
    databaseTx = new OObjectDatabaseTx("memory:OObjectEnumLazyListTest");
    databaseTx.create();

    databaseTx.getEntityManager().registerEntityClass(EntityWithEnumList.class);

  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.object.db.OObjectDatabaseTx

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.