Wolfgang-Schuetzelhofer / jcypher

Java access to Neo4J graph databases at multiple levels of abstraction
Apache License 2.0
86 stars 15 forks source link

NullPointerException at PredicateFunction.getType() #39

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi Wolfgang.

Sorry to return here, but I tried everything that I could.

I'm using the DSL query to compare my object properties, and i'm getting a NullPointerException at iot.jcypher.query.ast.predicate.PredicateFunction.getType()

Here's the groovy code that i'm using to feed a Concatenator inside a loop:

private Concatenator clausula

void ONDE(Concatenator funcaoPredicativa) {
        clausula = clausula != null ?
                clausula.AND().holdsTrue(funcaoPredicativa) :
                funcaoPredicativa
}

And here is where it's used:

props.each {  String chave, Object valor ->

                def v = valor instanceof Var ? valor.persistente : valor

                if (v) criterio.ONDE(WHERE.valueOf(origem.property(chave)).EQUALS(v))

 }

the StackTrace:

java.lang.NullPointerException at iot.jcypher.query.ast.predicate.PredicateFunction.getType(PredicateFunction.java:28) at iot.jcypher.query.writer.CypherWriter$CollectionCypherWriter.toCypherExpression(CypherWriter.java:462) at iot.jcypher.query.writer.CypherWriter$CollectionCypherWriter.access$1400(CypherWriter.java:452) at iot.jcypher.query.writer.CypherWriter$PredicateCypherWriter.toCypherExpression(CypherWriter.java:654) at iot.jcypher.query.writer.CypherWriter$PredicateCypherWriter.toCypherExpression(CypherWriter.java:638) at iot.jcypher.query.writer.CypherWriter$PredicateCypherWriter.toCypherExpression(CypherWriter.java:628) at iot.jcypher.query.writer.CypherWriter$PredicateCypherWriter.access$500(CypherWriter.java:620) at iot.jcypher.query.writer.CypherWriter.toCypherExpression(CypherWriter.java:247) at iot.jcypher.query.writer.CypherWriter.toCypherExpression(CypherWriter.java:139) at iot.jcypher.query.writer.CypherWriter.toCypherExpression(CypherWriter.java:132) at iot.jcypher.query.writer.CypherWriter.toCypherExpression(CypherWriter.java:126)

I'm using the 3.9.0 version. Thanks in advance, your library is one of the pillars of my college project.

Wolfgang-Schuetzelhofer commented 6 years ago

Hi Davi, I am currently on an engagement out of town. I will be back next week and will then have a look into your problem.

Best regards, Wolfgang

Wolfgang-Schuetzelhofer commented 6 years ago

Hi Davi, as far as I can see, you are handling partial query expressions as if they would immediately provide the results of performing such a query. You have to write a complete query using the JCypher Query DSL and then perform it against an instance of IDomainAccess. You can then iterate over the provided results. If you explain what you want to achieve with your query, I can provide an example. In addition to the project documentation a good source of knowledge about how JCypher works are the samples project as well as the JUnit tests, which are accessible if you clone the project from the Git repository.

Best regards, Wolfgang

ghost commented 6 years ago

Wolfgang,

I'm wrapping a List to construct a JcQuery with some application domain methods. I'm also wrapping a Concatenator (the 'criterio' variable, wich contains the Concatenator 'clausula'). This allows me to feed the concatenator inside a loop with a method 'ONDE' or 'OU' without need to test if it's the first expression or if i have to concatenate. After that, i put the Concatenator in the List, creating a JcQuery object.

The exception happens when i call the IDBAcess.execute(JcQuery) or the Util.toCypher(JcQuery, Format).

It started after some code changes and Groovy + JCypher version update, but a git revert doesn't fixed it. It doesn't happen when i got only one property to compare, in a query like this:

MATCH (c:Classe:Substancial:Conceito:Entidade) WHERE c.classeFinal = 'Modelo.Conceitos.Proporcao' RETURN c

By the StackTrace, i think it may be a groovy compilation problem with the APIObjectAccess.getAstNode((APIObject) clause) or the Concatenator ret = new Concatenator((PredicateExpression)this.astNode); inside the Concat.holdsTrue(IPredicateFunction I) method

Thank you a lot! Davi

ghost commented 6 years ago

Wolfgang.

It was really a groovy compilation problem. the method 'ONDE' was in a groovy 'Category', so i moved it to inside the loops:

`Concatenator concat

    props.findAll { it.value != null }.each { String chave, Object valor ->

        if (concat == null) concat = valueOf(origem.property(chave)).EQUALS(valor)
        else concat = concat.AND().valueOf(origem.property(chave)).EQUALS(valor)

    }

    if (concat) pesquisa << concat`

and now its working.

Thanks a lot for answering and sorry for the trouble. Davi.