Holger's
Java API

com.antelmann.sql
Class RowItem

java.lang.Object
  extended by com.antelmann.db.AbstractDBEntry
      extended by com.antelmann.db.PropertyEntryImpl
          extended by com.antelmann.sql.RowItem
All Implemented Interfaces:
DBEntry, PropertyEntry, DetailedString, Serializable

public class RowItem
extends PropertyEntryImpl

represents a row in a sql database table and provides convenient access to its properties. It is suggested to have special derived RowItem classes to handle special mappings. To customize the way the columns are accessed vs. how they are stored, consider overriding getProperty() and setProperty() to convert e.g. from java.util.Date to java.sql.Timestamp and vice versa. Also, you may want to override checkPropertyChange to restrict the type for certain columns. To support the dirty tag, the ChangeListenerSupport is enabled for RowItems by default.

Author:
Holger Antelmann
See Also:
ConnectionHelper, Serialized Form

Field Summary
 
Fields inherited from class com.antelmann.db.PropertyEntryImpl
propertyChangeSupport, props, um, vcs
 
Fields inherited from interface com.antelmann.db.DBEntry
ENTRY_FLAVOR, ENTRY_LIST_FLAVOR
 
Constructor Summary
RowItem(Object id, RowItem row)
           
RowItem(String tableName, String idColumn, Object id, Map<String,?> props, String... columns)
           
RowItem(String tableName, String idColumn, Object id, String... columns)
          constructs a RowItem with empty properties and the given columns
 
Method Summary
protected  void checkPropertyChange(String key, Object value)
          allows only keys that correspond to an existing column, unless there are no columns present, in which case true is always returned.
 boolean equals(Object obj)
          a row is equal only if id, tableName and idColumn are equal; columns (other than the idColumn) are ignored
static RowItem extractRow(ResultSet rs, String idField)
          the current row must not have been accessed, yet
 Map<String,Object> getColumnProperties()
          extracts only those properties that corresponds to a column of this instance
 String[] getColumns()
          returns all columns of the table other than the idColumn; the return value should not be altered to avoid unexpected behavior.
 String getIdColumn()
          returns the field name for accessing the primary key (whoms value can be accessed by getID().
 Map<String,Class<?>> getMetaData()
          provides access to optional meta data information, mapping property keys to the associated class; this may return null.
 String getTableName()
           
 boolean isDirty()
          the dirty flag is automatically set to true on each property change if the ChangeListenerSupport remains enabled
 void loadStreams()
          converts occurring InputStream to byte[] and Reader to StringBuffer, so that this instance can be properly serialized after it has been received from a ResultSet.
static void loadStreams(Map<String,Object> map)
          converts occurring InputStream to byte[] and Reader to StringBuffer, so that this instance can be properly serialized after it has been received from a ResultSet.
 void prepareStreams()
          converts occurring byte[] to InputStream and StringBuffer to Reader, so that this instance can be properly used by a ConnectionHelper for insert/update.
static void prepareStreams(Map<String,Object> map)
          converts occurring byte[] to InputStream and StringBuffer to Reader, so that this instance can be properly used by a ConnectionHelper for insert/update.
 boolean sameTable(RowItem row)
          checks for table, idColumn and columns to be identical
 void setColumns(String[] columns)
          allows to set the available columns in the table belonging to this row.
 void setDirty(boolean flag)
           
 void setIdColumn(String idColumn)
           
 void setMetaData(Map<String,Class<?>> meta)
          allows to optionally set meta data information that - if non-null - overrides the columns set for the checkPropertyChange() method.
 void setTableName(String tableName)
           
 String toString()
           
 
Methods inherited from class com.antelmann.db.PropertyEntryImpl
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, asProperties, canRedo, canUndo, clearProperties, containsPropertyText, containsValuePattern, equalWithProperties, equalWithProperties, getBoolean, getNumber, getProperties, getProperty, getProperty, getPropertyChangeListeners, getPropertyComparator, getPropertyExtractor, getPropertyExtractor, getPropertyKeys, getStringExtractor, getVetoableChangeListeners, isCaseInsensitive, isChangeListenerSupportEnabled, isKeyIn, isUndoSupport, isVetoableChangeSupportEnabled, putAll, redo, removeProperty, removePropertyChangeListener, removeVetoableChangeListener, setAllFrom, setCaseInsensitive, setChangeListenerSupport, setProperty, setUndoSupported, setVetoableChangeSupport, toDetailedString, undo, verifyProperties
 
Methods inherited from class com.antelmann.db.AbstractDBEntry
getID, hashCode, hashEntry, sameEntry
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.antelmann.db.DBEntry
getID
 

Constructor Detail

RowItem

public RowItem(Object id,
               RowItem row)

RowItem

public RowItem(String tableName,
               String idColumn,
               Object id,
               String... columns)
constructs a RowItem with empty properties and the given columns


RowItem

public RowItem(String tableName,
               String idColumn,
               Object id,
               Map<String,?> props,
               String... columns)
Method Detail

setMetaData

public void setMetaData(Map<String,Class<?>> meta)
allows to optionally set meta data information that - if non-null - overrides the columns set for the checkPropertyChange() method.


getMetaData

public Map<String,Class<?>> getMetaData()
provides access to optional meta data information, mapping property keys to the associated class; this may return null. If non-null, this information is used with checkPropertyChange.


checkPropertyChange

protected void checkPropertyChange(String key,
                                   Object value)
                            throws IllegalArgumentException
allows only keys that correspond to an existing column, unless there are no columns present, in which case true is always returned. If the metaData is set with a non-null Map, that information overrides the columns and will be used to check the data instead.

Overrides:
checkPropertyChange in class PropertyEntryImpl
Throws:
IllegalArgumentException - if the change of the value is not to be allowed
See Also:
PropertyEntryImpl.setProperty(String, Object), PropertyEntryImpl.removeProperty(String)

isDirty

public boolean isDirty()
the dirty flag is automatically set to true on each property change if the ChangeListenerSupport remains enabled


setDirty

public void setDirty(boolean flag)

getTableName

public String getTableName()

setTableName

public void setTableName(String tableName)

getIdColumn

public String getIdColumn()
returns the field name for accessing the primary key (whoms value can be accessed by getID().


setIdColumn

public void setIdColumn(String idColumn)

getColumns

public String[] getColumns()
returns all columns of the table other than the idColumn; the return value should not be altered to avoid unexpected behavior.


sameTable

public boolean sameTable(RowItem row)
checks for table, idColumn and columns to be identical


setColumns

public void setColumns(String[] columns)
                throws NullPointerException
allows to set the available columns in the table belonging to this row. Null is not allowed, but you may set a zero-length array to essentially allow all property changes on this row.

Throws:
NullPointerException

equals

public boolean equals(Object obj)
a row is equal only if id, tableName and idColumn are equal; columns (other than the idColumn) are ignored

Overrides:
equals in class AbstractDBEntry

getColumnProperties

public Map<String,Object> getColumnProperties()
extracts only those properties that corresponds to a column of this instance


toString

public String toString()
Overrides:
toString in class AbstractDBEntry

loadStreams

public void loadStreams()
                 throws IOException
converts occurring InputStream to byte[] and Reader to StringBuffer, so that this instance can be properly serialized after it has been received from a ResultSet.

Throws:
IOException
See Also:
prepareStreams()

loadStreams

public static void loadStreams(Map<String,Object> map)
                        throws IOException
converts occurring InputStream to byte[] and Reader to StringBuffer, so that this instance can be properly serialized after it has been received from a ResultSet.

Throws:
IOException
See Also:
prepareStreams(Map)

prepareStreams

public void prepareStreams()
converts occurring byte[] to InputStream and StringBuffer to Reader, so that this instance can be properly used by a ConnectionHelper for insert/update.

See Also:
loadStreams()

prepareStreams

public static void prepareStreams(Map<String,Object> map)
converts occurring byte[] to InputStream and StringBuffer to Reader, so that this instance can be properly used by a ConnectionHelper for insert/update.

See Also:
loadStreams(Map)

extractRow

public static RowItem extractRow(ResultSet rs,
                                 String idField)
                          throws SQLException
the current row must not have been accessed, yet

Throws:
SQLException


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads