Search in sources :

Example 1 with OLuceneTxChanges

use of com.orientechnologies.lucene.tx.OLuceneTxChanges in project orientdb by orientechnologies.

the class OLuceneIndexNotUnique method put.

@Override
public OLuceneIndexNotUnique put(final Object key, final OIdentifiable singleValue) {
    if (key != null) {
        OTransaction transaction = getDatabase().getTransaction();
        if (transaction.isActive()) {
            OLuceneTxChanges transactionChanges = getTransactionChanges(transaction);
            transaction.addIndexEntry(this, super.getName(), OTransactionIndexChanges.OPERATION.PUT, encodeKey(key), singleValue);
            Document luceneDoc;
            while (true) {
                try {
                    luceneDoc = storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Document>() {

                        @Override
                        public Document callEngine(OIndexEngine engine) {
                            OLuceneIndexEngine oIndexEngine = (OLuceneIndexEngine) engine;
                            return oIndexEngine.buildDocument(key, singleValue);
                        }
                    });
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            try {
                transactionChanges.put(key, singleValue, luceneDoc);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            while (true) {
                try {
                    storage.updateIndexEntry(indexId, key, new Callable<Object>() {

                        @Override
                        public Object call() throws Exception {
                            return Arrays.asList(singleValue);
                        }
                    });
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
        }
    }
    return this;
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OLuceneTxChanges(com.orientechnologies.lucene.tx.OLuceneTxChanges) OIndexEngine(com.orientechnologies.orient.core.index.OIndexEngine) OLuceneIndexEngine(com.orientechnologies.lucene.engine.OLuceneIndexEngine) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OIndexEngineCallback(com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback) OException(com.orientechnologies.common.exception.OException) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) IOException(java.io.IOException)

Example 2 with OLuceneTxChanges

use of com.orientechnologies.lucene.tx.OLuceneTxChanges in project orientdb by orientechnologies.

the class OLuceneIndexNotUnique method remove.

@Override
public boolean remove(final Object key, final OIdentifiable value) {
    if (key != null) {
        OTransaction transaction = getDatabase().getTransaction();
        if (transaction.isActive()) {
            transaction.addIndexEntry(this, super.getName(), OTransactionIndexChanges.OPERATION.REMOVE, encodeKey(key), value);
            OLuceneTxChanges transactionChanges = getTransactionChanges(transaction);
            try {
                transactionChanges.remove(key, value);
            } catch (IOException e) {
                OLogManager.instance().error(this, "Error while removing", e);
            }
            return true;
        } else {
            while (true) {
                try {
                    return storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Boolean>() {

                        @Override
                        public Boolean callEngine(OIndexEngine engine) {
                            OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine;
                            return indexEngine.remove(key, value);
                        }
                    });
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
        }
    }
    return true;
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OLuceneTxChanges(com.orientechnologies.lucene.tx.OLuceneTxChanges) OIndexEngine(com.orientechnologies.orient.core.index.OIndexEngine) OLuceneIndexEngine(com.orientechnologies.lucene.engine.OLuceneIndexEngine) IOException(java.io.IOException)

Aggregations

OLuceneIndexEngine (com.orientechnologies.lucene.engine.OLuceneIndexEngine)2 OLuceneTxChanges (com.orientechnologies.lucene.tx.OLuceneTxChanges)2 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)2 OIndexEngine (com.orientechnologies.orient.core.index.OIndexEngine)2 OTransaction (com.orientechnologies.orient.core.tx.OTransaction)2 IOException (java.io.IOException)2 OException (com.orientechnologies.common.exception.OException)1 OIndexException (com.orientechnologies.orient.core.index.OIndexException)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OIndexEngineCallback (com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback)1 Document (org.apache.lucene.document.Document)1