Examples of ODatabaseDocumentTx


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

    if (!(database.getDatabaseOwner() instanceof ODatabaseDocumentTx))
      throw new OCommandSQLParsingException("This command supports only the database type ODatabaseDocumentTx and type '"
          + database.getClass() + "' was found");

    final ODatabaseDocumentTx db = (ODatabaseDocumentTx) database.getDatabaseOwner();

    OClass sourceClass = database.getMetadata().getSchema().getClass(sourceClassName);
    if (sourceClass == null)
      throw new OCommandExecutionException("Source class '" + sourceClassName + "' not found");

    OClass destClass = database.getMetadata().getSchema().getClass(destClassName);
    if (destClass == null)
      throw new OCommandExecutionException("Destination class '" + destClassName + "' not found");

    Object value;
    String cmd = "select from " + destClassName + " where " + destField + " = ";
    List<ODocument> result;
    ODocument target;
    Object oldValue;
    long total = 0;

    if (linkName == null)
      // NO LINK NAME EXPRESSED: OVERWRITE THE SOURCE FIELD
      linkName = sourceField;

    boolean inverse = linkType != null && linkType.equalsIgnoreCase("inverse");
    boolean multipleRelationship = false;

    long totRecords = db.countClass(sourceClass.getName());
    long currRecord = 0;

    if (progressListener != null)
      progressListener.onBegin(this, totRecords);

    try {
      // BROWSE ALL THE RECORDS OF THE SOURCE CLASS
      for (ODocument doc : db.browseClass(sourceClass.getName())) {
        value = doc.field(sourceField);

        if (value != null) {
          if (value instanceof ODocument || value instanceof ORID) {
            // ALREADY CONVERTED
View Full Code Here

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

*
*/
public class ODatabaseGraphTx extends ODatabasePojoAbstract<OGraphElement> {

  public ODatabaseGraphTx(final String iURL) {
    super(new ODatabaseDocumentTx(iURL));
  }
View Full Code Here

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

    return (T) javaClass.newInstance();
  }

  public void validateInstances() {
    final ODatabaseDocumentTx db = (ODatabaseDocumentTx) getDatabase();
    for (ODocument d : db.browseClass(name, true)) {
      d.validate();
    }
  }
View Full Code Here

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

    System.out.println("Using db = local:" + dbPath);
    File dbDir = new File(dbPath);
    System.out.println("Clean db directory for test...");
    delTree(dbDir);
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("local:" + dbPath);
    db.create();
    db.close();

    System.out.println("Reopen it...");
    // Something was added to dbPath so the legacy situation was simulated
    dbPath += "/foo";
    db = new ODatabaseDocumentTx("local:" + dbPath).open("admin", "admin");
    db.close();
    db.delete();
    Assert.assertTrue(true);
  }
View Full Code Here

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

    System.out.println("Using db = local:" + dbPath);
    File dbDir = new File(dbPath).getParentFile();
    System.out.println("Clean db directory for test...");
    delTree(dbDir);
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("local:" + dbPath);
    db.create();
    db.close();

    System.out.println("Reopen it...");
    db = new ODatabaseDocumentTx("local:" + dbPath).open("admin", "admin");
    db.close();
    Assert.assertTrue(true);
  }
View Full Code Here

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

    System.out.println("Using db = local:" + dbPath);
    File dbDir = new File(dbPath);
    System.out.println("Clean db directory for test...");
    delTree(dbDir);
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("local:" + dbPath);
    db.create();
    db.close();

    System.out.println("Create OK!");
    db = new ODatabaseDocumentTx("local:" + dbPath).open("admin", "admin");
    System.out.println("Open OK!");
    Assert.assertTrue(db.exists());
    System.out.println("Exists OK!");
    db.delete();
    System.out.println("Delete OK!");
  }
View Full Code Here

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

  private OPropertyIndex      index;
  private ODatabaseDocumentTx  database;

  @BeforeClass
  public void setUpClass() {
    database = new ODatabaseDocumentTx(DEFAULT_DB_URL);
    if (database.exists()) {
      database.delete();
      database.create();
    } else {
      database.create();
View Full Code Here

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

  @Override
  public void init() {
    OProfiler.getInstance().startRecording();

    database = new ODatabaseDocumentTx(System.getProperty("url")).open("admin", "admin");

    database.declareIntent(new OIntentMassiveInsert());
    database.begin(TXTYPE.NOTX);
  }
View Full Code Here

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

    }
  }

  @Test(dependsOnMethods = "testTransactionOptimisticCacheMgmt2Db")
  public void testTransactionMultipleRecords() throws IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    db.open("admin", "admin");

    long totalAccounts = db.countClusterElements("Account");

    String json = "{ \"@class\": \"Account\", \"type\": \"Residence\", \"street\": \"Piazza di Spagna\"}";

    db.begin(TXTYPE.OPTIMISTIC);
    for (int g = 0; g < 1000; g++) {
      ODocument doc = new ODocument(db, "Account");
      doc.fromJSON(json);
      doc.field("nr", g);

      doc.save();
    }
    db.commit();

    Assert.assertEquals(db.countClusterElements("Account"), totalAccounts + 1000);

    db.close();
  }
View Full Code Here

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

  }

  @SuppressWarnings("unchecked")
  @Test
  public void createGraphInTx() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    db.open("admin", "admin");

    db.begin();

    ODocument kim = new ODocument(db, "Profile").field("name", "Kim").field("surname", "Bauer");
    ODocument teri = new ODocument(db, "Profile").field("name", "Teri").field("surname", "Bauer");
    ODocument jack = new ODocument(db, "Profile").field("name", "Jack").field("surname", "Bauer");

    ((HashSet<ODocument>) jack.field("following", new HashSet<ODocument>()).field("following")).add(kim);
    ((HashSet<ODocument>) kim.field("following", new HashSet<ODocument>()).field("following")).add(teri);
    ((HashSet<ODocument>) teri.field("following", new HashSet<ODocument>()).field("following")).add(jack);

    jack.save();

    db.commit();

    db.close();
    db.open("admin", "admin");

    ODocument loadedJack = db.load(jack.getIdentity());
    Assert.assertEquals(loadedJack.field("name"), "Jack");
    Collection<ODocument> jackFollowings = loadedJack.field("following");
    Assert.assertNotNull(jackFollowings.size());
    Assert.assertEquals(jackFollowings.size(), 1);

    ODocument loadedKim = jackFollowings.iterator().next();
    Assert.assertEquals(loadedKim.field("name"), "Kim");
    Collection<ODocument> kimFollowings = loadedKim.field("following");
    Assert.assertNotNull(kimFollowings.size());
    Assert.assertEquals(kimFollowings.size(), 1);

    ODocument loadedTeri = kimFollowings.iterator().next();
    Assert.assertEquals(loadedTeri.field("name"), "Teri");
    Collection<ODocument> teriFollowings = loadedTeri.field("following");
    Assert.assertNotNull(teriFollowings.size());
    Assert.assertEquals(teriFollowings.size(), 1);

    Assert.assertEquals(teriFollowings.iterator().next().field("name"), "Jack");

    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.