Search in sources :

Example 6 with OInvalidIndexEngineIdException

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

the class OIndexMultiValues method remove.

@Override
public boolean remove(Object key, final OIdentifiable value) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireExclusiveLock(key);
    try {
        acquireSharedLock();
        try {
            Set<OIdentifiable> values = null;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null) {
                return false;
            }
            final OModifiableBoolean removed = new OModifiableBoolean(false);
            final Callable<Object> creator = new EntityRemover(value, removed, values);
            while (true) try {
                storage.updateIndexEntry(indexId, key, creator);
                break;
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
            return removed.getValue();
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(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) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean)

Example 7 with OInvalidIndexEngineIdException

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

the class OIndexMultiValues method get.

public Set<OIdentifiable> get(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 Collections.emptySet();
            return Collections.unmodifiableSet(values);
        } 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 8 with OInvalidIndexEngineIdException

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

the class OIndexDictionary method put.

public OIndexOneValue put(Object key, final OIdentifiable value) {
    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.putIndexValue(indexId, key, value);
                    return this;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
        } 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 9 with OInvalidIndexEngineIdException

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

the class OIndexFullText method remove.

/**
   * Splits passed in key on several words and remove records with keys equals to any item of split result and values equals to
   * passed in value.
   *
   * @param key   Key to remove.
   * @param value Value to remove.
   *
   * @return <code>true</code> if at least one record is removed.
   */
@Override
public boolean remove(Object key, final OIdentifiable value) {
    if (key == null)
        return false;
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireExclusiveLock(key);
    try {
        final Set<String> words = splitIntoWords(key.toString());
        final OModifiableBoolean removed = new OModifiableBoolean(false);
        for (final String word : words) {
            acquireSharedLock();
            try {
                Set<OIdentifiable> recs;
                while (true) {
                    try {
                        recs = (Set<OIdentifiable>) storage.getIndexValue(indexId, word);
                        break;
                    } catch (OInvalidIndexEngineIdException e) {
                        doReloadIndexEngine();
                    }
                }
                if (recs != null && !recs.isEmpty()) {
                    while (true) {
                        try {
                            storage.updateIndexEntry(indexId, word, new EntityRemover(recs, value, removed));
                            break;
                        } catch (OInvalidIndexEngineIdException e) {
                            doReloadIndexEngine();
                        }
                    }
                }
            } finally {
                releaseSharedLock();
            }
        }
        return removed.getValue();
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 10 with OInvalidIndexEngineIdException

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

the class OIndexFullText method put.

/**
   * Indexes a value and save the index. Splits the value in single words and index each one. Save of the index is responsibility of
   * the caller.
   */
@Override
public OIndexFullText put(Object key, final OIdentifiable singleValue) {
    if (key == null)
        return this;
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireExclusiveLock(key);
    try {
        final Set<String> words = splitIntoWords(key.toString());
        // FOREACH WORD CREATE THE LINK TO THE CURRENT DOCUMENT
        for (final String word : words) {
            acquireSharedLock();
            try {
                Set<OIdentifiable> refs;
                while (true) {
                    try {
                        refs = (Set<OIdentifiable>) storage.getIndexValue(indexId, word);
                        break;
                    } catch (OInvalidIndexEngineIdException e) {
                        doReloadIndexEngine();
                    }
                }
                final boolean durable;
                if (metadata != null && Boolean.TRUE.equals(metadata.field("durableInNonTxMode")))
                    durable = true;
                else
                    durable = false;
                final Set<OIdentifiable> refsc = refs;
                // SAVE THE INDEX ENTRY
                while (true) {
                    try {
                        storage.updateIndexEntry(indexId, word, new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                Set<OIdentifiable> result = null;
                                if (refsc == null) {
                                    // WORD NOT EXISTS: CREATE THE KEYWORD CONTAINER THE FIRST TIME THE WORD IS FOUND
                                    if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm)) {
                                        result = new OIndexRIDContainer(getName(), durable);
                                    } else {
                                        throw new IllegalStateException("MBRBTreeContainer is not supported any more");
                                    }
                                } else {
                                    result = refsc;
                                }
                                // ADD THE CURRENT DOCUMENT AS REF FOR THAT WORD
                                result.add(singleValue);
                                return result;
                            }
                        });
                        break;
                    } catch (OInvalidIndexEngineIdException e) {
                        doReloadIndexEngine();
                    }
                }
            } finally {
                releaseSharedLock();
            }
        }
        return this;
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) Set(java.util.Set) HashSet(java.util.HashSet) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)

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