Search in sources :

Example 31 with OIndexException

use of com.orientechnologies.orient.core.index.OIndexException in project orientdb by orientechnologies.

the class IndexConcurrentCommitTest method testConcurrentUpdate.

public void testConcurrentUpdate() {
    OClass personClass = database.getMetadata().getSchema().createClass("Person");
    personClass.createProperty("ssn", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE);
    personClass.createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    try {
        // Transaction 1
        database.begin();
        // Insert two people in a transaction
        ODocument person1 = new ODocument("Person");
        person1.field("name", "John Doe");
        person1.field("ssn", "111-11-1111");
        person1.save();
        ODocument person2 = new ODocument("Person");
        person2.field("name", "Jane Doe");
        person2.field("ssn", "222-22-2222");
        person2.save();
        // Commit
        database.commit();
        // Ensure that the people made it in correctly
        final List<ODocument> result1 = database.command(new OCommandSQL("select from Person")).execute();
        System.out.println("After transaction 1");
        for (ODocument d : result1) System.out.println(d);
        // Transaction 2
        database.begin();
        // Update the ssn for the second person
        person2.field("ssn", "111-11-1111");
        person2.save();
        // Update the ssn for the first person
        person1.field("ssn", "222-22-2222");
        person1.save();
        System.out.println("To be committed:");
        System.out.println(person1);
        System.out.println(person2);
        // Commit - We get a transaction failure!
        database.commit();
        System.out.println("Success!");
    } catch (OIndexException e) {
        System.out.println("Exception: " + e.toString());
        database.rollback();
    }
    final List<ODocument> result2 = database.command(new OCommandSQL("select from Person")).execute();
    System.out.println("After transaction 2");
    for (ODocument d : result2) System.out.println(d);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OIndexException (com.orientechnologies.orient.core.index.OIndexException)31 IOException (java.io.IOException)27 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)26 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)23 OException (com.orientechnologies.common.exception.OException)16 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)14 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)8 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)6 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)6 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)3 Constructor (java.lang.reflect.Constructor)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 OIOException (com.orientechnologies.common.io.OIOException)1 OLuceneQueryContext (com.orientechnologies.lucene.query.OLuceneQueryContext)1 OIndexEngine (com.orientechnologies.orient.core.index.OIndexEngine)1 OHashTableIndexEngine (com.orientechnologies.orient.core.index.engine.OHashTableIndexEngine)1 ORemoteIndexEngine (com.orientechnologies.orient.core.index.engine.ORemoteIndexEngine)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1