Holger's
Java API

com.antelmann.sql
Class RowItem

java.lang.Object
  extended by com.antelmann.mgmt.EntityImpl
      extended by com.antelmann.sql.RowItem
All Implemented Interfaces:
Entity, Resource, Serializable

public class RowItem
extends EntityImpl

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:
Serialized Form

Field Summary
 
Fields inherited from class com.antelmann.mgmt.EntityImpl
propertyChangeSupport, props
 
Constructor Summary
RowItem(String tableName, String idColumn, Object id, Map<String,Object> 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)
          columns (other than the idColumn) are ignored
 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
 String getIdColumn()
          returns the field name for accessing the primary key (whoms value can be accessed by getID().
 String getTableName()
           
 boolean isDirty()
          the dirty flag is automatically set to true on each property change if the ChangeListenerSupport remains enabled
 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)
           
 String toString()
           
 
Methods inherited from class com.antelmann.mgmt.EntityImpl
addPropertyChangeListener, containsPropertyText, enableChangeListenerSupport, equalWithProperties, getID, getProperties, getProperty, getPropertyChangeListeners, hashCode, isChangeListenerSupportEnabled, removeProperty, removePropertyChangeListener, setAll, setProperty, verifyProperties
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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,Object> props,
               String... columns)
Method Detail

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.

Overrides:
checkPropertyChange in class EntityImpl
Throws:
IllegalArgumentException - if the change of the value is not to be allowed
See Also:
EntityImpl.setProperty(String, Object), EntityImpl.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()

getIdColumn

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


getColumns

public String[] getColumns()
returns all columns of the table other than the idColumn


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)
columns (other than the idColumn) are ignored

Overrides:
equals in class EntityImpl

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 Object


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