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);
}
}
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);
}
}
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();
}
}
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);
}
}
Aggregations