Java Code Examples for com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx#save()

The following examples show how to use com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx#save() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuceneInsertReadMultithreadTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {

  db = new ODatabaseDocumentTx(url);
  db.open("admin", "admin");
  db.declareIntent(new OIntentMassiveInsert());
  db.begin();
  for (int i = 0; i < cycle; i++) {
    ODocument doc = new ODocument("City");

    doc.field("name", "Rome");

    db.save(doc);
    if (i % commitBuf == 0) {
      db.commit();
      db.begin();
    }

  }

  db.close();
}
 
Example 2
Source File: LuceneInsertMultithreadTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {

  db = new ODatabaseDocumentTx(url);
  db.open("admin", "admin");
  db.declareIntent(new OIntentMassiveInsert());
  db.begin();
  for (int i = 0; i < cycle; i++) {
    ODocument doc = new ODocument("City");

    doc.field("name", "Rome");

    db.save(doc);
    if (i % commitBuf == 0) {
      db.commit();
      db.begin();
    }

  }

  db.close();
}
 
Example 3
Source File: ConfigDatabaseUpgrade_1_6.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void deleteBrokenRecord(ODatabaseDocumentTx db, ODocument selector) {
  // HACK to get around inability to directly delete documents that cannot be deserialized
  // from OrientDB - see https://github.com/orientechnologies/orientdb/issues/6190
  ODocument replacement = new ODocument();
  replacement.field("name", (String) selector.field("name"));
  replacement.field("type", (String) selector.field("type"));
  replacement.field("description", (String) selector.field("description"));
  replacement.field("attributes", new HashMap<String, String>());
  ORecordInternal.setVersion(replacement, selector.getVersion());
  ORecordInternal.setIdentity(replacement, (ORecordId) selector.getIdentity());
  db.save(replacement);
  db.delete(replacement.getRecord().getIdentity());
}
 
Example 4
Source File: TestCreateNested1.java    From orientdb-lucene with Apache License 2.0 3 votes vote down vote up
@Test
public void testIndex() {

  ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:tmp");

  db.create();

  OClass test = db.getMetadata().getSchema().createClass("Test");

  test.createProperty("name", OType.STRING);
  test.createProperty("age", OType.INTEGER);

  test.createIndex("Test.name_age", OClass.INDEX_TYPE.NOTUNIQUE, "name", "age");

  ODocument doc = new ODocument("Test");

  doc.field("name", "Enrico");
  doc.field("age", 32);
  db.save(doc);

  OIndex<?> index = db.getMetadata().getIndexManager().getIndex("Test.name_age");

  Collection<OIdentifiable> results = (Collection<OIdentifiable>) index.get(new OCompositeKey(Arrays.asList("Enrico", 32)));

  Assert.assertEquals(results.size(), 1);

  results = (Collection<OIdentifiable>) index.get(new OCompositeKey(Arrays.asList("Enrico", 31)));
  Assert.assertEquals(results.size(), 0);
}