Examples of EmbeddedGraphDatabase


Examples of org.neo4j.kernel.EmbeddedGraphDatabase

   */
  @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.kernel.EmbeddedGraphDatabase

public class Neo4jServer {

    private Smack smackServer;
   
    public static void main(String[] args) throws IOException {
        final Neo4jServer neo4jServer = new Neo4jServer(args[0], Integer.parseInt(args[1]), new EmbeddedGraphDatabase(args[2]));
        neo4jServer.start();
        System.in.read();
        neo4jServer.stop();
    }
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

  static final String DB_PATH = "db/neo4j-test-db";

  @Bean(destroyMethod = "shutdown") public EmbeddedGraphDatabase graphDatabaseService() throws IOException {
    FileUtils.deleteRecursively(new File(DB_PATH));
    return new EmbeddedGraphDatabase(DB_PATH);
  }
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

    private Config assertInjected(String testCase) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTest" + testCase + "-context.xml");
        Config config = ctx.getBean("config", Config.class);
        GraphDatabaseContext graphDatabaseContext = config.graphDatabaseContext;
        Assert.assertNotNull("graphDatabaseContext", graphDatabaseContext);
        EmbeddedGraphDatabase graphDatabaseService = (EmbeddedGraphDatabase) graphDatabaseContext.getGraphDatabaseService();
        Assert.assertEquals("store-dir", "target/config-test", graphDatabaseService.getStoreDir());
        Assert.assertNotNull("graphRepositoryFactory",config.graphRepositoryFactory);
        Assert.assertNotNull("graphDatabaseService",config.graphDatabaseService);
        Assert.assertNotNull("transactionManager",config.transactionManager);
        config.graphDatabaseService.shutdown();
        return config;
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

        if (url.startsWith( "file:" )) {
            path = new URI(url).getPath();
        }
        File file = new File( path );
        // if (!file.isDirectory()) file=file.getParentFile();
        return new DelegatingGraphDatabase(new EmbeddedGraphDatabase(file.getAbsolutePath()));
    }
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

    return false;
  }

  @Override
  public GraphDatabaseService graphDatabaseService() {
    return new EmbeddedGraphDatabase("target/neo4j-db");
  }
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

    private Index<Node> nodeIndex, nameIndex;
    private RelationshipIndex friendIndex;
    private int nodeCount, edgeCount;

    public NeoFeeder(String dbpath) {
        db = new EmbeddedGraphDatabase(dbpath);
        nodeIndex = db.index().forNodes(Prop.TWITTER_ID.toString());
        nameIndex = db.index().forNodes(Prop.NAME.toString());
        friendIndex = db.index().forRelationships(TwitterRelationship.FRIEND.toString());
        registerShutdownHook();
    }
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

public class UnderstandDatabase {
  private EmbeddedGraphDatabase graphDB;
 
  public UnderstandDatabase(String path){
    graphDB = new EmbeddedGraphDatabase(path);
  }
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

//    return graphDB;
//  }

  // Get NEO4J RW version
  public static EmbeddedGraphDatabase getGraphDatabase(ServletContext servletContext){
    EmbeddedGraphDatabase graphDB = (EmbeddedGraphDatabase)servletContext.getAttribute(RW_NEO4J);
    if (graphDB == null){
      IOHelper.log("Adding neo4j RW db to servletContext");
      graphDB = new EmbeddedGraphDatabase(Config.get().neo4jDbPath);
      servletContext.setAttribute(RW_NEO4J, graphDB);
    }
    return graphDB;
  }
View Full Code Here

Examples of org.neo4j.kernel.EmbeddedGraphDatabase

  }

  // Search index
  public static Index<Node> getSearchIndex(ServletContext servletContext){
//    EmbeddedReadOnlyGraphDatabase graphDB = getReadOnlyGraphDatabase(servletContext);
    EmbeddedGraphDatabase graphDB = getGraphDatabase(servletContext);
    Index<Node> index = (Index<Node>)servletContext.getAttribute(SEARCH_IDX_GWT);
    if (index == null){
      IOHelper.log("Adding search index - " + SEARCH_IDX_GWT + "- to servletContext.");
      index = graphDB.index().forNodes(SEARCH_IDX_NEO4J,
          MapUtil.stringMap("analyzer", CustomTokenAnalyzer.class.getName())
          );
      ((LuceneIndex<Node>) index).setCacheCapacity("key", 300000);
      servletContext.setAttribute(SEARCH_IDX_GWT,index);
    }
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.