use of com.orientechnologies.lucene.tx.OLuceneTxChanges in project orientdb by orientechnologies.
the class OLuceneIndexNotUnique method put.
@Override
public OLuceneIndexNotUnique put(final Object key, final OIdentifiable singleValue) {
if (key != null) {
OTransaction transaction = getDatabase().getTransaction();
if (transaction.isActive()) {
OLuceneTxChanges transactionChanges = getTransactionChanges(transaction);
transaction.addIndexEntry(this, super.getName(), OTransactionIndexChanges.OPERATION.PUT, encodeKey(key), singleValue);
Document luceneDoc;
while (true) {
try {
luceneDoc = storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Document>() {
@Override
public Document callEngine(OIndexEngine engine) {
OLuceneIndexEngine oIndexEngine = (OLuceneIndexEngine) engine;
return oIndexEngine.buildDocument(key, singleValue);
}
});
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
try {
transactionChanges.put(key, singleValue, luceneDoc);
} catch (IOException e) {
e.printStackTrace();
}
} else {
while (true) {
try {
storage.updateIndexEntry(indexId, key, new Callable<Object>() {
@Override
public Object call() throws Exception {
return Arrays.asList(singleValue);
}
});
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
}
}
return this;
}
use of com.orientechnologies.lucene.tx.OLuceneTxChanges 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