Search in sources :

Example 56 with OrientGraph

use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.

the class OCommandExecutorSQLDeleteVertex method result.

/**
   * Delete the current vertex.
   */
public boolean result(final Object iRecord) {
    final OIdentifiable id = (OIdentifiable) iRecord;
    if (id.getIdentity().isValid()) {
        final ODocument record = id.getRecord();
        final OrientBaseGraph g = currentGraph.get();
        final OrientVertex v = g.getVertex(record);
        if (v != null) {
            v.remove();
            if (!txAlreadyBegun && batch > 0 && removed % batch == 0) {
                if (g instanceof OrientGraph) {
                    g.commit();
                    ((OrientGraph) g).begin();
                }
            }
            if (returning.equalsIgnoreCase("BEFORE"))
                allDeletedRecords.add(record);
            removed++;
        }
    }
    return true;
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 57 with OrientGraph

use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.

the class OGraphCommandExecutorSQLFactory method runInTx.

public static <T> T runInTx(final GraphCallBack<T> callBack) {
    final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
    final ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.INSTANCE.get();
    final boolean txAlreadyBegun = curDb.getTransaction().isActive();
    final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownFlag);
    try {
        return runInTx(graph, callBack);
    } finally {
        if (!txAlreadyBegun) {
            graph.commit();
            if (shutdownFlag.getValue())
                graph.shutdown(false, false);
        }
        ODatabaseRecordThreadLocal.INSTANCE.set(curDb);
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 58 with OrientGraph

use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.

the class OGraphCommandExecutorSQLFactory method getGraph.

/**
   * Returns a Transactional OrientGraph implementation from the current database in thread local.
   *
   * @param autoStartTx
   *          Whether returned graph will start transaction before each operation till commit automatically or user should do it
   *          explicitly be calling {@link OrientGraph#getRawGraph()} method {@link ODatabaseDocumentTx#begin()}.
   *
   * @return Transactional OrientGraph implementation from the current database in thread local.
   */
public static OrientGraph getGraph(final boolean autoStartTx, OModifiableBoolean shouldBeShutDown) {
    final ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.get();
    final OrientBaseGraph result = OrientBaseGraph.getActiveGraph();
    if (result != null && (result instanceof OrientGraph)) {
        final ODatabaseDocumentTx graphDb = result.getRawGraph();
        // CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT
        if (canReuseActiveGraph(graphDb, database)) {
            if (!graphDb.isClosed()) {
                ODatabaseRecordThreadLocal.INSTANCE.set(graphDb);
                if (autoStartTx && autoTxStartRequired(graphDb))
                    ((OrientGraph) result).begin();
                shouldBeShutDown.setValue(false);
                return (OrientGraph) result;
            }
        }
    }
    // Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local
    ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseDocumentInternal) database);
    shouldBeShutDown.setValue(true);
    final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database, false);
    if (autoStartTx && autoTxStartRequired(database))
        g.begin();
    return g;
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 59 with OrientGraph

use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.

the class OSQLFunctionHeuristicPathFinderAbstract method getCustomHeuristicCost.

protected double getCustomHeuristicCost(final String functionName, final String[] vertextAxisNames, final OrientVertex start, final OrientVertex goal, final OrientVertex current, final OrientVertex parent, final long depth, double dFactor) {
    double heuristic = 0.0;
    OrientGraph ff;
    OFunction func = OrientGraph.getActiveGraph().getRawGraph().getMetadata().getFunctionLibrary().getFunction(functionName);
    Object fValue = func.executeInContext(context, vertextAxisNames, start, goal, current, parent, depth, dFactor);
    if (fValue != null && fValue instanceof Number) {
        heuristic = doubleOrDefault(fValue, heuristic);
    }
    return heuristic;
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OFunction(com.orientechnologies.orient.core.metadata.function.OFunction)

Example 60 with OrientGraph

use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.

the class IndexTest method testIndexEdgeComposite.

public void testIndexEdgeComposite() {
    OrientGraph graphNoTx = new OrientGraph((ODatabaseDocumentTx) database.getUnderlying());
    OrientVertexType vertexType = null;
    if (!graphNoTx.getRawGraph().existsCluster("CustomVertex")) {
        vertexType = graphNoTx.createVertexType("CustomVertex");
    } else {
        vertexType = graphNoTx.getVertexType("CustomVertex");
    }
    if (!graphNoTx.getRawGraph().existsCluster("CustomEdge")) {
        OrientEdgeType edgeType = graphNoTx.createEdgeType("CustomEdge");
        edgeType.createProperty("out", OType.LINK, vertexType);
        edgeType.createProperty("in", OType.LINK, vertexType);
        edgeType.createIndex("CustomEdge.in", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "in" });
        edgeType.createIndex("CustomEdge.out", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "out" });
        edgeType.createIndex("CustomEdge.compositeInOut", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "out", "in" });
    }
    // graphNoTx.shutdown();
    OrientGraph graph = new OrientGraph((ODatabaseDocumentTx) database.getUnderlying());
    Vertex inVert = null;
    for (int i = 0; i < 5; ++i) {
        Vertex currentVert = graph.addVertex("class:CustomVertex");
        if (inVert != null) {
            graph.addEdge("class:CustomEdge", currentVert, inVert, "CustomEdge");
        }
        inVert = currentVert;
    }
    graph.commit();
    Iterable<Vertex> verts = graph.getVertices();
    StringBuilder vertIds = new StringBuilder();
    for (Vertex vert : verts) {
        vertIds.append(vert.getId().toString()).append(" ");
    }
    System.out.println("Vertices: " + vertIds);
    System.out.println();
    checkIndexKeys(graph, "CustomEdge.in");
    checkIndexKeys(graph, "CustomEdge.out");
    checkIndexKeys(graph, "CustomEdge.compositeInOut");
}
Also used : OrientEdgeType(com.tinkerpop.blueprints.impls.orient.OrientEdgeType) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)94 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)43 Test (org.junit.Test)33 Vertex (com.tinkerpop.blueprints.Vertex)22 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)18 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)12 Edge (com.tinkerpop.blueprints.Edge)8 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)7 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)7 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)7 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)6 Test (org.testng.annotations.Test)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4