Examples of GraphDatabaseService


Examples of org.neo4j.graphdb.GraphDatabaseService

            index.flush();
        }
    }

    private void removeReferenceNodeAndFinalizeKeyIndices() {
        GraphDatabaseService rawGraphDB = null;
        try {
            GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(this.rawGraph.getStoreDir());
            if (this.vertexIndexKeys.size() > 0)
                builder.setConfig(GraphDatabaseSettings.node_keys_indexable, vertexIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.node_auto_indexing, GraphDatabaseSetting.TRUE);
            if (this.edgeIndexKeys.size() > 0)
                builder.setConfig(GraphDatabaseSettings.relationship_keys_indexable, edgeIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.relationship_auto_indexing, GraphDatabaseSetting.TRUE);

            rawGraphDB = builder.newGraphDatabase();
            Transaction tx = rawGraphDB.beginTx();

            try {
                rawGraphDB.getReferenceNode().delete();
                tx.success();
            } catch (Exception e) {
                tx.failure();
            } finally {
                tx.finish();
            }

            GlobalGraphOperations graphOperations = GlobalGraphOperations.at(rawGraphDB);
            if (this.vertexIndexKeys.size() > 0)
                populateKeyIndices(rawGraphDB, rawGraphDB.index().getNodeAutoIndexer(), graphOperations.getAllNodes(), Vertex.class);
            if (this.edgeIndexKeys.size() > 0)
                populateKeyIndices(rawGraphDB, rawGraphDB.index().getRelationshipAutoIndexer(), graphOperations.getAllRelationships(), Edge.class);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        } finally {
            if (rawGraphDB != null) rawGraphDB.shutdown();
        }
    }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            GraphDatabaseService neo4j = ((Neo4j2Graph) graph).getRawGraph();
            int counter = 0;
            this.stopWatch();
            for (final Node node : neo4j.getAllNodes()) {
                counter++;
                for (final Relationship relationship : node.getRelationships(Direction.OUTGOING)) {
                    counter++;
                    final Node node2 = relationship.getEndNode();
                    counter++;
                    for (final Relationship relationship2 : node2.getRelationships(Direction.OUTGOING)) {
                        counter++;
                        final Node node3 = relationship2.getEndNode();
                        counter++;
                        for (final Relationship relationship3 : node3.getRelationships(Direction.OUTGOING)) {
                            counter++;
                            relationship3.getEndNode();
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(neo4j.toString(), counter, "Neo4j raw elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
    }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            GraphDatabaseService neo4j = ((Neo4jGraph) graph).getRawGraph();
            int counter = 0;
            this.stopWatch();
            for (final Node node : neo4j.getAllNodes()) {
                counter++;
                for (final Relationship relationship : node.getRelationships(Direction.OUTGOING)) {
                    counter++;
                    final Node node2 = relationship.getEndNode();
                    counter++;
                    for (final Relationship relationship2 : node2.getRelationships(Direction.OUTGOING)) {
                        counter++;
                        final Node node3 = relationship2.getEndNode();
                        counter++;
                        for (final Relationship relationship3 : node3.getRelationships(Direction.OUTGOING)) {
                            counter++;
                            relationship3.getEndNode();
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(neo4j.toString(), counter, "Neo4j raw elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
    }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

        deleteDirectory(new File(directory));*/
    }

    public void testRollbackExceptionOnBeforeTxCommit() throws Exception {
        Neo4jGraph graph = (Neo4jGraph) graphTest.generateGraph();
        GraphDatabaseService rawGraph = graph.getRawGraph();
        rawGraph.registerTransactionEventHandler(new TransactionEventHandler<Object>() {
            @Override
            public Object beforeCommit(TransactionData data) throws Exception {
                if (true) {
                    throw new RuntimeException("jippo validation exception");
                }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

        deleteDirectory(new File(directory));*/
    }

    public void testRollbackExceptionOnBeforeTxCommit() throws Exception {
        Neo4j2Graph graph = (Neo4j2Graph) graphTest.generateGraph();
        GraphDatabaseService rawGraph = graph.getRawGraph();
        rawGraph.registerTransactionEventHandler(new TransactionEventHandler<Object>() {
            @Override
            public Object beforeCommit(TransactionData data) throws Exception {
                if (true) {
                    throw new RuntimeException("jippo validation exception");
                }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    // START SNIPPET: neo4j
    @Service EmbeddedDatabaseService neo4jService;

    public void doSomething()
    {
        GraphDatabaseService db = neo4jService.database();
        // END SNIPPET: neo4j
        // START SNIPPET: neo4j
    }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    }

    @Test
    public void testDatabase()
    {
        GraphDatabaseService database = module.findService( EmbeddedDatabaseService.class ).get().database();

        {
            Transaction tx = database.beginTx();

            try
            {
                Node rickard = database.createNode();
                rickard.setProperty( "name", "Rickard" );

                Node niclas = database.createNode();
                niclas.setProperty( "name", "Niclas" );

                rickard.createRelationshipTo( niclas, TestRelationships.KNOWS );

                tx.success();
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

            deleteDir(NEO4J_FOLDER);
        }


        //Init Neo4j database
        GraphDatabaseService db = new EmbeddedGraphDatabase(NEO4J_FOLDER);


        //Import OSM data into the Neo4j database
        new OsmImporter(db).importXML(OSM_MAP);


        //Optimize previously loaded database
        GlobalGraphOperations graphOperations = GlobalGraphOperations.at(db);
        System.out.printf("BEFORE OPTIMIZE nodes =  %d  ways = %d  \n", nodesCount(graphOperations), relCount(graphOperations));

        new OsmRoutingOptimizer(db).optimize();
        System.out.printf("AFTER OPTIMIZE nodes =  %d  ways = %d  \n", nodesCount(graphOperations), relCount(graphOperations));


        //Find route
        List<LineString> route = new RouteCalculator().findRoute(getStartNode(db), getEndNode(db));


        //Dump route to KML
        KmlBuilder kmlBuilder = new KmlBuilder();
        kmlBuilder.start();
        kmlBuilder.addPoint(getCoordinate(getStartNode(db)), "START");
        for (LineString lineString : route) {
            kmlBuilder.addLineString(lineString, "");
        }
        kmlBuilder.addPoint(getCoordinate(getEndNode(db)), "FINISH");
        kmlBuilder.finish();
        kmlBuilder.writeToFile(new File("siem-reap.kml"));


        //Close Neo4j
        db.shutdown();

    }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

   */
  @SuppressWarnings("boxing")
  public static void main(String[] args) throws Exception {

    /* Create or load the database content from a filesystem storage */
    final GraphDatabaseService graphDatabase = new EmbeddedGraphDatabase(System.getProperty("user.dir") + "/neo4j-graphdb");

    /* Add a JVM shutdown hook in order to stop cleanly the database */
    Runtime.getRuntime().addShutdownHook(new Thread() {
      /**
       * Stop cleanly the database <br>
       *
       * {@inheritDoc}
       *
       * @see java.lang.Thread#run()
       */
      @Override
      public void run() {
        System.out.print("\n==> Shutdown cleanly the database...");
        graphDatabase.shutdown();
        System.out.println("OK");
      }
    });

    /* Add nodes (members in our sample) and relationships between them */
    // Create graph database nodes using the database reference object
    Node memberA = createNode(graphDatabase, "Dominique");
    Node memberB = createNode(graphDatabase, "Tony");
    Node memberC = createNode(graphDatabase, "Guillaume");
    Node memberD = createNode(graphDatabase, "Sebastien");
    // Link nodes between them by adding relationships
    // ---Relationship owned by the MemberA node
    Relationship r01 = createRelationship(graphDatabase, memberA, memberB, SocialNetworkRelationship.FRIEND);
    Relationship r02 = createRelationship(graphDatabase, memberA, memberC, SocialNetworkRelationship.TEAMMATE);
    // ---Relationship owned by the MemberB node
    Relationship r03 = createRelationship(graphDatabase, memberB, memberC, SocialNetworkRelationship.TEAMMATE);
    // ---Relationship owned by the MemberC node
    Relationship r04 = createRelationship(graphDatabase, memberC, memberB, SocialNetworkRelationship.FRIEND);
    // ---Relationship owned by the MemberD node
    Relationship r05 = createRelationship(graphDatabase, memberD, memberC, SocialNetworkRelationship.FRIEND);
    // Display relationship created above
    System.out.println("*** MEMBERS RELATIONSHIPS CREATED ***");
    displayRelationship(r01);
    displayRelationship(r02);
    displayRelationship(r03);
    displayRelationship(r04);
    displayRelationship(r05);

    /* Perform selections on the graph database */
    System.out.println("\n*** MEMBERS RELATIONSHIPS SELECTION ***");
    // Use a transaction for selections because it's required by Neo4J...
    Transaction transaction = graphDatabase.beginTx();

    // Find a node according to a property value (search for Tony member)
    System.out.println("** Find a node according to a property value (search for Tony member)");
    Iterable<Node> members = graphDatabase.getAllNodes();
    long tonyId = -1;
    for (Node member : members) {
      if (member.hasProperty("MemberName") && "Tony".equals(member.getProperty("MemberName"))) {
        System.out.printf("Tony found, is node ID is %s\n", member.getId());
        tonyId = member.getId();
      }
    }

    // Get all relationships of a specific node (of Tony member in this
    // case)
    System.out.println("** Get all relationships of a specific node (of Tony member in this case)");
    // --Get directory access to the node using is unique ID
    Node tonyNode = graphDatabase.getNodeById(tonyId);
    // --Get is relationships in both directions (from this node to another
    // node (OUTGOING direction name) and another node to this node
    // (INCOMING direction name))
    Iterator<Relationship> relationships = tonyNode.getRelationships(Direction.BOTH).iterator();
    while (relationships.hasNext()) {
      displayRelationship(relationships.next());
    }

    // Use a traverser to traverse all specific relationships that ending to
    // a specific node (our goal here is to find all teamate member of
    // Guillaume)
    System.out.println("** Use a traverser to traverse all specific relationships that ending to a specific node (our goal here is to find all teamate member of Guillaume)");
    Node guillaumeNode = graphDatabase.getNodeById(3);
    Traverser teammates = guillaumeNode.traverse(Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL_BUT_START_NODE, SocialNetworkRelationship.TEAMMATE, Direction.INCOMING);
    for (Node teammateMember : teammates) {
      System.out.printf("%s (NodeID=%s)\n", teammateMember.getProperty("MemberName"), teammateMember.getId());
    }

View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    @Path(UrlReverseLookerUpper.PATH_NODE_RELATIONSHIPS)
    @DeserializeWith(RelationshipCreationDeserializationStrategy.class)
    @SerializeWith(RelationshipSerializationStrategy.class)
    public void createRelationship(Invocation invocation, Output result)
    {
        GraphDatabaseService db = invocation.getDB();
        RelationshipCreationDescription relToCreate = invocation.getContent();
       
        Node from = db.getNodeById(getNodeId(invocation));
        Node to   = db.getNodeById(relToCreate.getEndNodeId());
       
        Relationship rel = from.createRelationshipTo(to, relToCreate.getType());
        setProperties(rel, relToCreate);
       
        result.createdAt(url.reverse(rel), rel);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.