Examples of OObjectDatabaseTx


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

    super(url, prefix);
  }

  @Override
  protected OObjectDatabaseTx createDatabaseInstance(String url) {
    return new OObjectDatabaseTx(url);
  }
View Full Code Here

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

  /**
   * Checks if all registered entities has schema generated, if not it generates it
   */
  public synchronized void synchronizeSchema() {
    OObjectDatabaseTx database = ((OObjectDatabaseTx) ODatabaseRecordThreadLocal.INSTANCE.get().getDatabaseOwner());
    Collection<Class<?>> registeredEntities = database.getEntityManager().getRegisteredEntities();
    boolean automaticSchemaGeneration = database.isAutomaticSchemaGeneration();
    boolean reloadSchema = false;
    for (Class<?> iClass : registeredEntities) {
      if (Proxy.class.isAssignableFrom(iClass) || iClass.isEnum() || OReflectionHelper.isJavaType(iClass)
          || iClass.isAnonymousClass())
        return;

      if (!database.getMetadata().getSchema().existsClass(iClass.getSimpleName())) {
        database.getMetadata().getSchema().createClass(iClass.getSimpleName());
        reloadSchema = true;
      }

      for (Class<?> currentClass = iClass; currentClass != Object.class;) {

        if (automaticSchemaGeneration && !currentClass.equals(Object.class) && !currentClass.equals(ODocument.class)) {
          ((OSchemaProxyObject) database.getMetadata().getSchema()).generateSchema(currentClass, database.getUnderlying());
        }
        String iClassName = currentClass.getSimpleName();
        currentClass = currentClass.getSuperclass();

        if (currentClass == null || currentClass.equals(ODocument.class))
          // POJO EXTENDS ODOCUMENT: SPECIAL CASE: AVOID TO CONSIDER
          // ODOCUMENT FIELDS
          currentClass = Object.class;

        if (database != null && !database.isClosed() && !currentClass.equals(Object.class)) {
          OClass oSuperClass;
          OClass currentOClass = database.getMetadata().getSchema().getClass(iClassName);
          if (!database.getMetadata().getSchema().existsClass(currentClass.getSimpleName())) {
            oSuperClass = database.getMetadata().getSchema().createClass(currentClass.getSimpleName());
            reloadSchema = true;
          } else {
            oSuperClass = database.getMetadata().getSchema().getClass(currentClass.getSimpleName());
            reloadSchema = true;
          }

          if (currentOClass.getSuperClass() == null || !currentOClass.getSuperClass().equals(oSuperClass)) {
            currentOClass.setSuperClass(oSuperClass);
            reloadSchema = true;
          }

        }
      }
    }
    if (database != null && !database.isClosed() && reloadSchema) {
      database.getMetadata().getSchema().save();
      database.getMetadata().getSchema().reload();
    }
  }
View Full Code Here

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

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

    }
  }

  @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

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

    }
  }

  @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

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

    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

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

    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

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

    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

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

    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

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

      Callable<Void> t = new Callable<Void>() {

        @Override
        public Void call() throws InterruptedException, IOException {
          OObjectDatabaseTx tx = new OObjectDatabaseTx(dbUrl);

          ODatabaseHelper.deleteDatabase(tx, getStorageType());
          ODatabaseHelper.createDatabase(tx, dbUrl, getStorageType());

          try {
            System.out.println("(" + getDbId(tx) + ") " + "Created");

            if (tx.isClosed()) {
              tx.open("admin", "admin");
            }
            tx.getEntityManager().registerEntityClass(DummyObject.class);

            long start = System.currentTimeMillis();
            for (int j = 0; j < operations_write; j++) {
              DummyObject dummy = new DummyObject("name" + j);

              Assert.assertEquals(ODatabaseRecordThreadLocal.INSTANCE.get().getURL(), dbUrl);

              dummy = tx.save(dummy);

              // CAN'T WORK FOR LHPEPS CLUSTERS BECAUSE CLUSTER POSITION CANNOT BE KNOWN
              Assert.assertEquals(((ORID) dummy.getId()).getClusterPosition(), OClusterPositionFactory.INSTANCE.valueOf(j),
                  "RID was " + dummy.getId());

              if ((j + 1) % 20000 == 0) {
                System.out.println("(" + getDbId(tx) + ") " + "Operations (WRITE) executed: " + (j + 1));
              }
            }
            long end = System.currentTimeMillis();

            String time = "(" + getDbId(tx) + ") " + "Executed operations (WRITE) in: " + (end - start) + " ms";
            System.out.println(time);
            times.add(time);

            start = System.currentTimeMillis();
            for (int j = 0; j < operations_read; j++) {
              List<DummyObject> l = tx.query(new OSQLSynchQuery<DummyObject>(" select * from DummyObject "));
              Assert.assertEquals(l.size(), operations_write);

              if ((j + 1) % 20000 == 0) {
                System.out.println("(" + getDbId(tx) + ") " + "Operations (READ) executed: " + j + 1);
              }
            }
            end = System.currentTimeMillis();

            time = "(" + getDbId(tx) + ") " + "Executed operations (READ) in: " + (end - start) + " ms";
            System.out.println(time);
            times.add(time);

            tx.close();

          } finally {
            System.out.println("(" + getDbId(tx) + ") " + "Dropping");
            System.out.flush();
            ODatabaseHelper.deleteDatabase(tx, getStorageType());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.