You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Gerrie Myburgh <ge...@yahoo.co.uk.INVALID> on 2017/12/24 10:42:39 UTC

PersistenceQueryFindUsingApplibQueryProcessor.getResults returns null

Hi,
I have written the following query : new javax.jdo.annotations.Query(
  name = "findByJobName",
  value = "SELECT UNIQUE "
    + "FROM domainapp.modules.system.dom.impl.PersonObject "
    + "WHERE tasks.contains(task) && task.parentJob.name == :name ")And it returns no records. This is correct as there is no data in the database, but when the query results are returned by getResults of PersistenceQueryFindUsingApplibQueryProcessor it returns null from the following code in the getResults method: try {
    final List<?> results = (List<?>) jdoQuery.executeWithMap(argumentsByParameterName);
    final List<?> resultsToReturn =
            cardinality == QueryCardinality.MULTIPLE
                    ? results
                    : results.isEmpty()
                        ? Collections.emptyList()
                        : results.subList(0, 1);
    return Lists.newArrayList(resultsToReturn);
} finally {
    jdoQuery.closeAll();
}
The newArrayList is passed a null value and it then promptly throws an exception :
Caused by: java.lang.NullPointerException
 at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:212) at com.google.common.collect.Lists.newArrayList(Lists.java:144) at org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.getResults(PersistenceQueryFindUsingApplibQueryProcessor.java:124) at org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.process(PersistenceQueryFindUsingApplibQueryProcessor.java:57) at org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.process(PersistenceQueryFindUsingApplibQueryProcessor.java:41)
As far as I can see executeWithMap is the culprit here.
Must I log an issue or is this caused by  myself writing bad code?
ThanksGerrie

Re: PersistenceQueryFindUsingApplibQueryProcessor.getResults returns null

Posted by Dan Haywood <da...@haywood-associates.co.uk>.
Hi Gerrie,
Glad you tracked it down.

It seems to me that the framework ought to cater for a null being returned
from SELECT UNIQUE.

Normally we'd ask you to log an issue, but I've gone ahead and logged one
already [1]

Thanks for reporting this.

Cheers
Dan

[1] https://issues.apache.org/jira/browse/ISIS-1802

On Sun, 24 Dec 2017 at 12:24 Gerrie Myburgh
<ge...@yahoo.co.uk.invalid> wrote:

>  I Found the problem.
> It is the UNIQUE part of the query that causes jdoQuery.executeWithMap to
> return null. Removing the UNIQUE result in a DISTINCT in the generated
> query and the query returns a not null reference.
> Gerrie
>     On Sunday, 24 December 2017, 12:42:56 GMT+2, Gerrie Myburgh <
> gerrie.myburgh@yahoo.co.uk.INVALID> wrote:
>
>  Hi,
> I have written the following query : new javax.jdo.annotations.Query(
>   name = "findByJobName",
>   value = "SELECT UNIQUE "
>     + "FROM domainapp.modules.system.dom.impl.PersonObject "
>     + "WHERE tasks.contains(task) && task.parentJob.name == :name ")And
> it returns no records. This is correct as there is no data in the database,
> but when the query results are returned by getResults
> of PersistenceQueryFindUsingApplibQueryProcessor it returns null from the
> following code in the getResults method: try {
>     final List<?> results = (List<?>)
> jdoQuery.executeWithMap(argumentsByParameterName);
>     final List<?> resultsToReturn =
>             cardinality == QueryCardinality.MULTIPLE
>                     ? results
>                     : results.isEmpty()
>                         ? Collections.emptyList()
>                         : results.subList(0, 1);
>     return Lists.newArrayList(resultsToReturn);
> } finally {
>     jdoQuery.closeAll();
> }
> The newArrayList is passed a null value and it then promptly throws an
> exception :
> Caused by: java.lang.NullPointerException
>  at
> com.google.common.base.Preconditions.checkNotNull(Preconditions.java:212)
> at com.google.common.collect.Lists.newArrayList(Lists.java:144) at
> org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.getResults(PersistenceQueryFindUsingApplibQueryProcessor.java:124)
> at
> org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.process(PersistenceQueryFindUsingApplibQueryProcessor.java:57)
> at
> org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.process(PersistenceQueryFindUsingApplibQueryProcessor.java:41)
> As far as I can see executeWithMap is the culprit here.
> Must I log an issue or is this caused by  myself writing bad code?
> ThanksGerrie

Re: PersistenceQueryFindUsingApplibQueryProcessor.getResults returns null

Posted by Gerrie Myburgh <ge...@yahoo.co.uk.INVALID>.
 I Found the problem.
It is the UNIQUE part of the query that causes jdoQuery.executeWithMap to return null. Removing the UNIQUE result in a DISTINCT in the generated query and the query returns a not null reference.
Gerrie
    On Sunday, 24 December 2017, 12:42:56 GMT+2, Gerrie Myburgh <ge...@yahoo.co.uk.INVALID> wrote:  
 
 Hi,
I have written the following query : new javax.jdo.annotations.Query(
  name = "findByJobName",
  value = "SELECT UNIQUE "
    + "FROM domainapp.modules.system.dom.impl.PersonObject "
    + "WHERE tasks.contains(task) && task.parentJob.name == :name ")And it returns no records. This is correct as there is no data in the database, but when the query results are returned by getResults of PersistenceQueryFindUsingApplibQueryProcessor it returns null from the following code in the getResults method: try {
    final List<?> results = (List<?>) jdoQuery.executeWithMap(argumentsByParameterName);
    final List<?> resultsToReturn =
            cardinality == QueryCardinality.MULTIPLE
                    ? results
                    : results.isEmpty()
                        ? Collections.emptyList()
                        : results.subList(0, 1);
    return Lists.newArrayList(resultsToReturn);
} finally {
    jdoQuery.closeAll();
}
The newArrayList is passed a null value and it then promptly throws an exception :
Caused by: java.lang.NullPointerException
 at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:212) at com.google.common.collect.Lists.newArrayList(Lists.java:144) at org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.getResults(PersistenceQueryFindUsingApplibQueryProcessor.java:124) at org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.process(PersistenceQueryFindUsingApplibQueryProcessor.java:57) at org.apache.isis.objectstore.jdo.datanucleus.persistence.queries.PersistenceQueryFindUsingApplibQueryProcessor.process(PersistenceQueryFindUsingApplibQueryProcessor.java:41)
As far as I can see executeWithMap is the culprit here.
Must I log an issue or is this caused by  myself writing bad code?
ThanksGerrie