Reputation: 1
How do i set one of the node in the tree as a Root node ? Let say my index starts from 115, but when i am connecting to the db using Neo4jClient in dot net application am getting the root node as null ? Is it possible to set any node as root node ?
Upvotes: 0
Views: 487
Reputation: 4290
This is not possible via the REST API, and thus not possible for Neo4jClient to support.
Upvotes: 0
Reputation: 2661
It's not possible using the standard API, but here's a little trick, assuming you can run some Java code. It allows you to create a new root node, I don't think there's a way to change node IDs.
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();
}
}
and a test:
@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));
}
Upvotes: 1