An example of the standard usage pattern for JDBC can be seen in:
com.vividsolutions.jump.datastore.jdbc.ValueConverterFactory. Regardless of
whether you use ResultSet's getObject() or something like getInt(),
eventually you are going to need an object representation of the data in
order to work with it. BasicFeature.SetAttribute requires an Object. So if
you did something like: new Integer(rs.getInt(columnIndex)) on a null column
, the JavaDoc for ResultSet says you'll get a zero int wrapped in an
Integer.
I appreciate all of the clever solutions, but I will remain convinced that
BasicFeature can detect modification without any need for explicit client
methods to set it, until someone shows me proof that it can not.
regards,
Larry
On Thu, Apr 30, 2009 at 6:24 AM, Paolo Rizzi <g...@oicom.com> wrote:
> The previous sample code I posted was foolish, I'm sorry!!!
>
> Find attached a better version that uses a single Object reference to track
> both initialization and modify state.
>
> During initialization this Object references a byte[] where each element
> tracks the init state of the corresponding attribute.
>
> Init ends when all attributes has been set at least once or when the client
> code calls a provided method.
>
> After init has ended the byte[] is discarded and the Object references the
> static instance of Boolean.FALSE (so there's no memory wasted beyound the
> single Object reference itself).
>
> After at least one attributes is set, the Object references the static
> instance Boolean.TRUE.
>
> Client code can decide to force init end with a non-modified state or even
> an already-modified state, if it likes to.
>
> The code does not check if the new value set for an attribute is equal or
> not to the value already present. This is because a == check would not be
> good because two different Integer instances both containing the same value
> are to be considered equal.
> So the equals() method should be used, but that is not garanteed to work
> with all class types, so I think it may be better to skip the check
> altogether and consider an attribute modified in any case.
>
> Hope this is helpful!!! :-)
>
> Bye
> Paolo
>
>
>
> public class BasicFeature {
> private Object[] attributes;
> private Object mods;
>
> public void forceInitEnded(boolean modified) {
> //force init end and specified modify state
> mods = modified ? Boolean.TRUE : Boolean.FALSE;
> }
>
> public boolean isInitEnded() {
> if( mods instanceof Boolean ) //init ended
> return true;
>
> if( mods == null ) { //if still
> null
> mods = new byte[attributes.length]; //create it
> Arrays.fill((byte[])mods,(byte)0); //fill with zeros
>
> return false; //init not even started
> }
>
> for(int i=0;i<((byte[])mods).length;i++)
> if( ((byte[])mods)[i] == 0 ) //if any attribute never flagged
> return false; //init not ended
>
> forceInitEnded(false); //init ended, no mods done
>
> return true; //init ended
> }
>
> public void setAttribute(Object[] newAttributes) {
> //call setAttribute() for each element
> }
>
> public void setAttribute(int attributeIndex, Object newAttribute) {
> if( isInitEnded() ) //if init ended
> mods = Boolean.TRUE; //feature modified
> else
>
> //if init not ended
> ((byte[])mods)[attributeIndex] = 1; //flag the attributes mod
>
> attributes[attributeIndex] = newAttribute;
> }
>
> public boolean isModified() {
> return isInitEnded() ? ((Boolean)mods).booleanValue() : false;
> }
> }
>
>
> ------------------------------------------------------------------------------
> Register Now & Save for Velocity, the Web Performance & Operations
> Conference from O'Reilly Media. Velocity features a full day of
> expert-led, hands-on workshops and two days of sessions from industry
> leaders in dedicated Performance & Operations tracks. Use code vel09scf
> and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
> _______________________________________________
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
--
http://amusingprogrammer.blogspot.com/
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel