Search in sources :

Example 11 with ODatabase

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);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 12 with ODatabase

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);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 13 with ODatabase

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);
    }
}
Also used : OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) Set(java.util.Set) HashSet(java.util.HashSet) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)

Example 14 with ODatabase

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);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 15 with ODatabase

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();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabase(com.orientechnologies.orient.core.db.ODatabase) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ODatabase (com.orientechnologies.orient.core.db.ODatabase)29 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)13 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 File (java.io.File)6 List (java.util.List)6 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)5 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)2 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)2 ORID (com.orientechnologies.orient.core.id.ORID)2 IOException (java.io.IOException)2 OCommandExecutor (com.orientechnologies.orient.core.command.OCommandExecutor)1 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)1 ODatabaseListener (com.orientechnologies.orient.core.db.ODatabaseListener)1