Search in sources :

Example 1 with OModifiableBoolean

use of com.orientechnologies.common.types.OModifiableBoolean 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 2 with OModifiableBoolean

use of com.orientechnologies.common.types.OModifiableBoolean 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 3 with OModifiableBoolean

use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.

the class OServerCommandGetGephi method execute.

@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
    String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: gephi/<database>/<language>/<query-text>[/<limit>][/<fetchPlan>].<br>Limit is optional and is setted to 20 by default. Set expressely to 0 to have no limits.");
    final String language = urlParts[2];
    final String text = urlParts[3];
    final int limit = urlParts.length > 4 ? Integer.parseInt(urlParts[4]) : 20;
    final String fetchPlan = urlParts.length > 5 ? urlParts[5] : null;
    iRequest.data.commandInfo = "Gephi";
    iRequest.data.commandDetail = text;
    final ODatabaseDocument db = getProfiledDatabaseInstance(iRequest);
    final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
    final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getAnyGraph(shutdownFlag);
    try {
        final Iterable<OrientElement> vertices;
        if (language.equals("sql"))
            vertices = graph.command(new OSQLSynchQuery<OrientVertex>(text, limit).setFetchPlan(fetchPlan)).execute();
        else if (language.equals("gremlin")) {
            List<Object> result = new ArrayList<Object>();
            OGremlinHelper.execute(graph, text, null, null, result, null, null);
            vertices = new ArrayList<OrientElement>(result.size());
            for (Object o : result) {
                ((ArrayList<OrientElement>) vertices).add(graph.getVertex(o));
            }
        } else
            throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'");
        sendRecordsContent(iRequest, iResponse, vertices, fetchPlan);
    } finally {
        if (graph != null && shutdownFlag.getValue())
            graph.shutdown(false, false);
        if (db != null)
            db.close();
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) OrientElement(com.tinkerpop.blueprints.impls.orient.OrientElement) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ArrayList(java.util.ArrayList) List(java.util.List) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean)

Example 4 with OModifiableBoolean

use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.

the class OCommandExecutorSQLDeleteEdge method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLDeleteEdge parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
        // System.out.println("NEW PARSER FROM: " + queryText);
        queryText = preParse(queryText, iRequest);
        // System.out.println("NEW PARSER TO: " + queryText);
        textRequest.setText(queryText);
        init((OCommandRequestText) iRequest);
        parserRequiredKeyword("DELETE");
        parserRequiredKeyword("EDGE");
        OClass clazz = null;
        String where = null;
        String temp = parseOptionalWord(true);
        String originalTemp = null;
        int limit = -1;
        if (temp != null && !parserIsEnded())
            originalTemp = parserText.substring(parserGetPreviousPosition(), parserGetCurrentPosition()).trim();
        final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
        ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.INSTANCE.get();
        final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(false, shutdownFlag);
        try {
            while (temp != null) {
                if (temp.equals("FROM")) {
                    fromExpr = parserRequiredWord(false, "Syntax error", " =><,\r\n");
                    if (rids != null)
                        throwSyntaxErrorException("FROM '" + fromExpr + "' is not allowed when specify a RIDs (" + rids + ")");
                } else if (temp.equals("TO")) {
                    toExpr = parserRequiredWord(false, "Syntax error", " =><,\r\n");
                    if (rids != null)
                        throwSyntaxErrorException("TO '" + toExpr + "' is not allowed when specify a RID (" + rids + ")");
                } else if (temp.startsWith("#")) {
                    rids = new ArrayList<ORecordId>();
                    rids.add(new ORecordId(temp));
                    if (fromExpr != null || toExpr != null)
                        throwSyntaxErrorException("Specifying the RID " + rids + " is not allowed with FROM/TO");
                } else if (temp.startsWith("[") && temp.endsWith("]")) {
                    temp = temp.substring(1, temp.length() - 1);
                    rids = new ArrayList<ORecordId>();
                    for (String rid : temp.split(",")) {
                        rid = rid.trim();
                        if (!rid.startsWith("#")) {
                            throwSyntaxErrorException("Not a valid RID: " + rid);
                        }
                        rids.add(new ORecordId(rid));
                    }
                } else if (temp.equals(KEYWORD_WHERE)) {
                    if (clazz == null)
                        // ASSIGN DEFAULT CLASS
                        clazz = graph.getEdgeType(OrientEdgeType.CLASS_NAME);
                    where = parserGetCurrentPosition() > -1 ? " " + parserText.substring(parserGetCurrentPosition()) : "";
                    if (this.preParsedStatement != null) {
                        StringBuilder builder = new StringBuilder();
                        ((ODeleteEdgeStatement) this.preParsedStatement).getWhereClause().toString(parameters, builder);
                        where = builder.toString();
                    }
                    compiledFilter = OSQLEngine.getInstance().parseCondition(where, getContext(), KEYWORD_WHERE);
                    break;
                } else if (temp.equals(KEYWORD_BATCH)) {
                    temp = parserNextWord(true);
                    if (temp != null)
                        batch = Integer.parseInt(temp);
                } else if (temp.equals(KEYWORD_LIMIT)) {
                    temp = parserNextWord(true);
                    if (temp != null)
                        limit = Integer.parseInt(temp);
                } else if (temp.length() > 0) {
                    // GET/CHECK CLASS NAME
                    label = originalTemp;
                    clazz = graph.getEdgeType(temp);
                    if (clazz == null)
                        throw new OCommandSQLParsingException("Class '" + temp + "' was not found");
                }
                temp = parseOptionalWord(true);
                if (parserIsEnded())
                    break;
            }
            if (where == null)
                if (limit > -1) {
                    where = " LIMIT " + limit;
                } else {
                    where = "";
                }
            else
                where = " WHERE " + where;
            if (fromExpr == null && toExpr == null && rids == null)
                if (clazz == null)
                    // DELETE ALL THE EDGES
                    query = graph.getRawGraph().command(new OSQLAsynchQuery<ODocument>("select from E" + where, this));
                else
                    // DELETE EDGES OF CLASS X
                    query = graph.getRawGraph().command(new OSQLAsynchQuery<ODocument>("select from " + clazz.getName() + where, this));
            return this;
        } finally {
            if (shutdownFlag.getValue())
                graph.shutdown(false, false);
            ODatabaseRecordThreadLocal.INSTANCE.set(curDb);
        }
    } finally {
        textRequest.setText(originalQuery);
    }
}
Also used : OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean)

Example 5 with OModifiableBoolean

use of com.orientechnologies.common.types.OModifiableBoolean in project orientdb by orientechnologies.

the class OCommandExecutorSQLMoveVertex method execute.

/**
   * Executes the command and return the ODocument object created.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (className == null && clusterName == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    OModifiableBoolean shutdownGraph = new OModifiableBoolean();
    final boolean txAlreadyBegun = getDatabase().getTransaction().isActive();
    final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownGraph);
    try {
        final Set<OIdentifiable> sourceRIDs = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), source, context, iArgs);
        // CREATE EDGES
        final List<ODocument> result = new ArrayList<ODocument>(sourceRIDs.size());
        for (OIdentifiable from : sourceRIDs) {
            final OrientVertex fromVertex = graph.getVertex(from);
            if (fromVertex == null)
                continue;
            final ORID oldVertex = fromVertex.getIdentity().copy();
            final ORID newVertex = fromVertex.moveTo(className, clusterName);
            final ODocument newVertexDoc = newVertex.getRecord();
            if (fields != null) {
                // EVALUATE FIELDS
                for (final OPair<String, Object> f : fields) {
                    if (f.getValue() instanceof OSQLFunctionRuntime)
                        f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(newVertex.getRecord(), null, context));
                }
                OSQLHelper.bindParameters(newVertexDoc, fields, new OCommandParameters(iArgs), context);
            }
            if (merge != null)
                newVertexDoc.merge(merge, true, false);
            // SAVE CHANGES
            newVertexDoc.save();
            // PUT THE MOVE INTO THE RESULT
            result.add(new ODocument().setTrackingChanges(false).field("old", oldVertex, OType.LINK).field("new", newVertex, OType.LINK));
            if (batch > 0 && result.size() % batch == 0) {
                graph.commit();
                if (!graph.isAutoStartTx())
                    graph.begin();
            }
        }
        graph.commit();
        return result;
    } finally {
        if (!txAlreadyBegun)
            graph.commit();
        if (shutdownGraph.getValue())
            graph.shutdown(false);
    }
}
Also used : OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ArrayList(java.util.ArrayList) OCommandParameters(com.orientechnologies.orient.core.sql.OCommandParameters) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ORID(com.orientechnologies.orient.core.id.ORID) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)15 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)3 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)3 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)3 ByteBuffer (java.nio.ByteBuffer)3 ODatabase (com.orientechnologies.orient.core.db.ODatabase)2 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)2 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)2 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)2 ArrayList (java.util.ArrayList)2 OPair (com.orientechnologies.common.util.OPair)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ORID (com.orientechnologies.orient.core.id.ORID)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OCommandParameters (com.orientechnologies.orient.core.sql.OCommandParameters)1