use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OIndexAbstract method contains.
public boolean contains(Object key) {
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireSharedLock(key);
try {
acquireSharedLock();
try {
assert indexId >= 0;
while (true) try {
return storage.indexContainsKey(indexId, key);
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
} finally {
releaseSharedLock();
}
} finally {
if (!txIsActive)
keyLockManager.releaseSharedLock(key);
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OIndexFullText method remove.
/**
* Splits passed in key on several words and remove records with keys equals to any item of split result and values equals to
* passed in value.
*
* @param key Key to remove.
* @param value Value to remove.
*
* @return <code>true</code> if at least one record is removed.
*/
@Override
public boolean remove(Object key, final OIdentifiable value) {
if (key == null)
return false;
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireExclusiveLock(key);
try {
final Set<String> words = splitIntoWords(key.toString());
final OModifiableBoolean removed = new OModifiableBoolean(false);
for (final String word : words) {
acquireSharedLock();
try {
Set<OIdentifiable> recs;
while (true) {
try {
recs = (Set<OIdentifiable>) storage.getIndexValue(indexId, word);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
if (recs != null && !recs.isEmpty()) {
while (true) {
try {
storage.updateIndexEntry(indexId, word, new EntityRemover(recs, value, removed));
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
}
} finally {
releaseSharedLock();
}
}
return removed.getValue();
} finally {
if (!txIsActive)
keyLockManager.releaseExclusiveLock(key);
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OIndexFullText method put.
/**
* Indexes a value and save the index. Splits the value in single words and index each one. Save of the index is responsibility of
* the caller.
*/
@Override
public OIndexFullText put(Object key, final OIdentifiable singleValue) {
if (key == null)
return this;
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireExclusiveLock(key);
try {
final Set<String> words = splitIntoWords(key.toString());
// FOREACH WORD CREATE THE LINK TO THE CURRENT DOCUMENT
for (final String word : words) {
acquireSharedLock();
try {
Set<OIdentifiable> refs;
while (true) {
try {
refs = (Set<OIdentifiable>) storage.getIndexValue(indexId, word);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
final boolean durable;
if (metadata != null && Boolean.TRUE.equals(metadata.field("durableInNonTxMode")))
durable = true;
else
durable = false;
final Set<OIdentifiable> refsc = refs;
// SAVE THE INDEX ENTRY
while (true) {
try {
storage.updateIndexEntry(indexId, word, new Callable<Object>() {
@Override
public Object call() throws Exception {
Set<OIdentifiable> result = null;
if (refsc == null) {
// WORD NOT EXISTS: CREATE THE KEYWORD CONTAINER THE FIRST TIME THE WORD IS FOUND
if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm)) {
result = new OIndexRIDContainer(getName(), durable);
} else {
throw new IllegalStateException("MBRBTreeContainer is not supported any more");
}
} else {
result = refsc;
}
// ADD THE CURRENT DOCUMENT AS REF FOR THAT WORD
result.add(singleValue);
return result;
}
});
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
} finally {
releaseSharedLock();
}
}
return this;
} finally {
if (!txIsActive)
keyLockManager.releaseExclusiveLock(key);
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OIndexDictionary method put.
public OIndexOneValue put(Object key, final OIdentifiable value) {
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.putIndexValue(indexId, key, value);
return this;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
} finally {
releaseSharedLock();
}
} finally {
if (!txIsActive)
keyLockManager.releaseExclusiveLock(key);
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OrientGraphFactoryEncryptionTest method shouldFailWitWrongKey.
@Test
public void shouldFailWitWrongKey() {
ODatabase db = new ODatabaseDocumentTx("plocal:" + dbPath);
db.setProperty(STORAGE_ENCRYPTION_METHOD.getKey(), "des");
db.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.create();
db.close();
OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
storage.close();
OrientGraphFactory graphFactory = new OrientGraphFactory("plocal:" + dbPath);
graphFactory.setProperty(STORAGE_ENCRYPTION_METHOD.getKey(), "des");
graphFactory.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db = graphFactory.getDatabase();
db.command(new OCommandSQL("create class TestEncryption")).execute();
db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
db.close();
storage = ((ODatabaseDocumentInternal) db).getStorage();
graphFactory.close();
storage.close();
// Orient.instance().shutdown();
// Orient.instance().startup();
graphFactory = new OrientGraphFactory("plocal:" + dbPath);
graphFactory.setProperty(STORAGE_ENCRYPTION_METHOD.getKey(), "des");
graphFactory.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db = graphFactory.getDatabase();
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
assertThat(result).hasSize(1);
db.close();
}
Aggregations