AW: [OJB-developers] Detecting and mapping null Integer values
Brought to you by:
thma
From: Mahler T. <tho...@it...> - 2002-02-14 12:23:12
|
Hi Jakob, After having a short look at the code I believe that you are right! I'll put it on my todo list! thanks, Thomas > -----Urspr=FCngliche Nachricht----- > Von: Jakob Braeuchi [mailto:jbr...@ho...] > Gesendet: Donnerstag, 14. Februar 2002 08:50 > An: Thomas Mahler > Cc: obj...@li... > Betreff: Re: [OJB-developers] Detecting and mapping null=20 > Integer values >=20 >=20 > hi thomas, >=20 > i think the method set() of PersistentField could be =20 > streamlined a lot when > using f.set(obj,value) instead of the if-else-cascade. >=20 > public void set(Object obj, Object value) throws=20 > IllegalAccessException, > IllegalArgumentException > { > boolean before =3D getField().isAccessible(); > AccessController.doPrivileged(new SetAccessibleAction()); > Field f =3D getField(); > Class type =3D f.getType(); > try > { > f.set(obj,value); > } > catch (IllegalArgumentException ex) > { > getField().setAccessible(before); > LoggerFactory.getDefaultLogger().error(ex); > LoggerFactory.getDefaultLogger().error("field: " +=20 > fieldname + ", > type: " + type); > LoggerFactory.getDefaultLogger().error("value: " +=20 > value + ", type: > " + value.getClass()); > throw ex; > } > getField().setAccessible(before); > } >=20 > jakob >=20 > ----- Original Message ----- > From: "Thomas Mahler" <tho...@ho...> > To: "Darren Syzling" <Dar...@cw...> > Cc: <obj...@li...> > Sent: Wednesday, February 13, 2002 8:09 PM > Subject: Re: [OJB-developers] Detecting and mapping null=20 > Integer values >=20 >=20 > > Hi Darren, > > > > Darren Syzling wrote: > > > > > How can I detect null values for Integer, Long, Double=20 > etc Java class > attributes > > > ? Let's say we're mapping an object which has the=20 > following attributes: > > > > > > class Test > > > { > > > Integer id; > > > String name; > > > Integer sales; > > > } > > > > > > > > > Let's assume that both name and sales can be null. When=20 > retrieving this > object > > > from the database using the PersistenceBroker the String=20 > reference will > be null > > > but the sales reference will in fact refer to an Integer=20 > object with a > zero > > > value. If zero is within the valid range how can we=20 > detect that the > value is > > > actually null. > > > > > > This appears to boil down to:=20 > JdbcAccess.getObjectFromColumn. The code > to > > > convert a string looks like: > > > > > > case Types.VARCHAR: > > > result =3D rs.getString(columnId); > > > break; > > > > > > If the string value is null getString will return a null=20 > reference. But > for > > > Integer (and other classes) the following is used: > > > > > > case Types.INTEGER: > > > result =3D new Integer(rs.getInt(columnId)); > > > break; > > > > > > > > > > > I get your point. But: how should the above code look like to = handle > > your problem correctly? I have no idea. > > If you (or somebody else) tell me how this section should=20 > look like I > > will change it! > > > > > > java.sql.ResultSet does not tell you that a column is NULL. It just > > returns a 0. Of course this is wrong. But SUN specified it this = way. > > Or am I missing something? From the java.sql.ResultSet Source: > > > > /** > > * Gets the value of the designated column in the current row > > * of this <code>ResultSet</code> object as > > * an <code>int</code> in the Java programming language. > > * > > * @param columnIndex the first column is 1, the=20 > second is 2, ... > > * @return the column value; if the value is SQL=20 > <code>NULL</code>, > > * the value returned is <code>0</code> > > * @exception SQLException if a database access error occurs > > */ > > int getInt(int columnIndex) throws SQLException; > > > > > > > getInt will return 0 for null and the an integer will be=20 > created with a > zero > > > value. > > > > > > The Conversion Strategy stuff appears too late in the day=20 > to make the > > > conversion. > > > > > > You are right, things are already on the wrong track at=20 > this point.... > > > > How is everybody else handling this or have I missed something ? > > > > > > cu, > > > > Thomas > > > > > > > > > > > > > Thanks > > > Darren > > > > > > > > > > > > > ************************************************************** > ************** > ************************************************************** > ************ > > > This e-mail has been prepared using information believed by = the > author to be > > > reliable and accurate, but Thales Information Systems=20 > Finance makes no > > > warranty as to accuracy or completeness. In particular Thales > Information > > > Systems Finance does not accept responsibility for =20 > changes made to > this > > > e-mail after it was sent. Any opinions expressed in=20 > this document are > those of > > > the author and do not necessarily reflect the opinions=20 > of the company > or its > > > affiliates. They may be subject to change without notice. > > > This e-mail, its content and any files transmitted with it = are > intended > > > solely for the addressee(s) and may be legally = privileged > and/or > > > confidential. Access by any other party is unauthorised=20 > without the > express > > > written permission of the sender. If you have received=20 > this e-mail in > error you > > > may not copy or use the contents, attachments or=20 > information in any > way. > > > Please destroy it and contact the sender via the Thales=20 > Information > Systems > > > Finance switchboard in London at +44 (0) 20 7650 0100 or=20 > via e-mail > return. > > > This message and any attachments have been scanned > > > for viruses prior to leaving the originators network. The=20 > originator > does not > > > guarantee the security of this message and will not be=20 > responsible for > any > > > damages arising from any alteration of this message by a=20 > third party or > as a > > > result of any virus being passed on. > > > > ************************************************************** > ************** > ************************************************************** > ************* > > > > > > > > > > > > _______________________________________________ > > > Objectbridge-developers mailing list > > > Obj...@li... > > >=20 https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > > > > > > > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > _______________________________________________ Objectbridge-developers mailing list Obj...@li... https://lists.sourceforge.net/lists/listinfo/objectbridge-developers |