Examples of ODatabaseDocument


Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

public class TestExceptionNotOpen {

  @Test
  public void testExceptionNotOpenMemory() {

    ODatabaseDocument db = new ODatabaseDocumentTx("memory:test");
    try {
      db.save(new ODocument());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.delete(new ODocument());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.hide(new ORecordId());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.begin();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.begin(OTransaction.TXTYPE.NOTX);
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.rollback();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.commit();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.getMetadata();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }

  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

  }

  @Test
  public void testExceptionNotOpenRemote() {

    ODatabaseDocument db = new ODatabaseDocumentTx("remote:127.0.0.1:00");
    try {
      db.save(new ODocument());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.delete(new ODocument());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.hide(new ORecordId());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.begin();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.begin(OTransaction.TXTYPE.NOTX);
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.rollback();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.commit();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.getMetadata();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

  }

  @Test
  public void testExceptionNotOpenPlocal() {

    ODatabaseDocument db = new ODatabaseDocumentTx("plocal:./target/databaseCheck");
    try {
      db.save(new ODocument());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.delete(new ODocument());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.hide(new ORecordId());
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.begin();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.begin(OTransaction.TXTYPE.NOTX);
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.rollback();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.commit();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
    try {
      db.getMetadata();
      Assert.fail();
    } catch (ODatabaseException ex) {
    }
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

  public void afterMethod() throws Exception {
  }

  public void testDbCreationNoSecurity() throws IOException {
    if (!url.startsWith(OEngineRemote.NAME)) {
      ODatabaseDocument db = new ODatabaseDocumentTx(url);
      db.setProperty("security", Boolean.FALSE);

      ODatabaseHelper.dropDatabase(db, "server", getStorageType());
      ODatabaseHelper.createDatabase(db, url, getStorageType());
      ODatabaseHelper.dropDatabase(db, "server", getStorageType());
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

    ODatabaseHelper.dropDatabase(db, getStorageType());
  }

  @Test
  public void testCreateAndConnectionPool() throws IOException {
    ODatabaseDocument db = new ODatabaseDocumentTx(url);

    ODatabaseHelper.dropDatabase(db, getStorageType());

    ODatabaseHelper.createDatabase(db, url, getStorageType());
    db.close();
    // Get connection from pool
    db = ODatabaseDocumentPool.global().acquire(url, "admin", "admin");
    db.close();

    // Destroy db in the back of the pool
    db = new ODatabaseDocumentTx(url);
    ODatabaseHelper.dropDatabase(db, getStorageType());

    // Re-create it so that the db exists for the pool
    db = new ODatabaseDocumentTx(url);
    ODatabaseHelper.createDatabase(db, url, getStorageType());
    db.close();

    ODatabaseDocumentPool.global().close();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

  public void afterMethod() throws Exception {
  }


  public void testDbDeleteNoCredential() throws IOException {
    ODatabaseDocument db = new ODatabaseDocumentTx(url);
    try {
      db.drop();
      Assert.fail("Should have thrown ODatabaseException because trying to delete a not opened");
    } catch (ODatabaseException e) {
      Assert.assertTrue(e.getMessage().equals("Database '" + url + "' is closed"));
    } catch (OStorageException e) {
      Assert.assertTrue(e.getMessage().startsWith("Cannot delete the remote storage:"));
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

  public void testDbDelete() throws IOException {
    String prefix = url.substring(0, url.indexOf(':') + 1);
    if (prefix.equals("memory:") || prefix.equals("remote:"))
      return;

    ODatabaseDocument db = new ODatabaseDocumentTx(prefix + testPath + "/" + DbImportExportTest.NEW_DB_URL);
    if (!db.exists())
      db.create();

    if (db.exists()) {
      if (db.isClosed())
        db.open("admin", "admin");
    }

    ODatabaseHelper.dropDatabase(db, getStorageType());

    Assert.assertFalse(new File(testPath + "/" + DbImportExportTest.NEW_DB_PATH).exists());
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

  public void testDbDeleteWithIndex() {
    String prefix = url.substring(0, url.indexOf(':') + 1);
    if (prefix.equals("remote:"))
      return;

    ODatabaseDocument db = new ODatabaseDocumentTx(prefix + testPath + "/" + DbImportExportTest.NEW_DB_URL);
    if (!db.exists())
      db.create();

    if (db.exists()) {
      if (db.isClosed())
        db.open("admin", "admin");

      db.drop();
      db.create();
    }

    final OClass indexedClass = db.getMetadata().getSchema().createClass("IndexedClass");
    indexedClass.createProperty("value", OType.STRING);
    indexedClass.createIndex("indexValue", OClass.INDEX_TYPE.UNIQUE, "value");

    final ODocument document = new ODocument("IndexedClass");
    document.field("value", "value");
    document.save();

    db.drop();
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

    db.close();
  }

  public void testIndexParamsAutoConversion() {
    ODatabaseDocument db = new ODatabaseDocumentTx(database.getURL());
    db.open("admin", "admin");

    if (!db.getMetadata().getSchema().existsClass("IndexTestTerm")) {
      final OClass termClass = db.getMetadata().getSchema().createClass("IndexTestTerm");
      termClass.createProperty("label", OType.STRING);
      termClass.createIndex("idxTerm", INDEX_TYPE.UNIQUE, "label");

      db.getMetadata().getSchema().save();
    }

    final ODocument doc = new ODocument("IndexTestTerm");
    doc.field("label", "42");
    doc.save();

    final ORecordId result = (ORecordId) db.getMetadata().getIndexManager().getIndex("idxTerm").get("42");
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getIdentity(), doc.getIdentity());
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument

    Assert.assertTrue(result.isEmpty());

  }

  public void createInheritanceIndex() {
    ODatabaseDocument db = new ODatabaseDocumentTx(database.getURL());
    try {
      db.open("admin", "admin");

      if (!db.getMetadata().getSchema().existsClass("BaseTestClass")) {
        OClass baseClass = db.getMetadata().getSchema().createClass("BaseTestClass");
        OClass childClass = db.getMetadata().getSchema().createClass("ChildTestClass");
        OClass anotherChildClass = db.getMetadata().getSchema().createClass("AnotherChildTestClass");

        if (!baseClass.isSuperClassOf(childClass))
          childClass.setSuperClass(baseClass);
        if (!baseClass.isSuperClassOf(anotherChildClass))
          anotherChildClass.setSuperClass(baseClass);

        baseClass.createProperty("testParentProperty", OType.LONG).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);

        db.getMetadata().getSchema().save();
      }

      ODocument childClassDocument = db.newInstance("ChildTestClass");
      childClassDocument.field("testParentProperty", 10L);
      childClassDocument.save();

      ODocument anotherChildClassDocument = db.newInstance("AnotherChildTestClass");
      anotherChildClassDocument.field("testParentProperty", 11L);
      anotherChildClassDocument.save();

      Assert.assertFalse(new ORecordId(-1, ORID.CLUSTER_POS_INVALID).equals(childClassDocument.getIdentity()));
      Assert.assertFalse(new ORecordId(-1, ORID.CLUSTER_POS_INVALID).equals(anotherChildClassDocument.getIdentity()));
    } finally {
      db.close();
    }
  }
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.