How to connect active neo4j db from java (without REST API )? - neo4j

I have installed neo4j version 1.9.5 and tried some java sample to access / write data into graphdb, but for every action the existing graph db instance is created newly using below,
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("c:/movies/moviesdb"); so is it possible to access and execute cypher query through java on active Neo4j db without REST API concept.
Note : Consider Ne04j DB is already started and running

When running Neo4j as a server process, you communicate with your DB only via REST. The other usage model is embedded. Here you're application code controls the lifecycle of the DB by using new GraphDatabaseFactory().newEmbeddedDatabase(). These two modes are distinct.

Related

Neo4j Desktop - Where are Remote Graphs stored?

I'm new to Neo4j and am learning the Desktop application. I see that I can Add a Database (I can either Create a Local Graph or Connect to a Remote Graph). Creating a local graph obviously means creating a database on my computer, one with it's own bolt://... URL ID of some sort. If instead I Add a Remote Graph, does this imply that I can connect to another local graph stored on my laptop for example if I know its bolt id? I presume I can't but I want to make sure.
Next, if Remote implies stored in the cloud or served somehow, short of setting up a Neo4j instance on AWS or via another 3rd party does Neo4j come with its own easy way to setup a "remote" instance and where would this live? Does Neo have it's own cloud?
Remote Graph implies that there's a running Neo4j instance out there "somewhere" that we can connect to via the bolt URL, similar to how we would connect from a client application using a Neo4j driver (after all, Neo4j Desktop and Neo4j Browser are both client applications and connect via Neo4j drivers).
That might be a server instance somewhere set up by your company, or an instance running from your own laptop (not launched from Desktop), or maybe a Neo4j Aura instance you've set up yourself, or something on AWS or another cloud.
You can't administer remote instances, as bolt connections do not allow for starting/stopping Neo4j or other operations that require command-line access (though 4.0 security administration via the system db is supported).
For the most part though Desktop is agnostic of where or how the remote instance is set up, it just requires a bolt URL that can be used to connect to the instance or cluster.

Identifier of Neo4j database instance

I have several Neo4j databases which I'm using with one Neo4j server. I'm switching these databases (stop server, copy database to required database path, start server).
Is there any way how to identify which database is currently used? Is there any unique ID in neo4j database which I can use? Because I don't see any identifier in Neo4j API.
Yes, I can create node with label "DatabaseId" and store some unique identifier in this node, but I can't add additional data into existing Neo4j database (my application is not permitted to do any changes in Neo4j database).
Yes, I can analyze data in Neo4j database and create some UUID from these data but data in database can be changed by other application from time to time.
Or is there any "system node" in Neo4j database which I can create and this node is not visible for Cypher? Because this type of change of data is acceptable.
Each Neo4j database maintains a internal storeId. You can access it either via neo4j-shell with the following command:
neo4j-sh (?)$ dbinfo -g Kernel StoreId
{"StoreId": "550503bbc2af134e"}
Other option is to use JMX which exposes the same information.

Social Networking Site with Grails and Neo4j

I am developing a social networking website with Grails and MYSQL DB. But I am planning to move to Neo4j DB. Grails supports complete GORM features with MYSQL. But I am sure about the same features in Neo4j. There is a Grails plugin for Neo4j which does not support some of the features that is required to support big websites. So I am planning to use the native Neo4j API. From Grails how to connect to Neo4j DB? There are two scenarios in my case.
Case 1:
Neo4j server is up and running. How to connect and perform the database transactions?
Case 2:
Neo4j server is not running. How to connect and perform the database transactions? I was able to connect using GraphDatabaseService class. But why would one need to connect to DB which is not running. What is this class GraphDatabaseService particularly used for?
I want to use the native Neo4j API to get access to maximum features. Is there a better approach to build the application.
The Grails Neo4j GORM plugin in version 2.0.0.M01 is able to run embedded mode only - so the JVM running the Grails applications spawns the database inside the same JVM. Next milestone (M02) will add support for accessing Neo4j via REST.
In case you don't want to transparently use the GORM methods to talk to Neo4j you can always use direct access by emitting Cypher statements or accessing GraphDatabaseService directly (only on embedded mode of course).

Using Rexter API to interact with Neo4j

Is there a way to interact with a neo4j graph db (running externally HA mode) via Rexter API. Neo4j's REST api is great but using Rexter makes my application completely agnostic of the remote graph db implementation stack. This will enable me to swap in other tinkerpop based graph db stacks like titan without affecting/changing my application code.
You should be able to use the Neo4jHaGraph Blueprints implementation:
https://github.com/tinkerpop/blueprints/wiki/Neo4jHa-Implementation
Here's some instructions for connecting using Rexster:
https://github.com/tinkerpop/rexster/wiki/Specific-Graph-Configurations#neo4j-high-availability-cluster

Runs multiple web application with same embedded neo4j db

It is required to run multiple application on same neo4j db. But when I try to do that, I am meeting a problem about locking.
Neo4j is locking itself when an application is using it. Multiple application can't be run.
The exception is like,
Unable to lock store [/opt/neo4j-lojika-db/neostore.relationshiptypestore.db.names], this is usually a result of some other Neo4j kernel running using the same store
Is there a way to run multiple web application with same embedded neo4j db.
Thank you!
You can't do this way. You have two options
Use Neo4j HA or
Run Neo4j in server mode rather than embedded mode. If your application is simple then you can use the REST api provided by Neo4j out of box. If your service layer is more involved then, put a service layer on top of a single Neo4j embedded instance and let each application talk to Neo4j through this service layer.

Resources