Search in sources :

Example 26 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase 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 27 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase 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 28 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase 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 29 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase 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)

Aggregations

ODatabase (com.orientechnologies.orient.core.db.ODatabase)29 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)13 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 File (java.io.File)6 List (java.util.List)6 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)5 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)2 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)2 ORID (com.orientechnologies.orient.core.id.ORID)2 IOException (java.io.IOException)2 OCommandExecutor (com.orientechnologies.orient.core.command.OCommandExecutor)1 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)1 ODatabaseListener (com.orientechnologies.orient.core.db.ODatabaseListener)1