Search in sources :

Example 16 with OInvalidIndexEngineIdException

use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException in project orientdb by orientechnologies.

the class OIndexOneValue method count.

public long count(Object iKey) {
    iKey = getCollatingValue(iKey);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireSharedLock(iKey);
    try {
        acquireSharedLock();
        try {
            while (true) try {
                return storage.indexContainsKey(indexId, iKey) ? 1 : 0;
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseSharedLock(iKey);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 17 with OInvalidIndexEngineIdException

use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException in project orientdb by orientechnologies.

the class OIndexOneValue method iterateEntries.

@Override
public OIndexCursor iterateEntries(Collection<?> keys, boolean ascSortOrder) {
    final List<Object> sortedKeys = new ArrayList<Object>(keys);
    final Comparator<Object> comparator;
    if (ascSortOrder)
        comparator = ODefaultComparator.INSTANCE;
    else
        comparator = Collections.reverseOrder(ODefaultComparator.INSTANCE);
    Collections.sort(sortedKeys, comparator);
    return new OIndexAbstractCursor() {

        private Iterator<?> keysIterator = sortedKeys.iterator();

        @Override
        public Map.Entry<Object, OIdentifiable> nextEntry() {
            OIdentifiable result = null;
            Object key = null;
            while (keysIterator.hasNext() && result == null) {
                key = keysIterator.next();
                key = getCollatingValue(key);
                acquireSharedLock();
                try {
                    while (true) try {
                        result = (OIdentifiable) storage.getIndexValue(indexId, key);
                        break;
                    } catch (OInvalidIndexEngineIdException e) {
                        doReloadIndexEngine();
                    }
                } finally {
                    releaseSharedLock();
                }
            }
            if (result == null)
                return null;
            final Object resultKey = key;
            final OIdentifiable resultValue = result;
            return new Map.Entry<Object, OIdentifiable>() {

                @Override
                public Object getKey() {
                    return resultKey;
                }

                @Override
                public OIdentifiable getValue() {
                    return resultValue;
                }

                @Override
                public OIdentifiable setValue(OIdentifiable value) {
                    throw new UnsupportedOperationException("setValue");
                }
            };
        }
    };
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 18 with OInvalidIndexEngineIdException

use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException in project orientdb by orientechnologies.

the class OIndexUnique method put.

@Override
public OIndexOneValue put(Object key, final OIdentifiable iSingleValue) {
    if (iSingleValue != null && !iSingleValue.getIdentity().isPersistent())
        throw new IllegalArgumentException("Cannot index a non persistent record (" + iSingleValue.getIdentity() + ")");
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive) {
        keyLockManager.acquireExclusiveLock(key);
    }
    try {
        acquireSharedLock();
        try {
            while (true) try {
                storage.validatedPutIndexValue(indexId, key, iSingleValue, UNIQUE_VALIDATOR);
                break;
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
            return this;
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 19 with OInvalidIndexEngineIdException

use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException 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 20 with OInvalidIndexEngineIdException

use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException 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

OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)20 ODatabase (com.orientechnologies.orient.core.db.ODatabase)13 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 OLuceneIndexEngine (com.orientechnologies.lucene.engine.OLuceneIndexEngine)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 IOException (java.io.IOException)3 OException (com.orientechnologies.common.exception.OException)2 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)2 OLuceneTxChanges (com.orientechnologies.lucene.tx.OLuceneTxChanges)2 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OLuceneTxOperations (com.orientechnologies.lucene.OLuceneTxOperations)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OIndexException (com.orientechnologies.orient.core.index.OIndexException)1 OEmptyIterator (com.orientechnologies.orient.core.iterator.OEmptyIterator)1