Closed francetem closed 8 years ago
Hi,
which JCypher release are you using? Can you provide me the complete JcQuery (the clauses that make up the query)? Do you have some sample data?
Best regards, Wolfgang
Hi Wolfgang.
My jcypher dependency is:
<dependency>
<groupId>net.iot-solutions.graphdb</groupId>
<artifactId>jcypher</artifactId>
<version>3.2.0</version>
</dependency>
As I'm testing jcypher I have created the following client class:
public class JCypherClient {
public static final String BOOKING_LABEL = "Booking";
public static final String ID_PARAMETER = "id";
public static final String EMAIL_LABEL = "Email";
public static final String EMAIL_PROPERTY = "email";
public void insertBooking(Booking booking) {
JcNode b = new JcNode("b");
JcNode e = new JcNode("e");
JcQuery nodeQuery = new JcQuery();
nodeQuery.setClauses(new IClause[]{
MERGE.node(b).label(BOOKING_LABEL).property(ID_PARAMETER).value(booking.getId()),
DO.SET(b.property("fraud")).to(booking.getFraud()),
DO.SET(b.property("status")).to(booking.getStatus()),
MERGE.node(e).label(EMAIL_LABEL).property(EMAIL_PROPERTY).value(booking.getEmail())
}
);
JcQuery relationQuery = new JcQuery();
relationQuery.setClauses(new IClause[]{
MATCH.node(b).label(BOOKING_LABEL).property(ID_PARAMETER).value(booking.getId()),
MATCH.node(e).label(EMAIL_LABEL).property("email").value(booking.getEmail()),
MERGE.node(b).relation().type("WITH_EMAIL").node(e)
}
);
IDBAccess dbAccess = createDbAccess();
dbAccess.execute(Arrays.asList(nodeQuery, relationQuery));
dbAccess.close();
}
public List<GrRelation> getBookingsRelated(Long bookingId, int maxHops) {
IDBAccess dbAccess = createDbAccess();
JcQuery nodeQuery = new JcQuery();
JcNode b = new JcNode("b");
JcNode b2 = new JcNode("b2");
JcRelation r = new JcRelation("r");
nodeQuery.setClauses(new IClause[]{
MATCH.node(b).label(BOOKING_LABEL).property(ID_PARAMETER).value(bookingId).relation(r).maxHops(maxHops).node(b2),
RETURN.DISTINCT().value(r)
});
return dbAccess.execute(nodeQuery).resultOf(r);
}
private IDBAccess createDbAccess() {
Properties props = new Properties();
props.setProperty(DBProperties.SERVER_ROOT_URI, "http://localhost:7474");
return DBAccessFactory.createDBAccess(DBType.REMOTE, props, "neo4j", "admin");
}
}
And the test that I'm launching is the following one:
public class JCypherClientTest {
JCypherClient jCypherClient = new JCypherClient();
@Test
public void testInsertBooking(){
jCypherClient.insertBooking(new Booking(1l,"FRAUD","CONTRACT", "iam@fraudst.er"));
jCypherClient.insertBooking(new Booking(2l,"LEGIT","INIT", "iam@fraudst.er"));
}
@Test
public void testGetGraph(){
List<GrRelation> bookingsRelated = jCypherClient.getBookingsRelated(1L, 6);
}
}
The stack trace:
java.lang.NullPointerException at iot.jcypher.query.result.util.ResultHandler$ElementInfo.access$000(ResultHandler.java:930) at iot.jcypher.query.result.util.ResultHandler.getRelations(ResultHandler.java:238) at iot.jcypher.query.result.util.ResultHandler.getRelations(ResultHandler.java:219) at iot.jcypher.query.JcQueryResult.resultOf(JcQueryResult.java:76)
public class Booking {
private final Long id;
private final String fraud;
private final String status;
private final String email;
public Booking(Long id, String fraud, String status, String email) {
this.id = id;
this.fraud = fraud;
this.status = status;
this.email = email;
}
public Long getId() {
return id;
}
public String getFraud() {
return fraud;
}
public String getStatus() {
return status;
}
public String getEmail() {
return email;
}
}
Hi,
I have built a new JCypher release 3.2.1 which should fix your problem. It may take a couple of hours until the release is visible on maven central (distribution to all repository servers takes some time).
I hope I could help you, best regards, Wolfgang
Thank you very much Wolgang
Regards.
While doing:
I get a null pointer exception:
java.lang.NullPointerException at iot.jcypher.query.result.util.ResultHandler$ElementInfo.access$000(ResultHandler.java:930) at iot.jcypher.query.result.util.ResultHandler.getRelations(ResultHandler.java:238)
For what I see in the code:
The ValueType returned is Array and it is coming from the json result:
...
Maybe I'm doing something wrong however.