Search in sources :

Example 1 with OIndexEngineCallback

use of com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback in project orientdb by orientechnologies.

the class OLuceneIndexNotUnique method commitSnapshot.

@Override
protected void commitSnapshot(final Map<Object, Object> snapshot) {
    while (true) try {
        storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Object>() {

            @Override
            public Boolean callEngine(OIndexEngine engine) {
                OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine;
                for (Map.Entry<Object, Object> snapshotEntry : snapshot.entrySet()) {
                    Object key = snapshotEntry.getKey();
                    OLuceneTxOperations operations = (OLuceneTxOperations) snapshotEntry.getValue();
                    for (OIdentifiable oIdentifiable : operations.removed) {
                        indexEngine.remove(decodeKey(key), oIdentifiable);
                    }
                }
                for (Map.Entry<Object, Object> snapshotEntry : snapshot.entrySet()) {
                    Object key = snapshotEntry.getKey();
                    OLuceneTxOperations operations = (OLuceneTxOperations) snapshotEntry.getValue();
                    indexEngine.put(decodeKey(key), operations.added);
                }
                OTransaction transaction = getDatabase().getTransaction();
                resetTransactionChanges(transaction);
                return null;
            }
        });
        break;
    } catch (OInvalidIndexEngineIdException e) {
        doReloadIndexEngine();
    }
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OIndexEngine(com.orientechnologies.orient.core.index.OIndexEngine) OLuceneIndexEngine(com.orientechnologies.lucene.engine.OLuceneIndexEngine) OLuceneTxOperations(com.orientechnologies.lucene.OLuceneTxOperations) OIndexEngineCallback(com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback) Map(java.util.Map) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 2 with OIndexEngineCallback

use of com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback 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 3 with OIndexEngineCallback

use of com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback in project orientdb by orientechnologies.

the class OLuceneIndexNotUnique method onIndexEngineChange.

@Override
protected void onIndexEngineChange(int indexId) {
    while (true) try {
        storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Object>() {

            @Override
            public Object callEngine(OIndexEngine engine) {
                OLuceneIndexEngine oIndexEngine = (OLuceneIndexEngine) engine;
                oIndexEngine.init(getName(), getType(), getDefinition(), isAutomatic(), getMetadata());
                return null;
            }
        });
        break;
    } catch (OInvalidIndexEngineIdException e) {
        doReloadIndexEngine();
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OIndexEngine(com.orientechnologies.orient.core.index.OIndexEngine) OLuceneIndexEngine(com.orientechnologies.lucene.engine.OLuceneIndexEngine) OIndexEngineCallback(com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback)

Aggregations

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