[jira] [Commented] (JDO-751) Support for Java8 Optional
[ https://issues.apache.org/jira/browse/JDO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15138522#comment-15138522 ] Andy Jefferson commented on JDO-751: >From Apache JDO "minutes" Q. Does it make sense to support Optional as a persistent type? It would need to map to a nullable datastore value. So Optional can be the type of a persistent field iff T can be the type of a persistent field. Does it make sense to support Optional as a first class object? If an Employee has a field Optional can the field be treated as first class? Q. Could Employee.getDepartment() return an Optional? Answer : yes to both. A user can have fields of types like Optional, Optional and would expect these to be mapped in the datastore to a column that accepts NULLs, and of the equivalent type of T. Similarly they could have a 1-1 relation via a field of type Optional. The other aspect of this would be in terms of JDOQL and queryability of such fields. Following the idea that JDOQL attempts to have Java syntax then we should have methods optionalField.isPresent() returning a BooleanExpression optionalField.get() returning an expression of the type of the T type, so StringExpression, DateExpression, etc. The alternative to this is just to let the user do "== NULL" to check if a value is present. Comments? > Support for Java8 Optional > -- > > Key: JDO-751 > URL: https://issues.apache.org/jira/browse/JDO-751 > Project: JDO > Issue Type: New Feature > Components: specification, tck >Reporter: Andy Jefferson > > java.util.Optional provides a feature that is available in other languages. > Since JDO 3.2 will be for Java8+ then it makes sense to add support for this > as a "supported persistable type" -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JDO-751) Support for Java8 Optional
[ https://issues.apache.org/jira/browse/JDO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15138608#comment-15138608 ] Tilmann Zäschke commented on JDO-751: - I completely agree with the answers. Just to clarify the first question: I see that 'Optional' should be allowed to reference persistence classes (as FCOs) as well as SCOs (such as String, ...). But I guess Optional itself should not be a persistent type? Also, I think we have to decide whether we want to distinguish the case that the reference to Optional could be null vs Optional references a null: {{private Optional date;}} -> {{date==null}} vs {{date.isPresent}}. This is also important for queries, because again {{"date==null"}} would mean something different than {{"date.isPresent()"}} > Support for Java8 Optional > -- > > Key: JDO-751 > URL: https://issues.apache.org/jira/browse/JDO-751 > Project: JDO > Issue Type: New Feature > Components: specification, tck >Reporter: Andy Jefferson > > java.util.Optional provides a feature that is available in other languages. > Since JDO 3.2 will be for Java8+ then it makes sense to add support for this > as a "supported persistable type" -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Comment Edited] (JDO-751) Support for Java8 Optional
[ https://issues.apache.org/jira/browse/JDO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15138522#comment-15138522 ] Andy Jefferson edited comment on JDO-751 at 2/9/16 8:25 AM: >From Apache JDO "minutes" Q. Does it make sense to support Optional as a persistent type? It would need to map to a nullable datastore value. So Optional can be the type of a persistent field iff T can be the type of a persistent field. Does it make sense to support Optional as a first class object? If an Employee has a field Optional can the field be treated as first class? Q. Could Employee.getDepartment() return an Optional? Answer : yes to both. A user can have fields of types like Optional, Optional and would expect these to be mapped in the datastore to a column that accepts NULLs, and of the equivalent type of T. Similarly they could have a 1-1 relation via a field of type Optional (i.e creating the FK to the table of MyOtherType). The other aspect of this would be in terms of JDOQL and queryability of such fields. Following the idea that JDOQL attempts to have Java syntax then we should have methods optionalField.isPresent() returning a BooleanExpression optionalField.get() returning an expression of the type of the T type, so StringExpression, DateExpression, etc. The alternative to this is just to let the user do "== NULL" to check if a value is present. Comments? was (Author: andy): >From Apache JDO "minutes" Q. Does it make sense to support Optional as a persistent type? It would need to map to a nullable datastore value. So Optional can be the type of a persistent field iff T can be the type of a persistent field. Does it make sense to support Optional as a first class object? If an Employee has a field Optional can the field be treated as first class? Q. Could Employee.getDepartment() return an Optional? Answer : yes to both. A user can have fields of types like Optional, Optional and would expect these to be mapped in the datastore to a column that accepts NULLs, and of the equivalent type of T. Similarly they could have a 1-1 relation via a field of type Optional. The other aspect of this would be in terms of JDOQL and queryability of such fields. Following the idea that JDOQL attempts to have Java syntax then we should have methods optionalField.isPresent() returning a BooleanExpression optionalField.get() returning an expression of the type of the T type, so StringExpression, DateExpression, etc. The alternative to this is just to let the user do "== NULL" to check if a value is present. Comments? > Support for Java8 Optional > -- > > Key: JDO-751 > URL: https://issues.apache.org/jira/browse/JDO-751 > Project: JDO > Issue Type: New Feature > Components: specification, tck >Reporter: Andy Jefferson > > java.util.Optional provides a feature that is available in other languages. > Since JDO 3.2 will be for Java8+ then it makes sense to add support for this > as a "supported persistable type" -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (JDO-751) Support for Java8 Optional
[ https://issues.apache.org/jira/browse/JDO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15140104#comment-15140104 ] Renato Garcia commented on JDO-751: --- {quote} Just to clarify the first question: I see that 'Optional' should be allowed to reference persistence classes (as FCOs) as well as SCOs (such as String, ...). But I guess Optional itself should not be a persistent type? {quote} Optional type can be seen as a collection containing zero or one item, so perhaps it would make sense to address them the same way the spec addresses the other collection types. Regarding JDOQL support, I kind of like the idea of supporting methods like isPresent and make a distinction as Tilmann has mentioned above. Also, given the following scenario: Person FCO with an Optional I think it would probably be nice to be able to just write something like this in the query: {code:java} person.address.postCode = foo {code} instead of having to deference the value using get > Support for Java8 Optional > -- > > Key: JDO-751 > URL: https://issues.apache.org/jira/browse/JDO-751 > Project: JDO > Issue Type: New Feature > Components: specification, tck >Reporter: Andy Jefferson > > java.util.Optional provides a feature that is available in other languages. > Since JDO 3.2 will be for Java8+ then it makes sense to add support for this > as a "supported persistable type" -- This message was sent by Atlassian JIRA (v6.3.4#6332)