2013-08-25 2 views
0

트리의 노드 중 하나를 루트 노드로 설정하려면 어떻게해야합니까? 내 인덱스는 115에서 시작한다고 가정 해 봅시다. 그러나 도트 넷 어플리케이션에서 Neo4jClient를 사용하여 db에 연결할 때 루트 노드를 null로 가져 오는 중입니까? 노드를 루트 노드로 설정할 수 있습니까?Neo4j 그래프 DB에서 RootNode를 생성/설정 하시겠습니까?

답변

1

표준 API를 사용할 수 없지만 일부 자바 코드를 실행할 수 있다고 가정하면 약간의 트릭이 있습니다. 그것은 당신이 새로운 루트 노드를 만들 수있게 해줍니다. 노드 ID를 변경할 방법이 없다고 생각합니다.

public class RootNodeCreator { 

    /** 
    * Create the root node. Make sure the database is stopped when running this. 
    * 
    * @param pathToDatabase path to the database. 
    */ 
    public void createRoot(String pathToDatabase) { 
     BatchInserter inserter = BatchInserters.inserter(pathToDatabase); 
     inserter.createNode(0, new HashMap<String, Object>()); 
     inserter.shutdown(); 
    } 
} 

및 시험 :

@Test 
public void verifyRootCreation() throws IOException { 
    TemporaryFolder temporaryFolder = new TemporaryFolder(); 
    temporaryFolder.create(); 

    GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(temporaryFolder.getRoot().getAbsolutePath()); 
    Transaction tx = database.beginTx(); 
    try { 
     database.getNodeById(0).delete(); 
     tx.success(); 
    } 
    finally { 
     tx.finish(); 
    } 


    try { 
     database.getNodeById(0); 
     fail(); 
    } catch (NotFoundException e) { 
     //ok 
    } 

    database.shutdown(); 

    new RootNodeCreator().createRoot(temporaryFolder.getRoot().getAbsolutePath()); 

    database = new GraphDatabaseFactory().newEmbeddedDatabase(temporaryFolder.getRoot().getAbsolutePath()); 
    assertNotNull(database.getNodeById(0)); 
} 
0

이 Neo4jClient 지원하는 것이 가능하지 REST API를 통해 불가능합니다.

관련 문제