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