cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Øyvind Harboe" <oyvind.har...@zylin.com>
Subject Re: Represesntation of database NULL as something else than Java null pointer
Date Thu, 14 Dec 2006 22:08:15 GMT
On 12/14/06, Tore Halset <halset@pvv.ntnu.no> wrote:
> On Dec 14, 2006, at 9:11 , Øyvind Harboe wrote:
>
> > Could I implement my own "NeverNullString" datatype where I'm thinking
> > that .toString() returns the either what Cayenne java.lang.String
> > returns today or e.g. "" for the case where it represents a database
> > null?
>
> Or perhaps map java.lang.CharSequence and create a NullString that
> implements it. You could then create an ExtendedType (perhaps
> subclass CharType) that does what you want.

I messed around with this for a while and I've drawn some conclusions:

- If I'm to use CharSequence instead of String's, then that needs to
be in the application from day #1. It's testing hell trying to replace
String w/anything but a subclass of string(which isn't possible since
String is final).
- As I'm using Tapestry, then if I return something to Tapestry that
it interprets as an empty string, then it will set an empty string
upon my Cayenne object during Form rewind. If I used an empty string
to represent database null, my code would then make the mistake of
changing the database value from database null to an empty string.
- If it is OK from an application point of view to turn database null
into empty strings as a side effect of Tapestry form rewind, then this
approach seems fine and relatively straightforward.
- ExtendedType can not deal with relationships and database null, and
until I get rid of NPE(null pointer exceptions) w/relationships(ref.
OGNL property strings foo.bar.name where bar might be null), I've only
got half a solution. There have been other posts about relationships
and NPE's in the past in Cayenne-user, but a robust solution is far
from obvious.


-- 
Øyvind Harboe
http://www.zylin.com

Mime
View raw message