[ 
https://issues.apache.org/jira/browse/JDO-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=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<T> 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<T> as a first class object? If an Employee has a 
field Optional<Department> can the field be treated as first class? 
Q. Could Employee.getDepartment() return an Optional<Department>? 

Answer : yes to both. A user can have fields of types like Optional<String>, 
Optional<Date> 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<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?

> 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)

Reply via email to