You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by Tilmann <za...@gmx.de> on 2016/09/24 16:22:08 UTC

JDO-751 "Support for Java8 Optional" with subqueries - request for feedback

Hi,

could I get some feedback?

I tried the following subquery:

                 "SELECT FROM " + OptionalSample.class.getName() + " 
WHERE " +
                 "(select  max(a.id) from " + 
OptionalSample.class.getName() + " a " +
                 "where a.optionalPC != null) == id";

This returns '88' (an integer) instead of the object with id==88. Is 
this expected to return an integer?

Full code (can be used in SupportedOptionalMethods.java):
        String singleStringJDOQL2 =
                 "SELECT FROM " + OptionalSample.class.getName() + " 
WHERE " +
                 "(select  max(a.id) from " + 
OptionalSample.class.getName() + " a " +
                 "where a.optionalPC != null) == id";
         Object[] expectedResult2 = new Object[]{oidReferencedPC1};
         // single String JDOQL
         Query singleStringQuery2 = pm.newQuery(singleStringJDOQL2);
         executeJDOQuery(ASSERTION_FAILED, singleStringQuery2, 
singleStringJDOQL2,
                             false, null, expectedResult2, true);


Kind regards,
Tilmann


On 22.09.2016 22:33, Michael Bouschen wrote:
> Hi,
>
> We will have our regular meeting Friday, September 23 at 9 AM Pacific Daylight Time (PDT) to discuss JDO TCK issues and status.
>
> We use the new dial-in for audio and video. You need a Skype account to join.
> https://join.skype.com/euV54RJwJBcf
>
> Agenda:
> 1. JIRA JDO-756 "Enhance PK to avoid LongIdentity/StringIdentity dependencies" https://issues.apache.org/jira/browse/JDO-756
> 2. Spec changes for  JDO-751 "Support for Java8 Optional" https://issues.apache.org/jira/browse/JDO-751
> 3. JDO-735 "Make PersistenceManager and Query support AutoCloseable (JDK1.7+)" https://issues.apache.org/jira/browse/JDO-735
> 4. JDO-747 "Behavior of delete() with multiple concurrent Transactions" https://issues.apache.org/jira/browse/JDO-747
> 5. JDO 3.1: Need to go through change lists in JIRA for 3.1 RC1 and 3.1 to prepare JCP Change Log
> 6. Other issues
>
> Action Items from weeks past:
> [Oct 30 2015] AI Craig: File a maintenance review with JCP
> [May 15 2015] AI Craig Spec change for roll back an active transaction when closing a persistence manager (JDO-735)
> [Apr 17 2015] AI Craig: Oracle spec page on JDO need to be updated once the JCP Maintenance Release for JDO 3.1 is published
> [Oct 17 2014] AI Matthew any updates for "Modify specification to address NoSQL datastores": https://issues.apache.org/jira/browse/JDO-651?
> [Feb 28 2014] AI Everyone: take a look at https://issues.apache.org/jira/browse/JDO-712
> [Feb 28 2014] AI Everyone: take a look at https://issues.apache.org/jira/browse/JDO-625
> [Dec 13 2013] AI Craig file a JIRA for java.sql.Blob and java.sql.Clob as persistent field types
> [Aug 24 2012] AI Craig update the JIRAs JDO-689 JDO-690 and JDO-692 about JDOHelper methods. In process.
>
> Regards Michael
>
>


Re: JDO-751 "Support for Java8 Optional" with subqueries - request for feedback

Posted by Tilmann <za...@gmx.de>.
Another questions and my findings on using optional in subqueries:

1) Using Optional inside subqueries works just fine, as expected.

         String singleStringJDOQL1 =
                 "SELECT FROM " + OptionalSample.class.getName() + " 
WHERE " +
                 "(select  max(a.id) from " + 
OptionalSample.class.getName() + " a " +
                 "where a.optionalPC.isPresent() ) == id";

         String singleStringJDOQL2 =
                 "SELECT FROM " + OptionalSample.class.getName() + " 
WHERE " +
                 "(select  max(a.id) from " + 
OptionalSample.class.getName() + " a " +
                 "where a.optionalPC.get() != null) == id";

  I will upload a modified test harness that checks this functionality.


2) Another question.
According to 
https://docs.oracle.com/cd/E13189_01/kodo/docs324/ref_guide_subqueries.html 
(last example), subqueries can return collections. I tried to to call 
".isEmpty()" and ".get(0)" on them and I get (I hope I didn't screw up 
my tests again):

"Cannot perform operation ".isEmpty" on 
org.datanucleus.store.rdbms.sql.expression.SubqueryExpression"

"Cannot perform operation ".get" on 
org.datanucleus.store.rdbms.sql.expression.SubqueryExpression"

Query example:

         String singleStringJDOQL1 =
                 "SELECT FROM " + OptionalSample.class.getName() + " 
WHERE " +
                 "(select from " + OptionalSample.class.getName() + " a " +
                 "where a.optionalPC != null).isEmpty()";

         String singleStringJDOQL4 =
             "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
             "(select from " + OptionalSample.class.getName() + " a " +
             "where a.optionalPC != null).get(0).optionalPC.isPresent()";

In the spec I couldn't find a definition of what subqueries should 
return (examples in 14.10.18 and 14.10.19 return aggregates). So I 
suppose they should be able to return collections?
It seems that the TCK tests for subqueries use exclusively aggregates, 
so I'm not sure whether this is an omission or whether it is nor 
supposed to be possible.

Below is a code snippet that can be simply plugged in into the 
SupportedOptionalMethods.java test.

Cheers,
Tilmann

     /**
      * This methods tests that subqueries as collections.
      */
     public void testSubqueriesNoOptional() {
         //TODO
         //this gives:
         //Cannot perform operation ".isEmpty" on 
org.datanucleus.store.rdbms.sql.expression.SubqueryExpression
         //However, it should be possible according to:
//https://docs.oracle.com/cd/E13189_01/kodo/docs324/ref_guide_subqueries.html
         String singleStringJDOQL1 =
                 "SELECT FROM " + OptionalSample.class.getName() + " 
WHERE " +
                 "(select from " + OptionalSample.class.getName() + " a " +
                 "where a.optionalPC != null).isEmpty()";
         Object[] expectedResult1 = new Object[]{oidReferencedPC1};
         checkSingleStringQuery(singleStringJDOQL1, expectedResult1);

         //TODO
         //This gives:
         //Cannot perform operation ".get" on 
org.datanucleus.store.rdbms.sql.expression.SubqueryExpression
         String singleStringJDOQL4 =
             "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
             "(select from " + OptionalSample.class.getName() + " a " +
             "where a.optionalPC != null).get(0).optionalPC.isPresent()";
         Object[] expectedResult4 = new Object[]{oidReferencedPC1};
         checkSingleStringQuery(singleStringJDOQL4, expectedResult4);
     }



On 24.09.2016 18:59, Tilmann wrote:
> Thanks!
>
> Looks like I made a mistake during results checks, it works now, sorry 
> for that.
>
> Tilmann
>
>
> On 24.09.2016 18:32, Craig Russell wrote:
>> The subselect would return 88 and then the outer select would become
>>
>>                 "SELECT FROM " + OptionalSample.class.getName() + " 
>> WHERE " +
>>                 \u201c(88) == id\u201d;
>>
>> Seems to me this should select the object whose id is 88.
>>
>> Craig
>>
>>> On Sep 24, 2016, at 9:22 AM, Tilmann <za...@gmx.de> wrote:
>>>
>>> Hi,
>>>
>>> could I get some feedback?
>>>
>>> I tried the following subquery:
>>>
>>>                 "SELECT FROM " + OptionalSample.class.getName() + " 
>>> WHERE " +
>>>                 "(select  max(a.id) from " + 
>>> OptionalSample.class.getName() + " a " +
>>>                 "where a.optionalPC != null) == id";
>>>
>>> This returns '88' (an integer) instead of the object with id==88. Is 
>>> this expected to return an integer?
>>>
>>> Full code (can be used in SupportedOptionalMethods.java):
>>>        String singleStringJDOQL2 =
>>>                 "SELECT FROM " + OptionalSample.class.getName() + " 
>>> WHERE " +
>>>                 "(select  max(a.id) from " + 
>>> OptionalSample.class.getName() + " a " +
>>>                 "where a.optionalPC != null) == id";
>>>         Object[] expectedResult2 = new Object[]{oidReferencedPC1};
>>>         // single String JDOQL
>>>         Query singleStringQuery2 = pm.newQuery(singleStringJDOQL2);
>>>         executeJDOQuery(ASSERTION_FAILED, singleStringQuery2, 
>>> singleStringJDOQL2,
>>>                             false, null, expectedResult2, true);
>>>
>>>
>>> Kind regards,
>>> Tilmann

Re: JDO-751 "Support for Java8 Optional" with subqueries - request for feedback

Posted by Tilmann <za...@gmx.de>.
Thanks!

Looks like I made a mistake during results checks, it works now, sorry 
for that.

Tilmann


On 24.09.2016 18:32, Craig Russell wrote:
> The subselect would return 88 and then the outer select would become
>
>                 "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
>                 \u201c(88) == id\u201d;
>
> Seems to me this should select the object whose id is 88.
>
> Craig
>
>> On Sep 24, 2016, at 9:22 AM, Tilmann <za...@gmx.de> wrote:
>>
>> Hi,
>>
>> could I get some feedback?
>>
>> I tried the following subquery:
>>
>>                 "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
>>                 "(select  max(a.id) from " + OptionalSample.class.getName() + " a " +
>>                 "where a.optionalPC != null) == id";
>>
>> This returns '88' (an integer) instead of the object with id==88. Is this expected to return an integer?
>>
>> Full code (can be used in SupportedOptionalMethods.java):
>>        String singleStringJDOQL2 =
>>                 "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
>>                 "(select  max(a.id) from " + OptionalSample.class.getName() + " a " +
>>                 "where a.optionalPC != null) == id";
>>         Object[] expectedResult2 = new Object[]{oidReferencedPC1};
>>         // single String JDOQL
>>         Query singleStringQuery2 = pm.newQuery(singleStringJDOQL2);
>>         executeJDOQuery(ASSERTION_FAILED, singleStringQuery2, singleStringJDOQL2,
>>                             false, null, expectedResult2, true);
>>
>>
>> Kind regards,
>> Tilmann
>>
>>
>> On 22.09.2016 22:33, Michael Bouschen wrote:
>>> Hi,
>>>
>>> We will have our regular meeting Friday, September 23 at 9 AM Pacific Daylight Time (PDT) to discuss JDO TCK issues and status.
>>>
>>> We use the new dial-in for audio and video. You need a Skype account to join.
>>> https://join.skype.com/euV54RJwJBcf
>>>
>>> Agenda:
>>> 1. JIRA JDO-756 "Enhance PK to avoid LongIdentity/StringIdentity dependencies" https://issues.apache.org/jira/browse/JDO-756
>>> 2. Spec changes for  JDO-751 "Support for Java8 Optional" https://issues.apache.org/jira/browse/JDO-751
>>> 3. JDO-735 "Make PersistenceManager and Query support AutoCloseable (JDK1.7+)" https://issues.apache.org/jira/browse/JDO-735
>>> 4. JDO-747 "Behavior of delete() with multiple concurrent Transactions" https://issues.apache.org/jira/browse/JDO-747
>>> 5. JDO 3.1: Need to go through change lists in JIRA for 3.1 RC1 and 3.1 to prepare JCP Change Log
>>> 6. Other issues
>>>
>>> Action Items from weeks past:
>>> [Oct 30 2015] AI Craig: File a maintenance review with JCP
>>> [May 15 2015] AI Craig Spec change for roll back an active transaction when closing a persistence manager (JDO-735)
>>> [Apr 17 2015] AI Craig: Oracle spec page on JDO need to be updated once the JCP Maintenance Release for JDO 3.1 is published
>>> [Oct 17 2014] AI Matthew any updates for "Modify specification to address NoSQL datastores": https://issues.apache.org/jira/browse/JDO-651?
>>> [Feb 28 2014] AI Everyone: take a look at https://issues.apache.org/jira/browse/JDO-712
>>> [Feb 28 2014] AI Everyone: take a look at https://issues.apache.org/jira/browse/JDO-625
>>> [Dec 13 2013] AI Craig file a JIRA for java.sql.Blob and java.sql.Clob as persistent field types
>>> [Aug 24 2012] AI Craig update the JIRAs JDO-689 JDO-690 and JDO-692 about JDOHelper methods. In process.
>>>
>>> Regards Michael
>>>
>>>
> Craig L Russell
> Architect
> craig.russell@oracle.com
> P.S. A good JDO? O, Gasp!
>
>
>
>
>


Re: JDO-751 "Support for Java8 Optional" with subqueries - request for feedback

Posted by Craig Russell <cr...@oracle.com>.
The subselect would return 88 and then the outer select would become 

               "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
               “(88) == id”;

Seems to me this should select the object whose id is 88.

Craig

> On Sep 24, 2016, at 9:22 AM, Tilmann <za...@gmx.de> wrote:
> 
> Hi,
> 
> could I get some feedback?
> 
> I tried the following subquery:
> 
>                "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
>                "(select  max(a.id) from " + OptionalSample.class.getName() + " a " +
>                "where a.optionalPC != null) == id";
> 
> This returns '88' (an integer) instead of the object with id==88. Is this expected to return an integer?
> 
> Full code (can be used in SupportedOptionalMethods.java):
>       String singleStringJDOQL2 =
>                "SELECT FROM " + OptionalSample.class.getName() + " WHERE " +
>                "(select  max(a.id) from " + OptionalSample.class.getName() + " a " +
>                "where a.optionalPC != null) == id";
>        Object[] expectedResult2 = new Object[]{oidReferencedPC1};
>        // single String JDOQL
>        Query singleStringQuery2 = pm.newQuery(singleStringJDOQL2);
>        executeJDOQuery(ASSERTION_FAILED, singleStringQuery2, singleStringJDOQL2,
>                            false, null, expectedResult2, true);
> 
> 
> Kind regards,
> Tilmann
> 
> 
> On 22.09.2016 22:33, Michael Bouschen wrote:
>> Hi,
>> 
>> We will have our regular meeting Friday, September 23 at 9 AM Pacific Daylight Time (PDT) to discuss JDO TCK issues and status.
>> 
>> We use the new dial-in for audio and video. You need a Skype account to join.
>> https://join.skype.com/euV54RJwJBcf
>> 
>> Agenda:
>> 1. JIRA JDO-756 "Enhance PK to avoid LongIdentity/StringIdentity dependencies" https://issues.apache.org/jira/browse/JDO-756
>> 2. Spec changes for  JDO-751 "Support for Java8 Optional" https://issues.apache.org/jira/browse/JDO-751
>> 3. JDO-735 "Make PersistenceManager and Query support AutoCloseable (JDK1.7+)" https://issues.apache.org/jira/browse/JDO-735
>> 4. JDO-747 "Behavior of delete() with multiple concurrent Transactions" https://issues.apache.org/jira/browse/JDO-747
>> 5. JDO 3.1: Need to go through change lists in JIRA for 3.1 RC1 and 3.1 to prepare JCP Change Log
>> 6. Other issues
>> 
>> Action Items from weeks past:
>> [Oct 30 2015] AI Craig: File a maintenance review with JCP
>> [May 15 2015] AI Craig Spec change for roll back an active transaction when closing a persistence manager (JDO-735)
>> [Apr 17 2015] AI Craig: Oracle spec page on JDO need to be updated once the JCP Maintenance Release for JDO 3.1 is published
>> [Oct 17 2014] AI Matthew any updates for "Modify specification to address NoSQL datastores": https://issues.apache.org/jira/browse/JDO-651?
>> [Feb 28 2014] AI Everyone: take a look at https://issues.apache.org/jira/browse/JDO-712
>> [Feb 28 2014] AI Everyone: take a look at https://issues.apache.org/jira/browse/JDO-625
>> [Dec 13 2013] AI Craig file a JIRA for java.sql.Blob and java.sql.Clob as persistent field types
>> [Aug 24 2012] AI Craig update the JIRAs JDO-689 JDO-690 and JDO-692 about JDOHelper methods. In process.
>> 
>> Regards Michael
>> 
>> 
> 

Craig L Russell
Architect
craig.russell@oracle.com
P.S. A good JDO? O, Gasp!