use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException 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.exception.OInvalidIndexEngineIdException in project orientdb by orientechnologies.
the class OIndexOneValue 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();
@Override
public Map.Entry<Object, OIdentifiable> nextEntry() {
OIdentifiable result = null;
Object key = null;
while (keysIterator.hasNext() && result == null) {
key = keysIterator.next();
key = getCollatingValue(key);
acquireSharedLock();
try {
while (true) try {
result = (OIdentifiable) storage.getIndexValue(indexId, key);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
} finally {
releaseSharedLock();
}
}
if (result == null)
return null;
final Object resultKey = key;
final OIdentifiable resultValue = result;
return new Map.Entry<Object, OIdentifiable>() {
@Override
public Object getKey() {
return resultKey;
}
@Override
public OIdentifiable getValue() {
return resultValue;
}
@Override
public OIdentifiable setValue(OIdentifiable value) {
throw new UnsupportedOperationException("setValue");
}
};
}
};
}
use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException 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);
}
}
use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException in project orientdb by orientechnologies.
the class OLuceneIndexNotUnique method onIndexEngineChange.
@Override
protected void onIndexEngineChange(int indexId) {
while (true) try {
storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Object>() {
@Override
public Object callEngine(OIndexEngine engine) {
OLuceneIndexEngine oIndexEngine = (OLuceneIndexEngine) engine;
oIndexEngine.init(getName(), getType(), getDefinition(), isAutomatic(), getMetadata());
return null;
}
});
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
use of com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException in project orientdb by orientechnologies.
the class OLuceneIndexNotUnique method remove.
@Override
public boolean remove(final Object key, final OIdentifiable value) {
if (key != null) {
OTransaction transaction = getDatabase().getTransaction();
if (transaction.isActive()) {
transaction.addIndexEntry(this, super.getName(), OTransactionIndexChanges.OPERATION.REMOVE, encodeKey(key), value);
OLuceneTxChanges transactionChanges = getTransactionChanges(transaction);
try {
transactionChanges.remove(key, value);
} catch (IOException e) {
OLogManager.instance().error(this, "Error while removing", e);
}
return true;
} else {
while (true) {
try {
return storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Boolean>() {
@Override
public Boolean callEngine(OIndexEngine engine) {
OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine;
return indexEngine.remove(key, value);
}
});
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
}
}
return true;
}
Aggregations