Package com.orientechnologies.orient.object.db

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


    // loop for start & stop server
    for (int i = 0; i < 5; i++) {
      OLogManager.instance().info(this, "Iteration " + i);
      OServer server = OServerMain.create().startup().activate();
      // create database if does not exist
      OObjectDatabaseTx database = new OObjectDatabaseTx("plocal:" + System.getProperty("ORIENTDB_HOME") + "/test-db");
      if (!database.exists())
        database.create();
      database.open("admin", "admin");
      database.countClass("ouser");
      database.close();
      server.shutdown();
    }
  }
View Full Code Here


  @Override
  public void init() {
    Orient.instance().getProfiler().startRecording();

    database = new OObjectDatabaseTx(System.getProperty("url")).open("admin", "admin");
    database.getEntityManager().registerEntityClass(Account.class);
    database.declareIntent(new OIntentMassiveInsert());
    database.begin(TXTYPE.NOTX);
  }
View Full Code Here

    Assert.assertEquals(loadedMap3.size(), 0);
  }

  @Test
  public void testFetchedJson() {
    OObjectDatabaseTx database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    try {
      database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.business");
      database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.whiz");
      database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.base");

      List<ODocument> result = database.getUnderlying()
          .command(new OSQLSynchQuery<ODocument>("select * from Profile where name = 'Barack' and surname = 'Obama'")).execute();

      for (ODocument doc : result) {
        String jsonFull = doc.toJSON("type,rid,version,class,keepTypes,attribSameRow,indent:0,fetchPlan:*:-1");
        ODocument loadedDoc = new ODocument().fromJSON(jsonFull);

        Assert.assertTrue(doc.hasSameContentOf(loadedDoc));
      }
    } finally {
      database.close();
    }
  }
View Full Code Here

        this.clazz = modelClass;
    }

    @Override
    public Long count(List<String> searchFields, String keywords, String where) {
        OObjectDatabaseTx db = ODB.openObjectDB();
        String q = "select count(*) from " + clazz.getSimpleName() + " ";
        List<Object> params = new ArrayList<Object>();
        if (keywords != null && !keywords.equals("")) {
            String searchQuery = getSearchQuery(searchFields, params, keywords);
            if (!searchQuery.equals("")) {
                q += " where ( " + searchQuery + " )";
            }
            q += (where != null ? " and " + where : "");
        } else {
            q += (where != null ? " where " + where : "");
        }
        Long count = 0L;
        try {
            List<ODocument> lcount = db.query(new OSQLSynchQuery<Long>(q), params.toArray());
            if (!(lcount == null || lcount.isEmpty())) {
                ODocument doc = lcount.get(0);
                count = doc.field("count");
            }
        } catch (Exception e) {
View Full Code Here

        return count;
    }

    @Override
    public void deleteAll() {
        OObjectDatabaseTx db = ODB.openObjectDB();
        db.command(new OCommandSQL("delete from " + clazz.getSimpleName())).execute();
    }
View Full Code Here

    protected static final int TOT_RECORDS = 10;
    private City redmond = new City(new Country("Washington"), "Redmond");

    @Test
    public void basic() {
        OObjectDatabaseTx db = ODB.openObjectDB();
        Item item = new Item();
        item.description = "Description";
        item.name = "Item578";
        db.save(item);
        assertEquals(1, db.countClass(Item.class));
        for (Item it : db.browseClass(Item.class)) {
            assertNotNull(db.getIdentity(it).toString());
            assertEquals("Item578", it.name);
            db.delete(it);
        }
    }
View Full Code Here

        }
    }

    @Test
    public void crudInheritance() {
        OObjectDatabaseTx database = ODB.openObjectDB();

        long startRecordNumber = database.countClusterElements("Company");

        Company company;

        for (long i = startRecordNumber; i < startRecordNumber + TOT_RECORDS; ++i) {
            company = new Company((int) i, "Microsoft" + i);
            company.setEmployees((int) (100000 + i));
            company.getAddresses().add(new Address("Headquarter", redmond, "WA 98073-9717"));
            database.save(company);
        }
        assertEquals(database.countClusterElements("Company") - startRecordNumber, TOT_RECORDS);
        final List<Account> result = database.query(new OSQLSynchQuery<Account>(
                "select from Company where name.length() > 0"));

        assertTrue(result.size() > 0);
        assertEquals(result.size(), TOT_RECORDS);

        int companyRecords = 0;
        Account account;
        for (int i = 0; i < result.size(); ++i) {
            account = result.get(i);

            if (account instanceof Company)
                companyRecords++;

            assertNotSame(account.getName().length(), 0);
        }

        assertEquals(companyRecords, TOT_RECORDS);

        final List<Company> result2 = database.query(new OSQLSynchQuery<ODocument>(
                "select * from Company where name.length() > 0"));

        assertTrue(result2.size() == TOT_RECORDS);

        Company account2;
        for (int i = 0; i < result.size(); ++i) {
            account2 = result2.get(i);
            assertNotSame(account2.getName().length(), 0);
        }

        startRecordNumber = database.countClusterElements("Company");

        // DELETE ALL THE RECORD IN THE CLUSTER
        for (Object obj : database.browseCluster("Company")) {
            database.delete(obj);
            break;
        }

        assertEquals(database.countClusterElements("Company"), startRecordNumber - 1);
    }
View Full Code Here

        return localGraphTx.get();
    }

    public static OObjectDatabaseTx openObjectDB() {
        if (!hasObjectTx()) {
          OObjectDatabaseTx db = OObjectDatabasePool.global()
                    .acquire(ODBPlugin.url, ODBPlugin.user, ODBPlugin.passwd);
            localObjectTx.set(db);
            registerListeners(db);
            registerHooks(db);
        }
View Full Code Here

        Logger.info(PLUGIN_PREFIX + msg, args);
    }

    private void registerEntityClasses() {
        String modelPackage = Play.configuration.getProperty("odb.entities.package", "models");
        OObjectDatabaseTx db = new OObjectDatabaseTx(url);
        db.open(user, passwd);

        info("Registering Entities");
        for (ApplicationClass appClass : Play.classes.all()) {
            Class<?> javaClass = appClass.javaClass;
            if (javaClass.getName().startsWith(modelPackage)) {
                // TODO handle Oversize
                String entityName = javaClass.getSimpleName();
                info("Entity: %s", javaClass.getName());
                db.getEntityManager().registerEntityClass(javaClass);
                OSchema schema = db.getMetadata().getSchema();
                if (!schema.existsClass(entityName)) {
                    info("Schema: %s", entityName);
                    schema.createClass(javaClass);
                    schema.save();
                }
            }
        }
        // TODO filtered by package name?
        info("Registering Database Listeners");
        for (ApplicationClass listener : Play.classes.getAssignableClasses(ODatabaseListener.class)) {
            info("Listener: %s", listener.javaClass.getName());
            ODB.listeners.add(listener);
        }
        info("Registering Record Hooks");
        for (ApplicationClass hook : Play.classes.getAssignableClasses(ORecordHook.class)) {
            info("Hook: %s", hook.javaClass.getName());
            ODB.hooks.add(hook);
        }

        db.close();
    }
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.