Neo4j visualizing and retrieving data - java

Starting to use Neo4j embedded with my JAVA web server. While saving the data the transaction was successful, but not able to visualize the data via browser.
Have tried sample Hello world from tutorial. And installed neo4j community edition, after pointing to DB and navigating to http://localhost:7474/browser/ i don't see any data.
Also, when i stop the application and run Cypher query via Java not getting any data.
Maven dependency used
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.3.1</version>
</dependency>
Sample code written
try {
Transaction tx = graphDb.beginTx();
firstNode = graphDb.createNode();
firstNode.setProperty( "message", "Hello, " );
secondNode = graphDb.createNode();
secondNode.setProperty( "message", "World!" );
relationship = firstNode.createRelationshipTo( secondNode, RelTypes.KNOWS );
relationship.setProperty( "message", "brave Neo4j " );
tx.success();
}
DB path for embedded as well as server is same.

I do not know exact root of the issue. But I have checklist, that should be verified.
1) You application and Neo4j server should use same database. When you are creating embdedded database via GraphDatabaseFactory you are specifying database location. Same database location should be specified for Neo4j server in conf/neo4j-server.properties file (org.neo4j.server.database.location option).
2) You should NOT use database simultaneously in server and application. Database can be used only by one Neo4j instance at a time.
3) Use try-with-resource syntax for transactions. It is available in Java7 and later. Example:
try (Transaction tx = db.beginTx()) {
// do stuff
tx.success();
}
In this way transaction will be always closed, in any case (even if exception occurs during execution, or in beginTx()).
4) Ensure that your database is closed in “clean way”. In application it can be done via db.shutdown() method. Server can be stopped via bin/neo4j stop.

Related

Getting java.sql.SQLException: Routine (cdc_endcapture) can not be resolved while initializing IfxCDCEngine builder on Informix Change Stream Client

Tried out this code for Informix Change Streams API for Java . from https://informix.hcldoc.com/14.10/help/index.jsp?topic=%2Fcom.ibm.cdc.doc%2Fids_cdc_streamapi.htm
I Keep on getting this error .Is there any fix for this or solution??
16:03:57.054 [main] DEBUG com.informix.stream.cdc.IfxCDCEngine - Closing down CDC engine
Exception in thread "main" java.sql.SQLException: Routine (cdc_opensess) can not be resolved.
at com.informix.util.IfxErrMsg.buildExceptionWithMessage(IfxErrMsg.java:422)
at com.informix.util.IfxErrMsg.buildIsamException(IfxErrMsg.java:401)
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3022)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3273)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2269)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2194)
at com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1194)
at com.informix.jdbc.IfxPreparedStatement.setupExecutePrepare(IfxPreparedStatement.java:245)
at com.informix.jdbc.IfxCallableStatement.<init>(IfxCallableStatement.java:143)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:5924)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:2499)
at com.informix.stream.cdc.IfxCDCEngine.init(IfxCDCEngine.java:177)
at com.example.informixchangestream.demo.CDCExDemoApplicationample.main(CDCExDemoApplicationample.java:33)
Suppressed: com.informix.stream.impl.IfxStreamException: Unable to end cdc capture
at com.informix.stream.cdc.IfxCDCEngine.endCapture(IfxCDCEngine.java:295)
at com.informix.stream.cdc.IfxCDCEngine.unwatchTable(IfxCDCEngine.java:275)
at com.informix.stream.cdc.IfxCDCEngine.close(IfxCDCEngine.java:343)
at com.example.informixchangestream.demo.CDCExDemoApplicationample.main(CDCExDemoApplicationample.java:52)
Caused by: java.sql.SQLException: Routine (cdc_endcapture) can not be resolved.
at com.informix.util.IfxErrMsg.buildExceptionWithMessage(IfxErrMsg.java:422)
at com.informix.util.IfxErrMsg.buildIsamException(IfxErrMsg.java:401)
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3022)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3273)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2269)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2194)
at com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1194)
at com.informix.jdbc.IfxPreparedStatement.setupExecutePrepare(IfxPreparedStatement.java:245)
at com.informix.jdbc.IfxCallableStatement.<init>(IfxCallableStatement.java:143)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:5924)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:2499)
at com.informix.stream.cdc.IfxCDCEngine.endCapture(IfxCDCEngine.java:282)
... 3 more
My code looks like this :
try (IfxCDCEngine engine = builder.build()) {
// initialize the engine (creates the connections and begins listening for
// changes)
engine.init();
IfmxStreamRecord record = null;
// This loop is where you can inject logic that compiles
// transactions, look for commits, throw away rollbacks
// The data here is all Java typed, so it can be easily then
// sent to MQTT, other JDBC drivers, streaming engines, or anything
// else you can think of.
while ((record = engine.getRecord()) != null) {
// Print out the basic record information
System.out.println("record changed");
System.out.println(record);
// If it is an insert/update/delete, print the column data
if (record.hasOperationData()) {
System.out.println("operation data");
System.out.println(((IfxCDCOperationRecord) record).getData());
}
}
}
This error is happens when the CDC routines are not found. Make sure that you first run the CDC setup script with the server to create the syscdcv1 database.
Then make sure your DataSource connects to the syscdcv1 database when you try CDC operations. It's not intuitive, but you 'connect' to the syscdcv1 database, then add watchers on databases and tables you are interested in getting the changes for.
Documentation on the CDC setup on the server is here, you need step #2 at least.
https://informix.hcldoc.com/14.10/help/index.jsp?topic=%2Fcom.ibm.cdc.doc%2Fids_cdc_streamapi.htm
A working example can be found here with a README and java code that you can use that might be easier to follow than the pages of the official docs
https://github.com/informix/informix-db-examples/tree/master/streaming/cdc

Troubleshooting oracle database errors from cloud application

I am trying to troubleshoot an issue that presents as different database errors such as, ORA-01000: maximum open cursors exceeded or Unable to create DB Connection. I have reviewed the PLSQL to determine if cursors were left open and all are closed even if there is an error.
The java application and background are as follows:
The original application was a 3-tiered system:
GUI app. -> server app -> 11g Oracle database
The enhancement was to add an API service in a Pivotal Cloud Foundry (PCF) environment.
So this architecture was like this:
Close Function: GUI app -> Server App -> API service -> Database.
All other Functions: GUI app -> Server App -> Database.
This was put into production and run for a week without any database issues described above.
Then another enhancement was added in which the API Service communicates with several other services all in PCF in which 2 communicate with the same oracle database. Now during heavy volume we are getting these database errors.
It seems to me that the Oracle database cannot keep up with the requests from these additional services. But how can I demonstrate that. We have AppD configured for the servers but not the database. Are there queries that I can run in the prod env. that shows that these PCF applications are causing the issue? Or should I look in another area?
Thanks,
UPDATE
I looked at the legacy application and the result sets are closed. The other 3 PCF applications use Spring Boot to connect to the database. From my understanding, closing connections and result sets do not have to be explicitly closed. JDBCTemplate closes these connections/result sets. The PLSQL added has an additional cursor which is closed on success and exception.
UPDATE
I created a query that shows the total open cursor by sessionID
This is the query:
select b.sid, b.username, b.osuser, sum(a.value) total_opened_current_cursors
from sys.v_$statname c,
sys.v_$sesstat a,
sys.v_$session b
where a.statistic#=c.statistic# and
b.sid=a.sid and
c.name in ('opened cursors current') and
(b.username is not null or b.username <> '' )
group by b.sid, b.username, b.osuser
order by total_opened_current_cursors desc
Now, I need to link the sessionID with the application that has this session.
The osuser for the top ones is NULL.
Also, most of the sessions' status are INACTIVE
How to identify the application to the session?
Secondly, is the session is inactive, which I thought meant that no query is happening so why are there open cursors?
**UPDATE**
So, I wrote a query that returns the top 10 sessions with the highest open cursors
select *
FROM
(
select b.sid, b.username, b.osuser, b.status, sum(a.value) total_opened_current_cursors
from sys.v_$statname c,
sys.v_$sesstat a,
sys.v_$session b
where a.statistic#=c.statistic# and
b.sid=a.sid and
c.name in ('opened cursors current') and
(b.username is not null or b.username <> '' )
group by b.sid, b.username, b.osuser, b.status
order by total_opened_current_cursors desc
)
WHERE ROWNUM <= 10;
I found the SQL_TEXT that accounts for most of the open cursors...by far! (87%)
So, how do I find the query that calls this SQL?
There are at least 5 services that hit the database. Some of the services call PLSQL stored procedures some call raw SQL text. The query that accounts for the open cursors is listed as a SELECT statement. Does that mean it is NOT a stored procedure? Or can this SELECT be called within the stored procedures.
How do I find the connection that uses this session?

How to save to Cassandra from java?

I am new to Cassandra and i am working on a project that uses Cassandra as DB. The Cassandra is installed in another device and i will have to save it to the db remotely.
I have little knowledge about Cassandra and its functionality but I'm good with MySQL.
What are the steps to save a message into Cassandra?
Can I use the same database that I used with MySQL?
I believe that I will have to connect to the Cassandra Server and then save it.
Cluster cluster = Cluster.builder().addContactPoint("localhost").withPort(3306).build();
I have used this statement to connect to Cassandra. (replacing localhost to the ip of the device)
Your best bet here is to start with the java driver docs. If you use maven its quite easy to setup, but I often find the examples don't always give a full pom.xml so you can use some of the examples in the github project
The quick start guide gives a very simple example:
Cluster cluster = null;
try {
cluster = Cluster.builder()
.addContactPoint("127.0.0.1")
.build();
Session session = cluster.connect();
ResultSet rs = session.execute("select release_version from system.local");
Row row = rs.one();
System.out.println(row.getString("release_version"));
} finally {
if (cluster != null) cluster.close();
}
Some other items of interest are the connection pooling and load balancing
Create a session with the cluster created and the keyspace:
Session session = cluster.connect("keyspace");
create keyspace if u don't have one.
then use
session.execute(query);
to execute any query of your choice.
query has to be string and not null.
eg:
String query= "INSERT INTO keyspace.table_name (id, lastname, firstname) VALUES (6ab09bec-e68e-48d9-a5f8-97e6fb4c9b47, 'KRUIKSWIJK','Steven');";
session.execute(query);

Couchbase Client Configuration for enhanced durability

I am trying to implement ATPlus scan consistency within my couchbase java application. I have updated my queries to include the consistentWith(mutationState):
RawJsonDocument courseJsonDocument = toRawJsonDocument(course, true);
RawJsonDocument insertedJsonDocument = bucket.insert(courseJsonDocument);
MutationState insertMutationState = MutationState.from(insertedJsonDocument);
.....
N1qlQuery.simple(GET_COURSE_BY_ID_QUERY, N1qlParams.build().consistentWith(mutationState));
I'm trying to achieve read-your-own-write, but when I run the query immediately after inserting the document, nothing is found, so I must be doing something wrong. I think what I am missing is actually enabling enhanced durability on the client configuration.
I see examples of how to do it in .NET, but I can't figure out how to 'enable enhanced durability' in JAVA. Here is my cluster configuration:
Cluster cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder()
.queryServiceConfig(QueryServiceConfig.create(1, 100))
.mutationTokensEnabled(true)
.observeIntervalDelay(Delay.fixed(100, TimeUnit.MICROSECONDS))
.connectTimeout(timeout)
.build(),
clusterHost);

Call java-Agent of another DataBase from current DataBase Java-Agent

I have a java-agent from which I can call another agent with the parameter passed through it which contains NoteId, and using that NoteId, I am successfully able to get the work done the that document.Till here every thing is clear.
The main question regarding this is , Is it possible to run the agent of another database on same server from the current database agent?
To be more clear for an example
I have two databases, "ABC.nsf" and "XYZ.nsf", JavaAgent "A" is in "ABC.nsf" and JavaAgent "B" is in "XYZ.nsf". In my xpage I have a button running Agent "A", and even Agent "A" can run any other javaAgent from the same database.
Code:
Document mainDoc = db.getDocumentByUNID(tempDoc.getItemValueString("mainDocId"));
String noteID = mainDoc.getNoteID();
String agentName = "NotificationManager";
Agent agent = db.getAgent(agentName);
if (agent != null)
agent.runOnServer(noteID);
else
System.err.println("Something is wrong");
But Actually I want run the JavaAgent "B" Located in "XYZ.nsf" from JavaAgent "A" which is in "ABC.nsf".
After some research I have referd this code.
Code
Database db=session.getDatabase(current_server, "path/to/XYZ.nsf");
Agent myAgent=db.getAgent("B");
myAgent.run();
And yes I am unsuccessfull there,
Need some idea to acheive this.Any suggession will be really appretiated.
The example code is correct in principle. Just some things you have to know:
First of all the name of server can either be "" or the real name of the server. BUT if there is a server, then you have to check the Trusted servers:- section in the server document (Security Tab - Server Access section). There the server himself has to be member of the field (as name or in a group), otherwise you might not be able to open the other database.
Second thing: the path to the target database is relative to data directory and has to be in the right format for the given operating system.
e.g. C:\IBM\Domino\Data\first\xyz.nsf would be first\xyz.nsf and /local/notesdata/second/abc.nsfwould be second/abc.nsf
Third: the noteid that you get is from a document from the calling database. In the "target"- agent you have to go and get the document from the source database, otherwise it will either throw an error or -as the noteid is just a sequential number- return a document from target database that has nothing to do with the document you are searching for.
The calling agent A would have code like this:
Session session = getSession();
AgentContext agentContext =
session.getAgentContext();
Database dbCurrent = agentContext.getCurrentDatabase();
Database dbTarget = session.getDatabase(dbCurrent.Server, "XYZ.nsf");
Agent myAgent=dbTarget.getAgent("B");
myAgent.runOnServer(noteID);
The called agent B could look like this
Session session = getSession();
AgentContext agentContext =
session.getAgentContext();
Database dbCurrent = agentContext.getCurrentDatabase();
Database dbSource = session.getDatabase(dbCurrent.Server, "ABC.nsf");
Document doc = dbSource.getDocumentByID(agentContext.getCurrentAgent().getParameterDocID())
This should work (if security is ok on the server).
As Paul mentioned in the comments security also means that the agent signer or web user (depending on the settings in agent A) has to have sufficient access to the target database AND the target server (if it is different).
If it does not work despite of correct security: Show us the exact error / trace.
May I suggest a different approach? If you don't need an immediate reply from the agent, as a return value in the code, why don't you send the other database a special mail? Create a mail agent (triggered after new mail has been received), at the sender side create a NotesDocument object, add the values you need to reference the document you want the agent to work on, like the name of the server, the replicaId of the database, and the uniqueId. The agent receives the mail and inspects the fields for what it's supposed to do. The receiving database should be mentioned in the N&A book as Mail-in database.
Advantages are manifold: no hassle with rights, a clear interface, no need to open the other database, the agent is executed by the agent manager at a convenient time, you can easily add more functionality the same way, etc.

Categories

Resources