Search in sources :

Example 11 with OInvalidIndexEngineIdException

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

the class OIndexMultiValues method put.

public OIndexMultiValues put(Object key, final OIdentifiable singleValue) {
    if (singleValue != null && !singleValue.getIdentity().isPersistent())
        throw new IllegalArgumentException("Cannot index a non persistent record (" + singleValue.getIdentity() + ")");
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive) {
        keyLockManager.acquireExclusiveLock(key);
    }
    try {
        acquireSharedLock();
        try {
            if (!singleValue.getIdentity().isValid())
                (singleValue.getRecord()).save();
            final ORID identity = singleValue.getIdentity();
            final boolean durable;
            if (metadata != null && Boolean.TRUE.equals(metadata.field("durableInNonTxMode")))
                durable = true;
            else
                durable = false;
            Set<OIdentifiable> values = null;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            final Set<OIdentifiable> cvalues = values;
            final Callable<Object> creator = new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    Set<OIdentifiable> result = cvalues;
                    if (result == null) {
                        if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm)) {
                            result = new OIndexRIDContainer(getName(), durable);
                        } else {
                            throw new IllegalStateException("MVRBTree is not supported any more");
                        }
                    }
                    result.add(identity);
                    return result;
                }
            };
            while (true) {
                try {
                    storage.updateIndexEntry(indexId, key, creator);
                    return this;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Callable(java.util.concurrent.Callable)

Example 12 with OInvalidIndexEngineIdException

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

the class OIndexOneValue method get.

public OIdentifiable get(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 (OIdentifiable) storage.getIndexValue(indexId, iKey);
            } 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 13 with OInvalidIndexEngineIdException

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

the class OIndexAbstract method clear.

public OIndex<T> clear() {
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.lockAllExclusive();
    try {
        acquireSharedLock();
        try {
            while (true) try {
                storage.clearIndex(indexId);
                break;
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
            return this;
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.unlockAllExclusive();
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 14 with OInvalidIndexEngineIdException

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

the class OIndexMultiValues method count.

public long count(Object key) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireSharedLock(key);
    try {
        acquireSharedLock();
        try {
            Set<OIdentifiable> values;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null)
                return 0;
            return values.size();
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseSharedLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 15 with OInvalidIndexEngineIdException

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

the class OIndexMultiValues 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();

        private Iterator<OIdentifiable> currentIterator = OEmptyIterator.IDENTIFIABLE_INSTANCE;

        private Object currentKey;

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

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

                @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) OEmptyIterator(com.orientechnologies.orient.core.iterator.OEmptyIterator)

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