[OJB-developers] Detecting and mapping null Integer values
Brought to you by:
thma
From: Darren S. <Dar...@cw...> - 2002-02-13 16:54:53
|
How can I detect null values for Integer, Long, Double etc Java class attributes ? Let's say we're mapping an object which has the following attributes: class Test { Integer id; String name; Integer sales; } Let's assume that both name and sales can be null. When retrieving this object from the database using the PersistenceBroker the String reference will be null but the sales reference will in fact refer to an Integer object with a zero value. If zero is within the valid range how can we detect that the value is actually null. This appears to boil down to: JdbcAccess.getObjectFromColumn. The code to convert a string looks like: case Types.VARCHAR: result = rs.getString(columnId); break; If the string value is null getString will return a null reference. But for Integer (and other classes) the following is used: case Types.INTEGER: result = new Integer(rs.getInt(columnId)); break; getInt will return 0 for null and the an integer will be created with a zero value. The Conversion Strategy stuff appears too late in the day to make the conversion. How is everybody else handling this or have I missed something ? Thanks Darren ****************************************************************************************************************************************************** This e-mail has been prepared using information believed by the author to be reliable and accurate, but Thales Information Systems Finance makes no warranty as to accuracy or completeness. In particular Thales Information Systems Finance does not accept responsibility for changes made to this e-mail after it was sent. Any opinions expressed in this document are those of the author and do not necessarily reflect the opinions 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 without the express written permission of the sender. If you have received this e-mail in error you may not copy or use the contents, attachments or information in any way. Please destroy it and contact the sender via the Thales Information Systems Finance switchboard in London at +44 (0) 20 7650 0100 or via e-mail return. This message and any attachments have been scanned for viruses prior to leaving the originators network. The originator does not guarantee the security of this message and will not be responsible for any damages arising from any alteration of this message by a third party or as a result of any virus being passed on. ******************************************************************************************************************************************************* |