Re: Represesntation of database NULL as something else than Java null pointer

From: Øyvind Harboe (oyvind.harbo..ylin.com)
Date: Thu Dec 14 2006 - 17:08:15 EST

  • Next message: Michael Gentry: "Re: Re: Represesntation of database NULL as something else than Java null pointer"

    On 12/14/06, Tore Halset <halse..vv.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
    



    This archive was generated by hypermail 2.0.0 : Thu Dec 14 2006 - 17:08:52 EST