|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.scooterframework.orm.util.DataAccessUtil
public class DataAccessUtil
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
|
iteratorOf(java.util.Collection<T> items)
Returns an iterator of a collection. |
|
static
|
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 |
|---|
public DataAccessUtil()
| Method Detail |
|---|
public static java.lang.Object getProperty(java.lang.Object object,
java.lang.String property)
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.
object - property -
public static java.util.List<ActiveRecord> allAssociatedRecordsOf(ActiveRecord record,
java.lang.String associationName)
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.
record - an ActiveRecord instance.associationName - association name.
public static java.util.List<ActiveRecord> allAssociatedRecordsOf(ActiveRecord record,
java.lang.String associationName,
boolean refresh)
See description of allAssociatedRecordsOf(com.scooterframework.orm.activerecord.ActiveRecord,
java.lang.String) method for more details and examples.
record - an ActiveRecord instance.associationName - association name.refresh - true if reload database data
public static ActiveRecord associatedRecordOf(ActiveRecord record,
java.lang.String associationName)
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.
record - an ActiveRecord instance.associationName - association name.
public static ActiveRecord associatedRecordOf(ActiveRecord record,
java.lang.String associationName,
boolean refresh)
See description of associatedRecordOf(com.scooterframework.orm.activerecord.ActiveRecord,
java.lang.String) method for more details and examples.
record - an ActiveRecord instance.associationName - association name.refresh - true if reload database data
public static java.util.List<Message> getErrorMessages(ActiveRecord record)
record - an ActiveRecord instance
public static java.util.List<ReferenceData> getReferenceDataList(java.lang.String type)
public static ReferenceData getReferenceDataByTypeAndKey(java.lang.String type,
java.lang.String keyData)
public static ReferenceData getReferenceDataByTypeAndValue(java.lang.String type,
java.lang.Object valueData)
public static ActiveRecord homeInstance(java.lang.String model)
model - model name
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.
model - model name
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.
record - an active record instance or home instance
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.
rowInfo - a RowInfo instance
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.
td - a TableData instance
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.
rd - a RowData instance
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.
record - a restified record
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.
records - a collection of records
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.
model - model name
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.
record - an ActiveRecord record instance or home instance
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.
rowInfo - a RowInfo instance
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.
record - a restified record
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.
rd - a RowData record instance
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.
records - a collection of records
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.
items - a collection of items
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.
map - a map
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.
model - model name
public static java.lang.String restfulIdOf(RESTified record)
record - a RESTified record
public static RowInfo rowInfoOf(ActiveRecord record)
record - a record object
public static RowInfo rowInfoOf(RowData record)
record - a record object
public static RowInfo rowInfoOf(TableData tableData)
tableData - a TableData object
public static RowInfo rowInfoOf(TableInfo tableInfo)
tableInfo - a TableInfo object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||