Search in sources :

Example 6 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class DbClosedTest method testRemoteConns.

@Test
public void testRemoteConns() {
    if (!url.startsWith("remote:"))
        return;
    final int max = OGlobalConfiguration.NETWORK_MAX_CONCURRENT_SESSIONS.getValueAsInteger();
    for (int i = 0; i < max * 2; ++i) {
        final ODatabase db = new ODatabaseDocumentTx(url).open("admin", "admin");
        db.close();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabase(com.orientechnologies.orient.core.db.ODatabase) SetupTest(com.orientechnologies.orient.test.database.base.SetupTest)

Example 7 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class OIndexMultiValues method get.

public Set<OIdentifiable> get(Object key) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireSharedLock(key);
    try {
        acquireSharedLock();
        try {
            Set<OIdentifiable> values;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null)
                return Collections.emptySet();
            return Collections.unmodifiableSet(values);
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseSharedLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 8 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class OIndexMultiValues method remove.

@Override
public boolean remove(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 {
            Set<OIdentifiable> values = null;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null) {
                return false;
            }
            final OModifiableBoolean removed = new OModifiableBoolean(false);
            final Callable<Object> creator = new EntityRemover(value, removed, values);
            while (true) try {
                storage.updateIndexEntry(indexId, key, creator);
                break;
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
            return removed.getValue();
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean)

Example 9 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class OIndexMultiValues method put.

public OIndexMultiValues put(Object key, final OIdentifiable singleValue) {
    if (singleValue != null && !singleValue.getIdentity().isPersistent())
        throw new IllegalArgumentException("Cannot index a non persistent record (" + singleValue.getIdentity() + ")");
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive) {
        keyLockManager.acquireExclusiveLock(key);
    }
    try {
        acquireSharedLock();
        try {
            if (!singleValue.getIdentity().isValid())
                (singleValue.getRecord()).save();
            final ORID identity = singleValue.getIdentity();
            final boolean durable;
            if (metadata != null && Boolean.TRUE.equals(metadata.field("durableInNonTxMode")))
                durable = true;
            else
                durable = false;
            Set<OIdentifiable> values = null;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            final Set<OIdentifiable> cvalues = values;
            final Callable<Object> creator = new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    Set<OIdentifiable> result = cvalues;
                    if (result == null) {
                        if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm)) {
                            result = new OIndexRIDContainer(getName(), durable);
                        } else {
                            throw new IllegalStateException("MVRBTree is not supported any more");
                        }
                    }
                    result.add(identity);
                    return result;
                }
            };
            while (true) {
                try {
                    storage.updateIndexEntry(indexId, key, creator);
                    return this;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Callable(java.util.concurrent.Callable)

Example 10 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class OIndexAbstract method remove.

public boolean remove(Object key) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireExclusiveLock(key);
    try {
        acquireSharedLock();
        try {
            while (true) try {
                return storage.removeKeyFromIndex(indexId, key);
            } 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)

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