Java Code Examples for org.neo4j.graphdb.index.IndexHits#close()

The following examples show how to use org.neo4j.graphdb.index.IndexHits#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
public Graph getEdges(int childVertexId, int parentVertexId)
{
    Graph resultGraph = new Graph();
    try( Transaction tx = graphDb.beginTx() )
    {
        IndexHits<Relationship> queryHits = edgeIndex.query("type:*", graphDb.getNodeById(childVertexId), graphDb.getNodeById(parentVertexId));
        for (Relationship currentRelationship : queryHits)
        {
            resultGraph.putVertex(convertNodeToVertex(currentRelationship.getStartNode()));
            resultGraph.putVertex(convertNodeToVertex(currentRelationship.getEndNode()));
            resultGraph.putEdge(convertRelationshipToEdge(currentRelationship));
        }
        queryHits.close();
        tx.success();
    }
    return resultGraph;
}
 
Example 2
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
public Graph getVertices(String expression)
{
    try ( Transaction tx = graphDb.beginTx() )
    {
        Graph resultGraph = new Graph();
        IndexHits<Node> queryHits = vertexIndex.query(expression);
        for (Node foundNode : queryHits)
        {
            resultGraph.putVertex(convertNodeToVertex(foundNode));
        }
        queryHits.close();
        tx.success();
        return resultGraph;
    }
}
 
Example 3
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 4 votes vote down vote up
public Graph getEdges(String childExpression, String parentExpression, String edgeExpression)
{
    Graph resultGraph = new Graph();
    Set<AbstractVertex> childSet = null;
    Set<AbstractVertex> parentSet = null;
    if (childExpression != null)
    {
        if (childExpression.trim().equalsIgnoreCase("null"))
        {
            childExpression = null;
        }
        else
        {
            childSet = getVertices(childExpression).vertexSet();
        }
    }
    if (parentExpression != null)
    {
        if (parentExpression.trim().equalsIgnoreCase("null"))
        {
            parentExpression = null;
        }
        else
        {
            parentSet = getVertices(parentExpression).vertexSet();
        }
    }
    try( Transaction tx = graphDb.beginTx() )
    {
        IndexHits<Relationship> queryHits = edgeIndex.query(edgeExpression);
        for (Relationship foundRelationship : queryHits)
        {
            AbstractVertex childVertex = convertNodeToVertex(foundRelationship.getStartNode());
            AbstractVertex parentVertex = convertNodeToVertex(foundRelationship.getEndNode());
            AbstractEdge tempEdge = convertRelationshipToEdge(foundRelationship);
            if ((childExpression != null) && (parentExpression != null))
            {
                if (childSet.contains(tempEdge.getChildVertex()) && parentSet.contains(tempEdge.getParentVertex()))
                {
                    resultGraph.putVertex(childVertex);
                    resultGraph.putVertex(parentVertex);
                    resultGraph.putEdge(tempEdge);
                }
            }
            else if ((childExpression != null) && (parentExpression == null))
            {
                if (childSet.contains(tempEdge.getChildVertex()))
                {
                    resultGraph.putVertex(childVertex);
                    resultGraph.putVertex(parentVertex);
                    resultGraph.putEdge(tempEdge);
                }
            }
            else if ((childExpression == null) && (parentExpression != null))
            {
                if (parentSet.contains(tempEdge.getParentVertex()))
                {
                    resultGraph.putVertex(childVertex);
                    resultGraph.putVertex(parentVertex);
                    resultGraph.putEdge(tempEdge);
                }
            }
            else if ((childExpression == null) && (parentExpression == null))
            {
                resultGraph.putVertex(childVertex);
                resultGraph.putVertex(parentVertex);
                resultGraph.putEdge(tempEdge);
            }
        }
        queryHits.close();
        tx.success();
    }
    return resultGraph;
}