com.scooterframework.orm.sqldataexpress.object
Class RowData

java.lang.Object
  extended by com.scooterframework.orm.sqldataexpress.object.RowData
All Implemented Interfaces:
RESTified, java.io.Serializable

public class RowData
extends java.lang.Object
implements RESTified, java.io.Serializable

RowData class represents a row in TableData object.

See Also:
Serialized Form

Constructor Summary
RowData(RowInfo rowInfo, java.lang.Object[] data)
           
 
Method Summary
 void addChildRowToMap(java.lang.String key, java.util.List<RowData> childRowList)
          adds a list of child RowData objects to Map
 void addChildRowToMap(java.lang.String key, RowData childRow)
          adds a child RowData object to Map
 void clearAndSetData(java.util.Map<java.lang.String,?> inputDataMap)
          Clears all existing data and resets data from a Map.
 void clearData()
          Clears all existing data except the primary key data.
 java.util.List<RowData> getChildRowListFromMap(java.lang.String key)
          returns a list of RowData objects for a child from Map
 java.util.Map<java.lang.String,java.lang.Object> getDataMap()
          returns the data as a readonly Map.
 java.util.Map<java.lang.String,java.lang.Object> getDataMap(java.util.List<java.lang.String> columnNames)
          returns the data as a readonly Map.
 java.lang.Object getField(int index)
          Returns column data for a column index index: 0, 1, 2, ...
 java.lang.Object getField(java.lang.String columnName)
          Returns column data for a column name
 java.lang.Object[] getFields()
          returns plain data
 java.util.Map<java.lang.String,java.lang.Object> getPrimaryKeyDataMap()
          returns primary key data as a readonly Map.
 java.lang.String getPrimaryKeyDataString()
          returns primary key data as a string which comes from the primary key data map.
 java.lang.String getRestfulId()
           Returns the restified id of the resource.
 java.util.Map<java.lang.String,java.lang.Object> getRestfulIdMap()
          Returns the data map for the restified id.
 java.lang.String[] getRestfulIdNames()
          Returns column names corresponding to the RESTful id.
 RowInfo getRowInfo()
          returns row meta data
 int getSize()
          returns columnSize
 boolean hasInitialized()
          Checks if the record is initialized.
 boolean hasPrimaryKey()
          Indicates if there is primary key defined.
 java.util.List<java.lang.String> setData(java.util.Map<java.lang.String,?> inputDataMap)
          Sets data from a Map.
 void setField(int index, java.lang.Object columnData)
          Sets column data for a column index index: 0, 1, 2, ...
 void setField(java.lang.String columnName, java.lang.Object columnData)
          Sets column data for a column name If there is no such a columnName, an InvalidColumnNameException will be thrown.
 void setFields(java.lang.Object[] data)
          Sets data.
 void setRestfulId(java.lang.String id)
          Sets the id value of the resource.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RowData

public RowData(RowInfo rowInfo,
               java.lang.Object[] data)
Method Detail

getRestfulId

public java.lang.String getRestfulId()

Returns the restified id of the resource.

By default, this method returns a string of the primary key value of the record. If the primary key is a composite key, a separator (DatabaseConfig.PRIMARY_KEY_SEPARATOR) is used to link values of the key fields. The order of the fields of a composite primary key is defined by the getRestfulIdNames method.

If the underlying data does not have primary key, null is returned.

Subclass may override this method if a customized string format is required.

Specified by:
getRestfulId in interface RESTified
Returns:
id String

getRestfulIdNames

public java.lang.String[] getRestfulIdNames()
Returns column names corresponding to the RESTful id. If there is primary key, the column names come from primary key. Otherwise, null is returned.

Specified by:
getRestfulIdNames in interface RESTified
Returns:
a string array

getRestfulIdMap

public java.util.Map<java.lang.String,java.lang.Object> getRestfulIdMap()
Returns the data map for the restified id. By default, the keys in the map are primary key column names in lower case. If there is no primary key, an empty map is returned.

Specified by:
getRestfulIdMap in interface RESTified
Returns:
map of restified id data

setRestfulId

public void setRestfulId(java.lang.String id)

Sets the id value of the resource. The format of the id string must follow the pattern of the corresponding id config. If the id is backed by a composite primary key, a separator (DatabaseConfig.PRIMARY_KEY_SEPARATOR) must be used to link values of each primary key column.

 Examples:
   id string          id config array         description
   ---------          ---------------         -------
     0001             [id]                    an order
     0001-99          [order_id, id]          an item of an order

 

Specified by:
setRestfulId in interface RESTified
Parameters:
id -

getFields

public java.lang.Object[] getFields()
returns plain data


setFields

public void setFields(java.lang.Object[] data)

Sets data.

The order of values in the data array must be the same as the order of column names in the RowInfo object of this RowData instance.


getField

public java.lang.Object getField(int index)
Returns column data for a column index index: 0, 1, 2, ...


setField

public void setField(int index,
                     java.lang.Object columnData)
Sets column data for a column index index: 0, 1, 2, ...


getField

public java.lang.Object getField(java.lang.String columnName)
Returns column data for a column name


setField

public void setField(java.lang.String columnName,
                     java.lang.Object columnData)
Sets column data for a column name If there is no such a columnName, an InvalidColumnNameException will be thrown.


getRowInfo

public RowInfo getRowInfo()
returns row meta data


clearData

public void clearData()
Clears all existing data except the primary key data.


clearAndSetData

public void clearAndSetData(java.util.Map<java.lang.String,?> inputDataMap)
Clears all existing data and resets data from a Map. The key of the data entry in the Map is corresponding to a column name in the RowInfo object. If the key is not a column name, its value is ignored. If the column name is not in the key set of the Map, the column data is set to null.


setData

public java.util.List<java.lang.String> setData(java.util.Map<java.lang.String,?> inputDataMap)

Sets data from a Map.

The key of the data entry in the Map is corresponding to a column name in the RowInfo object. If the key is not a column name, its value is ignored. If the column name is not in the key set of the Map, the column data is not updated. To set those column data to null when the column name is not in the key set, use the setField method.

This method is restrictive. If a column is readonly, or not writable, or is primary key, then the data for the column in the inputDataMap is ignored. In that case, use the setField method

Returns:
a list of modified column names

getDataMap

public java.util.Map<java.lang.String,java.lang.Object> getDataMap()
returns the data as a readonly Map. The keys in the Map are column names in upper case. Modifications to this map have no impact on the row data.


getDataMap

public java.util.Map<java.lang.String,java.lang.Object> getDataMap(java.util.List<java.lang.String> columnNames)
returns the data as a readonly Map. The keys in the Map are requested column names in upper case. Modifications to this map have no impact on the row data.


getPrimaryKeyDataMap

public java.util.Map<java.lang.String,java.lang.Object> getPrimaryKeyDataMap()
returns primary key data as a readonly Map. The keys in the Map are primary key column names in lower case. Modifications to this map have no impact on the row data.


getPrimaryKeyDataString

public java.lang.String getPrimaryKeyDataString()
returns primary key data as a string which comes from the primary key data map.

Returns:
string

hasPrimaryKey

public boolean hasPrimaryKey()
Indicates if there is primary key defined.

Returns:
true if there is primary key defined.

hasInitialized

public boolean hasInitialized()
Checks if the record is initialized.

Returns:
true if the record is initialized

getSize

public int getSize()
returns columnSize


getChildRowListFromMap

public java.util.List<RowData> getChildRowListFromMap(java.lang.String key)
returns a list of RowData objects for a child from Map


addChildRowToMap

public void addChildRowToMap(java.lang.String key,
                             RowData childRow)
adds a child RowData object to Map


addChildRowToMap

public void addChildRowToMap(java.lang.String key,
                             java.util.List<RowData> childRowList)
adds a list of child RowData objects to Map


toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
String