Package org.neo4j.kernel

Examples of org.neo4j.kernel.EmbeddedGraphDatabase


            switch (type) {
                case IN_MEMORY:
                    instance = new ContextTrackingServiceImpl(new ImpermanentGraphDatabase(defaultDB));
                    break;
                case EMBEDDED:
                    instance = new ContextTrackingServiceImpl(new EmbeddedGraphDatabase(defaultDB));
                    break;
                case REST:
                    instance = new ContextTrackingServiceRest(SERVER_BASE_URL);
                    break;
                default:
View Full Code Here


    private static enum RelTypes implements RelationshipType {
        KNOWS, OWNED
    }

    private void initDatabase() {
        graphDb = new EmbeddedGraphDatabase(new File("mydb").getAbsolutePath());
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                System.out.println("shutting down the database");
                graphDb.shutdown();
            }
View Full Code Here

    this.databaseDirectory = configuredDirectory!= null ? configuredDirectory: "/tmp/database";
  }
 
  @PostConstruct
  public void initialize() {
    db = new EmbeddedGraphDatabase(databaseDirectory);
  }
View Full Code Here

    private static AbstractGraphDatabase graphDatabase;
    private static NeoServer neoServer;

    @BeforeClass
    public static void startServerWithACleanDb() {
        graphDatabase = new EmbeddedGraphDatabase("target/db1");

        ServerConfigurator config = new ServerConfigurator(graphDatabase);
        config.configuration().setProperty("org.neo4j.server.thirdparty.delete.key", "secret-key");
        config.getThirdpartyJaxRsClasses().add(new ThirdPartyJaxRsPackage("org.neo4j.server.extension.test.delete", "/cleandb"));
View Full Code Here

    public Neo4jGraph(final String directory, final Map<String, String> configuration) {
        boolean fresh = !new File(directory).exists();
        try {
            if (null != configuration)
                this.rawGraph = new EmbeddedGraphDatabase(directory, configuration);
            else
                this.rawGraph = new EmbeddedGraphDatabase(directory);

            if (fresh)
                this.freshLoad();

            this.loadKeyIndices();
View Full Code Here

         if (fileConfiguration != null)
            path = new File(fileConfiguration.dataDirectory(), config.get().identity().get()).getAbsolutePath();
         else
            path = "build/neodb";
      }
      neo = new EmbeddedGraphDatabase(path);
      indexService = new LuceneIndexService(neo);
      uuid = UUID.randomUUID().toString() + "-";
   }
View Full Code Here

        @Override
        public void startDatabase()
            throws Exception
        {
            String path = new File( config.dataDirectory(), identity().get() ).getAbsolutePath();
            db = new EmbeddedGraphDatabase( path );
        }
View Full Code Here

            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

        if(newDb){
            clearDb();
        }
        // START SNIPPET: startDb
        //graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
        graphDb = new EmbeddedGraphDatabase( DB_PATH );  
        ID_KEY = idKey;
        idIndex = graphDb.index().forNodes(ID_KEY);
        registerShutdownHook( graphDb );
        // END SNIPPET: startDb     
    }
View Full Code Here

   */
  @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

TOP

Related Classes of org.neo4j.kernel.EmbeddedGraphDatabase

Copyright © 2018 www.massapicom. 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.