use of com.orientechnologies.orient.core.index.OIndexEngine in project orientdb by orientechnologies.
the class OHashIndexFactory method createIndexEngine.
@Override
public OIndexEngine createIndexEngine(final String algoritm, final String name, final Boolean durableInNonTxMode, final OStorage storage, final int version, final Map<String, String> engineProperties) {
OIndexEngine indexEngine;
final String storageType = storage.getType();
if (storageType.equals("memory") || storageType.equals("plocal"))
indexEngine = new OHashTableIndexEngine(name, durableInNonTxMode, (OAbstractPaginatedStorage) storage, version);
else if (storageType.equals("distributed"))
// DISTRIBUTED CASE: HANDLE IT AS FOR LOCAL
indexEngine = new OHashTableIndexEngine(name, durableInNonTxMode, (OAbstractPaginatedStorage) storage.getUnderlying(), version);
else if (storageType.equals("remote"))
indexEngine = new ORemoteIndexEngine(name);
else
throw new OIndexException("Unsupported storage type: " + storageType);
return indexEngine;
}
use of com.orientechnologies.orient.core.index.OIndexEngine 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.orient.core.index.OIndexEngine in project orientdb by orientechnologies.
the class OLuceneIndexNotUnique method commitSnapshot.
@Override
protected void commitSnapshot(final Map<Object, Object> snapshot) {
while (true) try {
storage.callIndexEngine(false, false, indexId, new OIndexEngineCallback<Object>() {
@Override
public Boolean callEngine(OIndexEngine engine) {
OLuceneIndexEngine indexEngine = (OLuceneIndexEngine) engine;
for (Map.Entry<Object, Object> snapshotEntry : snapshot.entrySet()) {
Object key = snapshotEntry.getKey();
OLuceneTxOperations operations = (OLuceneTxOperations) snapshotEntry.getValue();
for (OIdentifiable oIdentifiable : operations.removed) {
indexEngine.remove(decodeKey(key), oIdentifiable);
}
}
for (Map.Entry<Object, Object> snapshotEntry : snapshot.entrySet()) {
Object key = snapshotEntry.getKey();
OLuceneTxOperations operations = (OLuceneTxOperations) snapshotEntry.getValue();
indexEngine.put(decodeKey(key), operations.added);
}
OTransaction transaction = getDatabase().getTransaction();
resetTransactionChanges(transaction);
return null;
}
});
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
use of com.orientechnologies.orient.core.index.OIndexEngine 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.index.OIndexEngine 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