Search in sources :

Example 1 with OLuceneIndexEngine

use of com.orientechnologies.lucene.engine.OLuceneIndexEngine 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 OLuceneIndexEngine

use of com.orientechnologies.lucene.engine.OLuceneIndexEngine 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 OLuceneIndexEngine

use of com.orientechnologies.lucene.engine.OLuceneIndexEngine 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)

Example 4 with OLuceneIndexEngine

use of com.orientechnologies.lucene.engine.OLuceneIndexEngine 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)4 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)4 OIndexEngine (com.orientechnologies.orient.core.index.OIndexEngine)4 OIndexEngineCallback (com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback)3 OTransaction (com.orientechnologies.orient.core.tx.OTransaction)3 OLuceneTxChanges (com.orientechnologies.lucene.tx.OLuceneTxChanges)2 IOException (java.io.IOException)2 OException (com.orientechnologies.common.exception.OException)1 OLuceneTxOperations (com.orientechnologies.lucene.OLuceneTxOperations)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 Map (java.util.Map)1 Document (org.apache.lucene.document.Document)1