How can I refer my Neo4j embedded Db to getGraphDb() method? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How can I refer my Neo4j embedded Db to getGraphDb() method? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I want to develop a piece of software that helps the user to open and close a Neo4j embedded server within my java application. Practically, I click the button and the web admin tool should be opened in the default web browser. However, I am stuck because I have a problem with the line code

InternalAbstractGraphDatabase graphdb = getGraphDb();

I don’t understand how to open my implemented db which is in the variable:

 private static GraphDatabaseService BORO_DB;

and has path:

public static String DB_PATH;

Below the code:

final Variable var = new Variable(true);

InternalAbstractGraphDatabase graphdb = getGraphDb();
final WrappingNeoServerBootstrapper srv;
srv = new WrappingNeoServerBootstrapper( graphdb );

final JButton btnNewButton = new JButton("Show Graph - Start Server");
btnNewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {

        if (var.getVar()){
            var.setVar(false);
            btnNewButton.setText("Graph - Stop Server");
            srv.start();

               try {

                 String url = "http://localhost:7474";
                 java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
               }
               catch (java.io.IOException e) {
                   System.out.println(e.getMessage());
               }

        }else{
            var.setVar(true);
            btnNewButton.setText("Show Graph - Start Server");
            srv.stop();
        }   
    }
});

May you teach me how to link my DB (BORO_DB) to getGraphDb()?

Thank you

Answer

Using DB_PATH, you can instantiate BORO_DB like this:

BORO_DB = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);

srv=new WrappingNeoServerBootstrapper((GraphDatabaseAPI) BORO_DB);
We are here to answer your question about How can I refer my Neo4j embedded Db to getGraphDb() method? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji