com.scooterframework.orm.util
Class DataAccessUtil

java.lang.Object
  extended by com.scooterframework.orm.util.DataAccessUtil

public class DataAccessUtil
extends java.lang.Object

DataAccessUtil class has helper methods for objects including ActiveRecord and SQL data express related instances.


Constructor Summary
DataAccessUtil()
           
 
Method Summary
static java.util.List<ActiveRecord> allAssociatedRecordsOf(ActiveRecord record, java.lang.String associationName)
          Gets all the associated records of an ActiveRecord instance.
static java.util.List<ActiveRecord> allAssociatedRecordsOf(ActiveRecord record, java.lang.String associationName, boolean refresh)
          Gets all the associated records of an ActiveRecord instance.
static ActiveRecord associatedRecordOf(ActiveRecord record, java.lang.String associationName)
          Gets the associated record of an ActiveRecord instance.
static ActiveRecord associatedRecordOf(ActiveRecord record, java.lang.String associationName, boolean refresh)
          Gets the associated record of an ActiveRecord instance.
static java.util.Iterator<java.lang.String> columnNames(ActiveRecord record)
           Returns an iterator of column names of the record.
static java.util.Iterator<java.lang.String> columnNames(java.util.Collection<?> records)
           Returns an iterator of column names of the record in the records collection.
static java.util.Iterator<java.lang.String> columnNames(RESTified record)
           Returns an iterator of column names.
static java.util.Iterator<java.lang.String> columnNames(RowData rd)
           Returns an iterator of column names.
static java.util.Iterator<java.lang.String> columnNames(RowInfo rowInfo)
           Returns an iterator of column names.
static java.util.Iterator<java.lang.String> columnNames(java.lang.String model)
           Returns an iterator of column names of the model.
static java.util.Iterator<java.lang.String> columnNames(TableData td)
           Returns an iterator of column names.
static java.util.Iterator<ColumnInfo> columns(ActiveRecord record)
           Returns an iterator of ColumnInfo instances of the record.
static java.util.Iterator<ColumnInfo> columns(java.util.Collection<?> records)
           Returns an iterator of ColumnInfo instances of the records collection.
static java.util.Iterator<ColumnInfo> columns(RESTified record)
           Returns an iterator of ColumnInfo instances of the record.
static java.util.Iterator<ColumnInfo> columns(RowData rd)
           Returns an iterator of ColumnInfo instances of the record.
static java.util.Iterator<ColumnInfo> columns(RowInfo rowInfo)
           Returns an iterator of ColumnInfo instances.
static java.util.Iterator<ColumnInfo> columns(java.lang.String model)
           Returns an iterator of ColumnInfo instances of the model.
static java.util.List<Message> getErrorMessages(ActiveRecord record)
          Returns all error messages associated with a record instance.
static java.lang.Object getProperty(java.lang.Object object, java.lang.String property)
          Gets property value from the object.
static ReferenceData getReferenceDataByTypeAndKey(java.lang.String type, java.lang.String keyData)
          Gets ReferenceData by type and key
static ReferenceData getReferenceDataByTypeAndValue(java.lang.String type, java.lang.Object valueData)
          Gets ReferenceData by type and value
static java.util.List<ReferenceData> getReferenceDataList(java.lang.String type)
          Gets a list of ReferenceData instances for a certain type.
static RowInfo getRowInfo(java.lang.String model)
           Returns a RowInfo instance of the model.
static ActiveRecord homeInstance(java.lang.String model)
          Returns home instance of the model.
static
<T> java.util.Iterator<T>
iteratorOf(java.util.Collection<T> items)
           Returns an iterator of a collection.
static
<K,V> java.util.Iterator<K>
iteratorOf(java.util.Map<K,V> map)
           Returns an iterator of a map.
static java.lang.String restfulIdOf(RESTified record)
          Returns restful id of the record.
static RowInfo rowInfoOf(ActiveRecord record)
          Returns RowInfo attribute of the record.
static RowInfo rowInfoOf(RowData record)
          Returns RowInfo attribute of the record.
static RowInfo rowInfoOf(TableData tableData)
          Returns RowInfo attribute of the TableData instance.
static RowInfo rowInfoOf(TableInfo tableInfo)
          Returns RowInfo attribute of the TableInfo instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataAccessUtil

public DataAccessUtil()
Method Detail

getProperty

public static java.lang.Object getProperty(java.lang.Object object,
                                           java.lang.String property)
Gets property value from the object. The object can be of type ActiveRecord, RowData, Properties, Map, or simply a java bean (POJO).

If the object is an ActiveRecord instance, and the property string consists of dots, this method will treat the dotted string as a path in association.

 Examples:
     //post belongsTo user
     getProperty(post, "user.first_name") 
     => returns first name of the post author
     
     //lineitem belongsTo order belongsTo customer
     getProperty(lineitem, "order.customer.first_name") 
     => returns first name of the customer who ordered the line item
 

It is not recommended to use dotted property string unless you are sure the object is in a belongs-to or has-one relation chain among all elements of the dotted property string.

Parameters:
object -
property -
Returns:
Object

allAssociatedRecordsOf

public static java.util.List<ActiveRecord> allAssociatedRecordsOf(ActiveRecord record,
                                                                  java.lang.String associationName)
Gets all the associated records of an ActiveRecord instance.

If the associationName string consists of dots, this method will treat the dotted string as a path in association.

 Examples:
     //customer hasMany orders
     allAssociatedRecordsOf(customer, "orders") 
     => returns a list of orders of the customer
     
     //customer hasMany orders hasMany lineitems
     allAssociatedRecordsOf(customer, "orders.lineitems") 
     => returns a list of lineitems for all orders of the customer
 

It is not recommended to use dotted allAssociatedRecordsOf string unless you are sure the object is in a hasMany or hasManyThrough relation chain among all elements of the dotted string.

Parameters:
record - an ActiveRecord instance.
associationName - association name.
Returns:
list of associated records.

allAssociatedRecordsOf

public static java.util.List<ActiveRecord> allAssociatedRecordsOf(ActiveRecord record,
                                                                  java.lang.String associationName,
                                                                  boolean refresh)
Gets all the associated records of an ActiveRecord instance.

See description of allAssociatedRecordsOf(com.scooterframework.orm.activerecord.ActiveRecord, java.lang.String) method for more details and examples.

Parameters:
record - an ActiveRecord instance.
associationName - association name.
refresh - true if reload database data
Returns:
list of associated records.

associatedRecordOf

public static ActiveRecord associatedRecordOf(ActiveRecord record,
                                              java.lang.String associationName)
Gets the associated record of an ActiveRecord instance.

If the associationName string consists of dots, this method will treat the dotted string as a path in association.

 Examples:
     //post belongsTo user
     associatedRecordOf(post, "user") 
     => returns the post author
     
     //lineitem belongsTo order belongsTo customer
     associatedRecordOf(lineitem, "order.customer") 
     => returns the customer who ordered the line item
 

It is not recommended to use dotted associationName string unless you are sure the object is in a belongs-to or has-one relation chain among all elements of the dotted string.

Parameters:
record - an ActiveRecord instance.
associationName - association name.
Returns:
the associated record

associatedRecordOf

public static ActiveRecord associatedRecordOf(ActiveRecord record,
                                              java.lang.String associationName,
                                              boolean refresh)
Gets the associated record of an ActiveRecord instance.

See description of associatedRecordOf(com.scooterframework.orm.activerecord.ActiveRecord, java.lang.String) method for more details and examples.

Parameters:
record - an ActiveRecord instance.
associationName - association name.
refresh - true if reload database data
Returns:
the associated record

getErrorMessages

public static java.util.List<Message> getErrorMessages(ActiveRecord record)
Returns all error messages associated with a record instance.

Parameters:
record - an ActiveRecord instance
Returns:
List of error messages.

getReferenceDataList

public static java.util.List<ReferenceData> getReferenceDataList(java.lang.String type)
Gets a list of ReferenceData instances for a certain type.

Returns:
List

getReferenceDataByTypeAndKey

public static ReferenceData getReferenceDataByTypeAndKey(java.lang.String type,
                                                         java.lang.String keyData)
Gets ReferenceData by type and key

Returns:
ReferenceData

getReferenceDataByTypeAndValue

public static ReferenceData getReferenceDataByTypeAndValue(java.lang.String type,
                                                           java.lang.Object valueData)
Gets ReferenceData by type and value

Returns:
ReferenceData

homeInstance

public static ActiveRecord homeInstance(java.lang.String model)
Returns home instance of the model.

Parameters:
model - model name
Returns:
home instance of the model

columnNames

public static java.util.Iterator<java.lang.String> columnNames(java.lang.String model)

Returns an iterator of column names of the model. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
model - model name
Returns:
iterator

columnNames

public static java.util.Iterator<java.lang.String> columnNames(ActiveRecord record)

Returns an iterator of column names of the record. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
record - an active record instance or home instance
Returns:
iterator

columnNames

public static java.util.Iterator<java.lang.String> columnNames(RowInfo rowInfo)

Returns an iterator of column names. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
rowInfo - a RowInfo instance
Returns:
iterator

columnNames

public static java.util.Iterator<java.lang.String> columnNames(TableData td)

Returns an iterator of column names. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
td - a TableData instance
Returns:
iterator

columnNames

public static java.util.Iterator<java.lang.String> columnNames(RowData rd)

Returns an iterator of column names. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
rd - a RowData instance
Returns:
iterator

columnNames

public static java.util.Iterator<java.lang.String> columnNames(RESTified record)

Returns an iterator of column names. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
record - a restified record
Returns:
iterator

columnNames

public static java.util.Iterator<java.lang.String> columnNames(java.util.Collection<?> records)

Returns an iterator of column names of the record in the records collection. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
records - a collection of records
Returns:
iterator

columns

public static java.util.Iterator<ColumnInfo> columns(java.lang.String model)

Returns an iterator of ColumnInfo instances of the model. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
model - model name
Returns:
iterator

columns

public static java.util.Iterator<ColumnInfo> columns(ActiveRecord record)

Returns an iterator of ColumnInfo instances of the record. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
record - an ActiveRecord record instance or home instance
Returns:
an iterator of ColumnInfo instances

columns

public static java.util.Iterator<ColumnInfo> columns(RowInfo rowInfo)

Returns an iterator of ColumnInfo instances. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
rowInfo - a RowInfo instance
Returns:
iterator

columns

public static java.util.Iterator<ColumnInfo> columns(RESTified record)

Returns an iterator of ColumnInfo instances of the record. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
record - a restified record
Returns:
an iterator of ColumnInfo instances

columns

public static java.util.Iterator<ColumnInfo> columns(RowData rd)

Returns an iterator of ColumnInfo instances of the record. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
rd - a RowData record instance
Returns:
an iterator of ColumnInfo instances

columns

public static java.util.Iterator<ColumnInfo> columns(java.util.Collection<?> records)

Returns an iterator of ColumnInfo instances of the records collection. This is a safe method. If input record is null, an empty iterator is still returned.

Parameters:
records - a collection of records
Returns:
an iterator of ColumnInfo instances

iteratorOf

public static <T> java.util.Iterator<T> iteratorOf(java.util.Collection<T> items)

Returns an iterator of a collection. This is a safe method. If the collection is null, an empty iterator is still returned.

Parameters:
items - a collection of items
Returns:
an iterator of the collection

iteratorOf

public static <K,V> java.util.Iterator<K> iteratorOf(java.util.Map<K,V> map)

Returns an iterator of a map. This is a safe method. If the map is null, an empty iterator is still returned.

Parameters:
map - a map
Returns:
an iterator of the collection

getRowInfo

public static RowInfo getRowInfo(java.lang.String model)

Returns a RowInfo instance of the model. This is a safe method. If input model is null, an empty RowInfo instance is still returned.

Parameters:
model - model name
Returns:
RowInfo for the model

restfulIdOf

public static java.lang.String restfulIdOf(RESTified record)
Returns restful id of the record. If it is null, return empty string.

Parameters:
record - a RESTified record
Returns:
restful id of the record.

rowInfoOf

public static RowInfo rowInfoOf(ActiveRecord record)
Returns RowInfo attribute of the record.

Parameters:
record - a record object
Returns:
RowInfo attribute of the record.

rowInfoOf

public static RowInfo rowInfoOf(RowData record)
Returns RowInfo attribute of the record.

Parameters:
record - a record object
Returns:
RowInfo attribute of the record.

rowInfoOf

public static RowInfo rowInfoOf(TableData tableData)
Returns RowInfo attribute of the TableData instance.

Parameters:
tableData - a TableData object
Returns:
RowInfo attribute of the record.

rowInfoOf

public static RowInfo rowInfoOf(TableInfo tableInfo)
Returns RowInfo attribute of the TableInfo instance.

Parameters:
tableInfo - a TableInfo object
Returns:
RowInfo attribute of the record.