You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Michael Gentry <bl...@gmail.com> on 2017/02/01 15:24:48 UTC

Java 8 Optionals

I haven't thought through this too much yet, but wanted to get some
feedback if possible.

Would it make sense to have an option in CM (and supporting templates/etc)
to have Optional as a return type?  This would only be meaningful, I think,
on to-one relationships, since to-many will return an empty collection.

Thanks,

mrg

Re: Java 8 Optionals

Posted by Michael Gentry <bl...@gmail.com>.
On Wed, Feb 1, 2017 at 12:11 PM, Andrus Adamchik <an...@objectstyle.org>
wrote:

>
> > On Feb 1, 2017, at 10:34 PM, Michael Gentry <bl...@gmail.com> wrote:
> >
> > How would the extended type work?
>
> Sorry, it won't. See my other email - I corrected myself.
>

Yeah, our e-mails crossed paths.


>  (Useful enough to warrant the development expense of
> > including the feature.)
>
> Yeah, that's what I am still trying to figure out for myself as well.


That's mainly why I was asking.  Wondering if it is something worthwhile,
etc.

Re: Java 8 Optionals

Posted by Andrus Adamchik <an...@objectstyle.org>.
> On Feb 1, 2017, at 10:34 PM, Michael Gentry <bl...@gmail.com> wrote:
> 
> How would the extended type work?

Sorry, it won't. See my other email - I corrected myself.

> 
>  (Useful enough to warrant the development expense of
> including the feature.)

Yeah, that's what I am still trying to figure out for myself as well. 

Andrus 


Re: Java 8 Optionals

Posted by Michael Gentry <bl...@gmail.com>.
Well, my thought was to have a checkbox/etc for each attribute/relationship
where you could choose if you wanted an Optional returned (defaulting to
NOT returning an Optional).  I agree that the syntax would be overwhelming
for the general case, but was more curious about if it could be useful for
a few explicit cases.  (Useful enough to warrant the development expense of
including the feature.)

How would the extended type work?  I assume you are talking attributes-only
here?

Thanks,

mrg


On Wed, Feb 1, 2017 at 11:53 AM, Andrus Adamchik <an...@objectstyle.org>
wrote:

> I thought of this too. Though I have mixed feelings about using Optional
> casually. It is good in processing pipelines. But when used as property
> return type in Java Beans to indicate nullable values, it just feels like
> syntax for the sake of syntax (I tried a few times, reverted back to normal
> properties every time).
>
> So how about we try it on a small scale? Add an ExtendedType for it in
> cayenne-java8, tell the community, and then sit back and wait if anyone
> actually wants it :)
>
> Andrus
>
>
>
> > On Feb 1, 2017, at 9:03 PM, Michael Gentry <bl...@gmail.com> wrote:
> >
> > Actually, I suppose this might make sense for attributes, too.  Such as a
> > User class with a Role attribute that you want to make sure is non-null
> and
> > you are forced handle the null condition with a default Role if something
> > happened to your DB value.
> >
> > mrg
> >
> >
> > On Wed, Feb 1, 2017 at 10:24 AM, Michael Gentry <bl...@gmail.com>
> wrote:
> >
> >> I haven't thought through this too much yet, but wanted to get some
> >> feedback if possible.
> >>
> >> Would it make sense to have an option in CM (and supporting
> templates/etc)
> >> to have Optional as a return type?  This would only be meaningful, I
> think,
> >> on to-one relationships, since to-many will return an empty collection.
> >>
> >> Thanks,
> >>
> >> mrg
> >>
> >>
>
>

Re: Java 8 Optionals

Posted by Andrus Adamchik <an...@objectstyle.org>.
Actually I haven't thought through the ExtendedType idea ... Perhaps it shouldn't be that, but instead just a getter/setter wrapper like you suggested. 

Anyways, before we add another code generator switch, I'd like to hear from people who tried Optionals in java beans, and whether anyone actually thinks they are helpful?

Andrus


> On Feb 1, 2017, at 10:23 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> I thought of this too. Though I have mixed feelings about using Optional casually. It is good in processing pipelines. But when used as property return type in Java Beans to indicate nullable values, it just feels like syntax for the sake of syntax (I tried a few times, reverted back to normal properties every time).
> 
> So how about we try it on a small scale? Add an ExtendedType for it in cayenne-java8, tell the community, and then sit back and wait if anyone actually wants it :)
> 
> Andrus
> 
> 
> 
>> On Feb 1, 2017, at 9:03 PM, Michael Gentry <bl...@gmail.com> wrote:
>> 
>> Actually, I suppose this might make sense for attributes, too.  Such as a
>> User class with a Role attribute that you want to make sure is non-null and
>> you are forced handle the null condition with a default Role if something
>> happened to your DB value.
>> 
>> mrg
>> 
>> 
>> On Wed, Feb 1, 2017 at 10:24 AM, Michael Gentry <bl...@gmail.com> wrote:
>> 
>>> I haven't thought through this too much yet, but wanted to get some
>>> feedback if possible.
>>> 
>>> Would it make sense to have an option in CM (and supporting templates/etc)
>>> to have Optional as a return type?  This would only be meaningful, I think,
>>> on to-one relationships, since to-many will return an empty collection.
>>> 
>>> Thanks,
>>> 
>>> mrg
>>> 
>>> 
> 


Re: Java 8 Optionals

Posted by Andrus Adamchik <an...@objectstyle.org>.
I thought of this too. Though I have mixed feelings about using Optional casually. It is good in processing pipelines. But when used as property return type in Java Beans to indicate nullable values, it just feels like syntax for the sake of syntax (I tried a few times, reverted back to normal properties every time).

So how about we try it on a small scale? Add an ExtendedType for it in cayenne-java8, tell the community, and then sit back and wait if anyone actually wants it :)

Andrus



> On Feb 1, 2017, at 9:03 PM, Michael Gentry <bl...@gmail.com> wrote:
> 
> Actually, I suppose this might make sense for attributes, too.  Such as a
> User class with a Role attribute that you want to make sure is non-null and
> you are forced handle the null condition with a default Role if something
> happened to your DB value.
> 
> mrg
> 
> 
> On Wed, Feb 1, 2017 at 10:24 AM, Michael Gentry <bl...@gmail.com> wrote:
> 
>> I haven't thought through this too much yet, but wanted to get some
>> feedback if possible.
>> 
>> Would it make sense to have an option in CM (and supporting templates/etc)
>> to have Optional as a return type?  This would only be meaningful, I think,
>> on to-one relationships, since to-many will return an empty collection.
>> 
>> Thanks,
>> 
>> mrg
>> 
>> 


Re: Java 8 Optionals

Posted by Michael Gentry <bl...@gmail.com>.
Actually, I suppose this might make sense for attributes, too.  Such as a
User class with a Role attribute that you want to make sure is non-null and
you are forced handle the null condition with a default Role if something
happened to your DB value.

mrg


On Wed, Feb 1, 2017 at 10:24 AM, Michael Gentry <bl...@gmail.com> wrote:

> I haven't thought through this too much yet, but wanted to get some
> feedback if possible.
>
> Would it make sense to have an option in CM (and supporting templates/etc)
> to have Optional as a return type?  This would only be meaningful, I think,
> on to-one relationships, since to-many will return an empty collection.
>
> Thanks,
>
> mrg
>
>