You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2008/08/20 11:46:54 UTC

Handling of database NULL - default value column to modeler?

One way to handle database NULL (replace with default value)
is to override the CayenneDataObject get/set methods.

However, I was wondering if it would make sense to add a column
to DbEntity in the modeler for this case.

The idea is that this "documents" the behaviour in the modeler for
what happens in this case for a column. It also saves a tad of
Java boilerplate code.

I would expect the default value to behave as follows:

default value = null. Same as today.

default value != null:

- return default value upon getXxx() methods (readProperty()) when
database column contains NULL
- setProperty() w/default value upon column w/database NULL. Probably
update the database upon commit. This would cause database NULL
to be updated to default value when rewinding/submitting a form without
actually making any changes to a form(using tapestry rewinding
wording above...)
- I'm not quite sure if I have decided what to expect from Expression's.
If I search for a value in the database that is equal to the default value,
would I then expect rows w/NULL to match? Probably not.


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Re: Handling of database NULL - default value column to modeler?

Posted by Michael Gentry <bl...@gmail.com>.
Say you overrode the getter ... if null, return default value.  This
wouldn't flag the object as having been changed, so if you
commitChanges() -- without making other changes, this object wouldn't
be pushed back t the DB.

I'm not sure what the correct (as in expected) behavior would be if
the Modeler had a default value column.  Should Cayenne check for NULL
and then SET the value (ensuring it is modified)?  Should Cayenne just
check for NULLs in the getter and return the default value (not
modifying the object)?  I just know some would expect it to work one
way and others the other way.

/dev/mrg


On Wed, Aug 20, 2008 at 5:46 AM, Øyvind Harboe <oy...@zylin.com> wrote:
> One way to handle database NULL (replace with default value)
> is to override the CayenneDataObject get/set methods.

RE: Handling of database NULL - default value column to modeler?

Posted by Scott Anderson <sa...@airvana.com>.
Sounds like you want to make the field NOT NULL with a default value in the database. That would transparently do what you've described, without any reliance on Cayenne.

-----Original Message-----
From: oyvindharboe@gmail.com [mailto:oyvindharboe@gmail.com] On Behalf Of Øyvind Harboe
Sent: Wednesday, August 20, 2008 5:47 AM
To: cayenne-user@incubator.apache.org
Subject: Handling of database NULL - default value column to modeler?

One way to handle database NULL (replace with default value)
is to override the CayenneDataObject get/set methods.

However, I was wondering if it would make sense to add a column
to DbEntity in the modeler for this case.

The idea is that this "documents" the behaviour in the modeler for
what happens in this case for a column. It also saves a tad of
Java boilerplate code.

I would expect the default value to behave as follows:

default value = null. Same as today.

default value != null:

- return default value upon getXxx() methods (readProperty()) when
database column contains NULL
- setProperty() w/default value upon column w/database NULL. Probably
update the database upon commit. This would cause database NULL
to be updated to default value when rewinding/submitting a form without
actually making any changes to a form(using tapestry rewinding
wording above...)
- I'm not quite sure if I have decided what to expect from Expression's.
If I search for a value in the database that is equal to the default value,
would I then expect rows w/NULL to match? Probably not.


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Re: Handling of database NULL - default value column to modeler?

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 28/08/2008, at 1:38 AM, Scott Anderson wrote:

>
> For something as cool and impressive as the DbGenerator is, I think it
> deserves a priority higher than "someday" :)

Please remember that Cayenne is a volunteer project. If this feature  
is of great importance to you I encourage you to submit patches to the  
Jira task, or hire a Java programmer to do that for you. The Cayenne  
project would benefit as a result and others would be able to benefit  
from your contribution, as well as being able to build even more nice  
features on top of it.

Any contributions are always welcomed and if they reach the  
appropriate coding standards and licensing requirements, they will be  
incorporated into the Cayenne project.

Regards
Ari Maniatis



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



RE: Handling of database NULL - default value column to modeler?

Posted by Scott Anderson <sa...@airvana.com>.
After switching over to using the DbGenerator and DbMerger from flat SQL
files, I see this to be of fairly major importance. Since the database
doesn't know what default values should be, I'm finding myself reworking
a fair amount of code to add these where it wouldn't otherwise be
necessary.

For something as cool and impressive as the DbGenerator is, I think it
deserves a priority higher than "someday" :)

-----Original Message-----
From: Aristedes Maniatis [mailto:ari@ish.com.au] 
Sent: Wednesday, August 20, 2008 8:00 PM
To: user@cayenne.apache.org
Subject: Re: Handling of database NULL - default value column to
modeler?


On 21/08/2008, at 3:54 AM, Andrus Adamchik wrote:

> If we are to bring this to Cayenne as a feature, I am very much in  
> favor of an generic solution with the ability to define arbitrary  
> metadata in the model. It has been mentioned in this thread already  
> that this is a very popular request, and as usual my reply is  
> "someday" :-/

Interesting. I just added a note to
https://issues.apache.org/cayenne/browse/CAY-400 
  in case we want to include this idea as part of that task. It really  
isn't that hard to implement: just a question of creating the GUI that  
works for different types of data (eg. compare long documentation data  
to short properties).


Ari



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



Re: Handling of database NULL - default value column to modeler?

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 21/08/2008, at 3:54 AM, Andrus Adamchik wrote:

> If we are to bring this to Cayenne as a feature, I am very much in  
> favor of an generic solution with the ability to define arbitrary  
> metadata in the model. It has been mentioned in this thread already  
> that this is a very popular request, and as usual my reply is  
> "someday" :-/

Interesting. I just added a note to https://issues.apache.org/cayenne/browse/CAY-400 
  in case we want to include this idea as part of that task. It really  
isn't that hard to implement: just a question of creating the GUI that  
works for different types of data (eg. compare long documentation data  
to short properties).


Ari



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



Re: Handling of database NULL - default value column to modeler?

Posted by Andrus Adamchik <an...@objectstyle.org>.
If we are to bring this to Cayenne as a feature, I am very much in  
favor of an generic solution with the ability to define arbitrary  
metadata in the model. It has been mentioned in this thread already  
that this is a very popular request, and as usual my reply is  
"someday" :-/

Andrus


On Aug 20, 2008, at 4:34 PM, Øyvind Harboe wrote:

> On Wed, Aug 20, 2008 at 2:44 PM, Andrus Adamchik <andrus@objectstyle.org 
> > wrote:
>> So this is not about syncing with DB defaults?
>
> Nope.
>
>> Then I think that's over-engineered. Would it be easier to simply  
>> override
>> needed getters per entity class and do "return super is null ?  
>> defaultVal :
>> super", without changing Cayenne core?
>
> That of course gives the user no user interface to
> browse through the model to figure out how defaults are handled +
> scatters boilerplate code all over the subclasses.
>
> Perhaps there is some other way to achieve this?
>
> The crucial bit is to be able to tabulate handling of default  
> values. Perhaps
> use a custom base class for all the CayenneDataObject subclasses and
> override readProperty() to handle null pointers via a lookup...
>
> -- 
> Øyvind Harboe
> http://www.zylin.com/zy1000.html
> ARM7 ARM9 XScale Cortex
> JTAG debugger and flash programmer
>


Re: Handling of database NULL - default value column to modeler?

Posted by Kevin Menard <ni...@gmail.com>.
Sure.  Provide a patch against Cayenne trunk and it will get looked at.
 Otherwise, it's not all that reasonable to expect us to go grab a non-patch
from a third party and integrate into our project.

-- 
Kevin


On Sun, Aug 24, 2008 at 6:10 AM, Tiho Lupak <tl...@yahoo.com> wrote:

>
> > It was not a patch but a complete disto with sources to cayenne 1.2.x,
> and
> > it's still there:
> > http://click.sourceforge.net/click-maven-bundle/cayenne-1.2.2.b.zip
> >
> > There are also improvements to DataView there
> > http://click.sourceforge.net/click-maven-bundle/dataview.zip
> >
> Can we have the improvements from the above 2 packages finally included in
> Cayenne, please :) ?
>
> Thanks,
> Tiho.
> --
> View this message in context:
> http://www.nabble.com/Handling-of-database-NULL---default-value-column-to-modeler--tp19066020p19129199.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>
>

Re: Handling of database NULL - default value column to modeler?

Posted by Tiho Lupak <tl...@yahoo.com>.

Demetrios Kyriakis wrote:
> 
>>>> Also a comment/description field for each column/table in
>>>> CayenneModeler might be nice
>>> This has been implemented (and demonstrated) by Malcolm since years, but
>>> somehow never got
>>> to be included in the official trunk. 
>> If you mean Malcolm Edgar, he is a committer... Could you point to the
>> patch? We may look at it again.
> It was not a patch but a complete disto with sources to cayenne 1.2.x, and
> it's still there:
> http://click.sourceforge.net/click-maven-bundle/cayenne-1.2.2.b.zip
> 
> There are also improvements to DataView there
> http://click.sourceforge.net/click-maven-bundle/dataview.zip
> 
Can we have the improvements from the above 2 packages finally included in
Cayenne, please :) ?

Thanks,
Tiho.
-- 
View this message in context: http://www.nabble.com/Handling-of-database-NULL---default-value-column-to-modeler--tp19066020p19129199.html
Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: Handling of database NULL - default value column to modeler?

Posted by Demetrios Kyriakis <de...@googlemail.com>.
>>> Also a comment/description field for each column/table in
>>> CayenneModeler might be nice
>> This has been implemented (and demonstrated) by Malcolm since years, but
>> somehow never got
>> to be included in the official trunk. 
> If you mean Malcolm Edgar, he is a committer... Could you point to the
> patch? We may look at it again.
Yes, that Malcolm (the author of Click) :).
It was not a patch but a complete disto with sources to cayenne 1.2.x, and
it's still there:
http://click.sourceforge.net/click-maven-bundle/cayenne-1.2.2.b.zip
(I think a directory diff to the official 1.2.2 distro might quickly show
the changes)

I think the reason why he did not sent a patch (but I might be wrong) was
because the move of the trunk
to Maven.

(I also see that these improvements were mentioned several times on the
cayenne lists in the past, but still not included)

Demetrios.
P.S. There are also improvements to DataView there (I think they are from
the same author :) ) : 
http://click.sourceforge.net/click-maven-bundle/dataview.zip



-- 
View this message in context: http://www.nabble.com/Handling-of-database-NULL---default-value-column-to-modeler--tp19066020p19070017.html
Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: Handling of database NULL - default value column to modeler?

Posted by Øyvind Harboe <oy...@zylin.com>.
On Wed, Aug 20, 2008 at 4:29 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
> If you mean Malcolm Edgar, he is a committer... Could you point to the
> patch? We may look at it again.


Meta data is so popular these days. In addition to a comment field(or
embedded therein) I could have information such as default value handling
encoded.

I assume that my CayenneDataObject subclass could get at the
comment text from within a getProperty() override.




-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Re: Handling of database NULL - default value column to modeler?

Posted by Andrus Adamchik <an...@objectstyle.org>.
If you mean Malcolm Edgar, he is a committer... Could you point to the  
patch? We may look at it again.

Andrus

On Aug 20, 2008, at 4:54 PM, Demetrios Kyriakis wrote:

>
>
> Øyvind Harboe wrote:
>>
>> Also a comment/description field for each column/table in
>> CayenneModeler might be nice
>>
> This has been implemented (and demonstrated) by Malcolm since years,  
> but
> somehow never got
> to be included in the official trunk.
>
> Demetrios.
> -- 
> View this message in context: http://www.nabble.com/Handling-of-database-NULL---default-value-column-to-modeler--tp19066020p19069900.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>
>


Re: Handling of database NULL - default value column to modeler?

Posted by Demetrios Kyriakis <de...@googlemail.com>.

Øyvind Harboe wrote:
> 
> Also a comment/description field for each column/table in
> CayenneModeler might be nice
> 
This has been implemented (and demonstrated) by Malcolm since years, but
somehow never got
to be included in the official trunk.

Demetrios.
-- 
View this message in context: http://www.nabble.com/Handling-of-database-NULL---default-value-column-to-modeler--tp19066020p19069900.html
Sent from the Cayenne - User mailing list archive at Nabble.com.


Re: Handling of database NULL - default value column to modeler?

Posted by Øyvind Harboe <oy...@zylin.com>.
Also a comment/description field for each column/table in
CayenneModeler might be nice


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Re: Handling of database NULL - default value column to modeler?

Posted by Øyvind Harboe <oy...@zylin.com>.
On Wed, Aug 20, 2008 at 2:44 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
> So this is not about syncing with DB defaults?

Nope.

> Then I think that's over-engineered. Would it be easier to simply override
> needed getters per entity class and do "return super is null ? defaultVal :
> super", without changing Cayenne core?

That of course gives the user no user interface to
browse through the model to figure out how defaults are handled +
scatters boilerplate code all over the subclasses.

Perhaps there is some other way to achieve this?

The crucial bit is to be able to tabulate handling of default values. Perhaps
use a custom base class for all the CayenneDataObject subclasses and
override readProperty() to handle null pointers via a lookup...

-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Re: Handling of database NULL - default value column to modeler?

Posted by Andrus Adamchik <an...@objectstyle.org>.
So this is not about syncing with DB defaults?

Then I think that's over-engineered. Would it be easier to simply  
override needed getters per entity class and do "return super is  
null ? defaultVal : super", without changing Cayenne core?

Andrus


On Aug 20, 2008, at 12:46 PM, Øyvind Harboe wrote:

> One way to handle database NULL (replace with default value)
> is to override the CayenneDataObject get/set methods.
>
> However, I was wondering if it would make sense to add a column
> to DbEntity in the modeler for this case.
>
> The idea is that this "documents" the behaviour in the modeler for
> what happens in this case for a column. It also saves a tad of
> Java boilerplate code.
>
> I would expect the default value to behave as follows:
>
> default value = null. Same as today.
>
> default value != null:
>
> - return default value upon getXxx() methods (readProperty()) when
> database column contains NULL
> - setProperty() w/default value upon column w/database NULL. Probably
> update the database upon commit. This would cause database NULL
> to be updated to default value when rewinding/submitting a form  
> without
> actually making any changes to a form(using tapestry rewinding
> wording above...)
> - I'm not quite sure if I have decided what to expect from  
> Expression's.
> If I search for a value in the database that is equal to the default  
> value,
> would I then expect rows w/NULL to match? Probably not.
>
>
> -- 
> Øyvind Harboe
> http://www.zylin.com/zy1000.html
> ARM7 ARM9 XScale Cortex
> JTAG debugger and flash programmer
>