com.scooterframework.orm.activerecord
Class TableGateway

java.lang.Object
  extended by com.scooterframework.orm.activerecord.TableGateway

public class TableGateway
extends java.lang.Object

TableGateway class implements Table Data Gateway pattern. TableGateway handles access to all records of a table or view for a domain model: selects, updates, deletes.

There is no callback involved in methods in this class. To enable callbacks when deleting or updating a set of records, you can first retrieve them and then use the record instance's delete() or update() method which has callbacks.


Method Summary
 java.util.Map<java.lang.String,java.lang.Object> constructFindSQL(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData, java.util.Map<java.lang.String,java.lang.String> options)
           
 java.util.Map<java.lang.String,java.lang.Object> convertToPrimaryKeyDataMap(java.lang.String pkString)
          Converts a primary key RESTful id string to primary key map.
 int deleteAll(java.util.Map<java.lang.String,java.lang.Object> conditions)
           Deletes all the records that satisfy the condition.
 int deleteAll(java.lang.String conditionsSQL)
           Deletes all the records that satisfy the conditions.
 int deleteAll(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)
           Deletes all the records that satisfy the conditions.
 int deleteById(long id)
          Deletes the record with the given id, assuming ID is the primary key column.
 int deleteById(java.lang.Object id)
          Deletes the record with the given id, assuming ID is the primary key column.
 int deleteByPK(java.lang.String pkString)
          Deletes the record with the given pkString.
 int deleteByPrimaryKeyMap(java.util.Map<java.lang.String,java.lang.Object> dataMap)
          Deletes the record with the given data map containing primary keys.
 int deleteBySQL(java.lang.String sql)
          Deletes all the records that satisfy the SQL statement.
 int deleteBySQL(java.lang.String sql, java.util.Map<java.lang.String,java.lang.Object> inputs)
          Deletes all the records that satisfy the SQL statement.
 int deleteBySQLKey(java.lang.String sqlKey)
          Deletes all the records that satisfy the SQL specified by the sqlKey.
 int deleteBySQLKey(java.lang.String sqlKey, java.util.Map<java.lang.String,java.lang.Object> inputs)
          Deletes all the records that satisfy the SQL specified by the sqlKey.
 java.util.List<ActiveRecord> findAll()
           Finds all the records of a table.
 java.util.List<ActiveRecord> findAll(java.util.Map<java.lang.String,java.lang.Object> conditions)
           Finds all the records that satisfy the conditions.
 java.util.List<ActiveRecord> findAll(java.util.Map<java.lang.String,java.lang.Object> conditions, java.util.Map<java.lang.String,java.lang.String> options)
           Finds all the records that satisfy the conditions and options.
 java.util.List<ActiveRecord> findAll(java.util.Map<java.lang.String,java.lang.Object> conditions, java.lang.String options)
           Finds all the records that satisfy the conditions and options.
 java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL)
           Finds all the records that satisfy the conditions.
 java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)
           Finds all the records that satisfy the conditions.
 java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData, java.util.Map<java.lang.String,java.lang.String> options)
           Finds all the records that satisfy the conditions and options.
 java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData, java.lang.String options)
           Finds all the records that satisfy the conditions and options.
 java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL, java.lang.String options)
           Finds all the records that satisfy the conditions and options.
 java.util.List<ActiveRecord> findAllBy(java.lang.String columns, java.lang.Object[] values)
           Finds all the records that satisfy the conditions.
 java.util.List<ActiveRecord> findAllBy(java.lang.String columns, java.lang.Object[] values, java.util.Map<java.lang.String,java.lang.String> options)
           Finds all the records that satisfy the conditions.
 java.util.List<ActiveRecord> findAllBy(java.lang.String columns, java.lang.Object[] values, java.lang.String options)
           Finds all the records that satisfy the conditions.
 java.util.List<ActiveRecord> findAllBySQL(java.lang.String sql)
           Finds all the records that satisfy the SQL query.
 java.util.List<ActiveRecord> findAllBySQL(java.lang.String sql, java.util.Map<java.lang.String,java.lang.Object> inputs)
           Finds all the records that satisfy the SQL query.
 java.util.List<ActiveRecord> findAllBySQLKey(java.lang.String sqlKey)
           Finds all the records that satisfy the SQL corresponding to the SQL key.
 java.util.List<ActiveRecord> findAllBySQLKey(java.lang.String sqlKey, java.util.Map<java.lang.String,java.lang.Object> inputs)
           Finds all the records that satisfy the SQL corresponding to the SQL key.
 ActiveRecord findById(long id)
          Finds the record with the given id, assuming ID is the primary key column.
 ActiveRecord findById(java.lang.Object id)
          Finds the record with the given id, assuming ID is the primary key column.
 ActiveRecord findByPK(java.lang.String pkString)
          Finds the record with the given pkString.
 ActiveRecord findByRESTfulId(java.lang.String restfulId)
          Finds the record with the given restfulId.
 ActiveRecord findFirst()
           Finds the first record of a table.
 ActiveRecord findFirst(java.util.Map<java.lang.String,java.lang.Object> conditions)
           Finds the first record that satisfy the conditions.
 ActiveRecord findFirst(java.util.Map<java.lang.String,java.lang.Object> conditions, java.util.Map<java.lang.String,java.lang.String> options)
           Finds the first record that satisfy the conditions and options.
 ActiveRecord findFirst(java.util.Map<java.lang.String,java.lang.Object> conditions, java.lang.String options)
           Finds the first record that satisfy the conditions and options.
 ActiveRecord findFirst(java.lang.String conditionsSQL)
           Finds the first record that satisfy the conditions.
 ActiveRecord findFirst(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)
           Finds the first record that satisfy the conditions.
 ActiveRecord findFirst(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData, java.util.Map<java.lang.String,java.lang.String> options)
           Finds the first record that satisfy the conditions and options.
 ActiveRecord findFirst(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData, java.lang.String options)
           Finds the first record that satisfy the conditions and options.
 ActiveRecord findFirst(java.lang.String conditionsSQL, java.lang.String options)
           Finds the first record that satisfy the conditions and options.
 ActiveRecord findFirstBy(java.lang.String columns, java.lang.Object[] values)
           Finds the first record that satisfy the conditions.
 ActiveRecord findLast()
           Finds the last record of a table.
 ActiveRecord findLast(java.util.Map<java.lang.String,java.lang.Object> conditions)
           Finds the last record that satisfy the conditions.
 ActiveRecord findLast(java.util.Map<java.lang.String,java.lang.Object> conditions, java.util.Map<java.lang.String,java.lang.String> options)
           Finds the last record that satisfy the conditions and options.
 ActiveRecord findLast(java.util.Map<java.lang.String,java.lang.Object> conditions, java.lang.String options)
           Finds the last record that satisfy the conditions and options.
 ActiveRecord findLast(java.lang.String conditionsSQL)
           Finds the last record that satisfy the conditions.
 ActiveRecord findLast(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)
           Finds the last record that satisfy the conditions.
 ActiveRecord findLast(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData, java.util.Map<java.lang.String,java.lang.String> options)
           Finds the last record that satisfy the conditions and options.
 ActiveRecord findLast(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData, java.lang.String options)
           Finds the last record that satisfy the conditions and options.
 ActiveRecord findLast(java.lang.String conditionsSQL, java.lang.String options)
           Finds the last record that satisfy the conditions and options.
 ActiveRecord findLastBy(java.lang.String columns, java.lang.Object[] values)
           Finds the last record that satisfy the conditions.
 java.lang.String getFinderSql(java.util.Map<java.lang.String,java.lang.String> options)
           
 ActiveRecord getHomeInstance()
          Returns the underlining home instance of this gateway.
 java.lang.Class<? extends ActiveRecord> getModelClass()
          Returns the underlining model class type of this gateway.
 QueryBuilder groupBy(java.lang.String groupBy)
           Setup group-by clause.
 QueryBuilder having(java.lang.String having)
           Setup having clause.
 QueryBuilder includes(java.lang.String includes)
           Setup associated models for eager loading.
 QueryBuilder includes(java.lang.String includes, boolean strict)
           Setup associated models for eager loading.
 QueryBuilder includes(java.lang.String includes, java.lang.String joinType)
           Setup associated models for eager loading.
 QueryBuilder limit(int limit)
           Setup limit for number of records per retrieval.
 QueryBuilder offset(int offset)
           Setup number of records to skip.
 QueryBuilder orderBy(java.lang.String orderBy)
           Setup group-by clause.
 QueryBuilder page(int page)
           Setup current page number.
 int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData)
           Updates all the records of a table.
 int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData, java.lang.String conditionsSQL)
           Updates all the records that satisfy a set of conditions supplied.
 int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData, java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)
           Updates all the records that satisfy the conditions.
 int updateBySQL(java.lang.String sql)
          Updates all the records that satisfy the SQL statement.
 int updateBySQL(java.lang.String sql, java.util.Map<java.lang.String,java.lang.Object> inputs)
          Updates all the records that satisfy the SQL statement.
 int updateBySQLKey(java.lang.String sqlKey)
          Updates all the records that satisfy the SQL specified by sqlKey .
 int updateBySQLKey(java.lang.String sqlKey, java.util.Map<java.lang.String,java.lang.Object> inputs)
          Updates all the records that satisfy the SQL specified by sqlKey .
 QueryBuilder where(java.lang.String conditionsSQL)
           Setup where clause.
 QueryBuilder where(java.lang.String conditionsSQL, java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)
           Setup where clause.
 QueryBuilder where(java.lang.String conditionsSQL, java.lang.Object[] conditionsSQLData)
           Setup where clause.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getHomeInstance

public ActiveRecord getHomeInstance()
Returns the underlining home instance of this gateway.


getModelClass

public java.lang.Class<? extends ActiveRecord> getModelClass()
Returns the underlining model class type of this gateway.


where

public QueryBuilder where(java.lang.String conditionsSQL)

Setup where clause.

Parameters:
conditionsSQL - a valid SQL query where clause string
Returns:
current QueryBuilder instance

where

public QueryBuilder where(java.lang.String conditionsSQL,
                          java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)

Setup where clause.

Parameters:
conditionsSQL - a valid SQL query where clause string
conditionsSQLData - an array of data for the conditionsSQL string
Returns:
current QueryBuilder instance

where

public QueryBuilder where(java.lang.String conditionsSQL,
                          java.lang.Object[] conditionsSQLData)

Setup where clause.

Parameters:
conditionsSQL - a valid SQL query where clause string
conditionsSQLData - an array of data for the conditionsSQL string
Returns:
current QueryBuilder instance

includes

public QueryBuilder includes(java.lang.String includes)

Setup associated models for eager loading.

Parameters:
includes - a string of associated models
Returns:
current QueryBuilder instance

includes

public QueryBuilder includes(java.lang.String includes,
                             java.lang.String joinType)

Setup associated models for eager loading.

Parameters:
includes - a string of associated models
joinType - type of join
Returns:
current QueryBuilder instance

includes

public QueryBuilder includes(java.lang.String includes,
                             boolean strict)

Setup associated models for eager loading.

If strict is true, then child records can only be accessed through their parent.

Parameters:
includes - a string of associated models
strict - true if strict
Returns:
current QueryBuilder instance

groupBy

public QueryBuilder groupBy(java.lang.String groupBy)

Setup group-by clause.

Parameters:
groupBy - a valid SQL query group-by clause string
Returns:
current QueryBuilder instance

having

public QueryBuilder having(java.lang.String having)

Setup having clause.

Parameters:
having - a valid SQL query having clause string
Returns:
current QueryBuilder instance

orderBy

public QueryBuilder orderBy(java.lang.String orderBy)

Setup group-by clause.

Parameters:
orderBy - a valid SQL query order-by clause string
Returns:
current QueryBuilder instance

limit

public QueryBuilder limit(int limit)

Setup limit for number of records per retrieval.

Parameters:
limit - number of records for each retrieval
Returns:
current QueryBuilder instance

offset

public QueryBuilder offset(int offset)

Setup number of records to skip.

Parameters:
offset - number of records to skip
Returns:
current QueryBuilder instance

page

public QueryBuilder page(int page)

Setup current page number. All records in previous pages are skipped.

Parameters:
page - current page number
Returns:
current QueryBuilder instance

findById

public ActiveRecord findById(long id)
Finds the record with the given id, assuming ID is the primary key column. If there is no column name like "ID", an exception will be thrown.

Parameters:
id - the id of the record
Returns:
the ActiveRecord associated with the id

findById

public ActiveRecord findById(java.lang.Object id)
Finds the record with the given id, assuming ID is the primary key column. If there is no column name like "ID", an exception will be thrown.

Parameters:
id - the id of the record
Returns:
the ActiveRecord associated with the id

findByRESTfulId

public ActiveRecord findByRESTfulId(java.lang.String restfulId)
Finds the record with the given restfulId. See ActiveRecord.getRestfulId() for definition of RESTfulId. If there is no primary key, a null record is returned.

Parameters:
restfulId - the RESTful id of the record
Returns:
the ActiveRecord associated with the restfulId

findByPK

public ActiveRecord findByPK(java.lang.String pkString)
Finds the record with the given pkString. This method is the same as findByRESTfulId(String restfulId) method. See ActiveRecord.getRestfulId() for definition of RESTfulId which is the same as the primary key string. If there is no primary key, a null record is returned.

Parameters:
pkString - primary key string
Returns:
the ActiveRecord associated with the restfulId

findAllBySQL

public java.util.List<ActiveRecord> findAllBySQL(java.lang.String sql)

Finds all the records that satisfy the SQL query.

Parameters:
sql - a valid SQL query string
Returns:
a list of ActiveRecord objects

findAllBySQL

public java.util.List<ActiveRecord> findAllBySQL(java.lang.String sql,
                                                 java.util.Map<java.lang.String,java.lang.Object> inputs)

Finds all the records that satisfy the SQL query.

Parameters:
sql - a valid SQL query string
inputs - a map of name and value pairs
Returns:
a list of ActiveRecord objects

findAllBySQLKey

public java.util.List<ActiveRecord> findAllBySQLKey(java.lang.String sqlKey)

Finds all the records that satisfy the SQL corresponding to the SQL key.

Parameters:
sqlKey - a key to a SQL string defined in sql.properties file
Returns:
a list of ActiveRecord objects

findAllBySQLKey

public java.util.List<ActiveRecord> findAllBySQLKey(java.lang.String sqlKey,
                                                    java.util.Map<java.lang.String,java.lang.Object> inputs)

Finds all the records that satisfy the SQL corresponding to the SQL key.

Parameters:
sqlKey - a key to a SQL string defined in sql.properties file
inputs - a map of name and value pairs
Returns:
a list of ActiveRecord objects

findFirstBy

public ActiveRecord findFirstBy(java.lang.String columns,
                                java.lang.Object[] values)

Finds the first record that satisfy the conditions.

This is a dynamic finder method. See ActiveRecord class for dynamic finder examples.

Parameters:
columns - a string of column names linked by "_and_".
values - an Object[] array
Returns:
ActiveRecord

findLastBy

public ActiveRecord findLastBy(java.lang.String columns,
                               java.lang.Object[] values)

Finds the last record that satisfy the conditions.

This is a dynamic finder method. See ActiveRecord class for dynamic finder examples.

Parameters:
columns - a string of column names linked by "_and_".
values - an Object[] array
Returns:
ActiveRecord

findAllBy

public java.util.List<ActiveRecord> findAllBy(java.lang.String columns,
                                              java.lang.Object[] values)

Finds all the records that satisfy the conditions.

This is a dynamic finder method. See ActiveRecord class for dynamic finder examples.

Parameters:
columns - a string of column names linked by "_and_".
values - an Object[] array
Returns:
List of ActiveRecord objects

findAllBy

public java.util.List<ActiveRecord> findAllBy(java.lang.String columns,
                                              java.lang.Object[] values,
                                              java.util.Map<java.lang.String,java.lang.String> options)

Finds all the records that satisfy the conditions.

This is a dynamic finder method. See ActiveRecord class for dynamic finder examples.

Parameters:
columns - a string of column names linked by "_and_".
values - an Object[] array
options - a map of options
Returns:
List of ActiveRecord objects

findAllBy

public java.util.List<ActiveRecord> findAllBy(java.lang.String columns,
                                              java.lang.Object[] values,
                                              java.lang.String options)

Finds all the records that satisfy the conditions.

This is a dynamic finder method. See ActiveRecord class for dynamic finder examples.

Parameters:
columns - a string of column names linked by "_and_".
values - an Object[] array
options - a string of options
Returns:
List of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll()

Finds all the records of a table.

Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.util.Map<java.lang.String,java.lang.Object> conditions)

Finds all the records that satisfy the conditions.

See ActiveRecord class for conditions examples.

Parameters:
conditions - a map of column name and value pairs
Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.util.Map<java.lang.String,java.lang.Object> conditions,
                                            java.util.Map<java.lang.String,java.lang.String> options)

Finds all the records that satisfy the conditions and options.

See ActiveRecord class for conditions and options examples.

Parameters:
conditions - a map of column name and value pairs
options - a map of options
Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.util.Map<java.lang.String,java.lang.Object> conditions,
                                            java.lang.String options)

Finds all the records that satisfy the conditions and options.

See ActiveRecord class for conditions and options examples.

Parameters:
conditions - a map of column name and value pairs
options - a string of options
Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL)

Finds all the records that satisfy the conditions.

See ActiveRecord class for conditionsSQL examples.

Parameters:
conditionsSQL - a SQL fragment string
Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL,
                                            java.lang.String options)

Finds all the records that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and options examples.

Parameters:
conditionsSQL - a SQL fragment string
options - a string of options.
Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL,
                                            java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)

Finds all the records that satisfy the conditions.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL,
                                            java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData,
                                            java.util.Map<java.lang.String,java.lang.String> options)

Finds all the records that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
options - a map of options.
Returns:
a list of ActiveRecord objects

findAll

public java.util.List<ActiveRecord> findAll(java.lang.String conditionsSQL,
                                            java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData,
                                            java.lang.String options)

Finds all the records that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
options - a string of options.
Returns:
a list of ActiveRecord objects

findFirst

public ActiveRecord findFirst()

Finds the first record of a table.

Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.util.Map<java.lang.String,java.lang.Object> conditions)

Finds the first record that satisfy the conditions.

See ActiveRecord class for conditions examples.

Parameters:
conditions - a map of column name and value pairs
Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.util.Map<java.lang.String,java.lang.Object> conditions,
                              java.util.Map<java.lang.String,java.lang.String> options)

Finds the first record that satisfy the conditions and options.

See ActiveRecord class for conditions and options examples.

Parameters:
conditions - a map of column name and value pairs
options - a map of options
Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.util.Map<java.lang.String,java.lang.Object> conditions,
                              java.lang.String options)

Finds the first record that satisfy the conditions and options.

See ActiveRecord class for conditions and options examples.

Parameters:
conditions - a map of column name and value pairs
options - a string of options
Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.lang.String conditionsSQL)

Finds the first record that satisfy the conditions.

See ActiveRecord class for conditionsSQL examples.

Parameters:
conditionsSQL - a SQL fragment string
Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.lang.String conditionsSQL,
                              java.lang.String options)

Finds the first record that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and options examples.

Parameters:
conditionsSQL - a SQL fragment string
options - a string of options.
Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.lang.String conditionsSQL,
                              java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)

Finds the first record that satisfy the conditions.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.lang.String conditionsSQL,
                              java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData,
                              java.util.Map<java.lang.String,java.lang.String> options)

Finds the first record that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
options - a map of options.
Returns:
the first ActiveRecord found

findFirst

public ActiveRecord findFirst(java.lang.String conditionsSQL,
                              java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData,
                              java.lang.String options)

Finds the first record that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
options - a string of options.
Returns:
the first ActiveRecord found

findLast

public ActiveRecord findLast()

Finds the last record of a table.

Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.util.Map<java.lang.String,java.lang.Object> conditions)

Finds the last record that satisfy the conditions.

See ActiveRecord class for conditions examples.

Parameters:
conditions - a map of column name and value pairs
Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.util.Map<java.lang.String,java.lang.Object> conditions,
                             java.util.Map<java.lang.String,java.lang.String> options)

Finds the last record that satisfy the conditions and options.

See ActiveRecord class for conditions and options examples.

Parameters:
conditions - a map of column name and value pairs
options - a map of options
Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.util.Map<java.lang.String,java.lang.Object> conditions,
                             java.lang.String options)

Finds the last record that satisfy the conditions and options.

See ActiveRecord class for conditions and options examples.

Parameters:
conditions - a map of column name and value pairs
options - a string of options
Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.lang.String conditionsSQL)

Finds the last record that satisfy the conditions.

See ActiveRecord class for conditionsSQL examples.

Parameters:
conditionsSQL - a SQL fragment string
Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.lang.String conditionsSQL,
                             java.lang.String options)

Finds the last record that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and options examples.

Parameters:
conditionsSQL - a SQL fragment string
options - a string of options.
Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.lang.String conditionsSQL,
                             java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)

Finds the last record that satisfy the conditions.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.lang.String conditionsSQL,
                             java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData,
                             java.util.Map<java.lang.String,java.lang.String> options)

Finds the last record that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
options - a map of options.
Returns:
the last ActiveRecord found

findLast

public ActiveRecord findLast(java.lang.String conditionsSQL,
                             java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData,
                             java.lang.String options)

Finds the last record that satisfy the conditions and options.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
options - a string of options.
Returns:
the last ActiveRecord found

constructFindSQL

public java.util.Map<java.lang.String,java.lang.Object> constructFindSQL(java.lang.String conditionsSQL,
                                                                         java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData,
                                                                         java.util.Map<java.lang.String,java.lang.String> options)

getFinderSql

public java.lang.String getFinderSql(java.util.Map<java.lang.String,java.lang.String> options)

deleteById

public int deleteById(long id)
Deletes the record with the given id, assuming ID is the primary key column. If there is no column name like "ID", an exception will be thrown.

Parameters:
id - key to the object with field name "ID"
Returns:
int number of records deleted

deleteById

public int deleteById(java.lang.Object id)
Deletes the record with the given id, assuming ID is the primary key column. If there is no column name like "ID", an exception will be thrown.

Parameters:
id - key to the object with field name "ID"
Returns:
int number of records deleted

deleteByPK

public int deleteByPK(java.lang.String pkString)
Deletes the record with the given pkString. If there is no primary key defined, this method returns 0.

Parameters:
pkString - primary key string
Returns:
int number of records deleted

deleteByPrimaryKeyMap

public int deleteByPrimaryKeyMap(java.util.Map<java.lang.String,java.lang.Object> dataMap)
Deletes the record with the given data map containing primary keys. If not all primary key columns have data, an exception will be thrown.

Returns:
int number of records deleted

deleteBySQL

public int deleteBySQL(java.lang.String sql)
Deletes all the records that satisfy the SQL statement.

Parameters:
sql - a key to a SQL string
Returns:
int number of records deleted

deleteBySQL

public int deleteBySQL(java.lang.String sql,
                       java.util.Map<java.lang.String,java.lang.Object> inputs)
Deletes all the records that satisfy the SQL statement. The inputs is a map of name and value pairs related to the SQL statement.

Parameters:
sql - a key to a SQL string
inputs - a map of name and value pairs
Returns:
int number of records deleted

deleteBySQLKey

public int deleteBySQLKey(java.lang.String sqlKey)
Deletes all the records that satisfy the SQL specified by the sqlKey.

Parameters:
sqlKey - a key to a SQL string
Returns:
int number of records deleted

deleteBySQLKey

public int deleteBySQLKey(java.lang.String sqlKey,
                          java.util.Map<java.lang.String,java.lang.Object> inputs)
Deletes all the records that satisfy the SQL specified by the sqlKey. The inputs is a map of name and value pairs related to the SQL statement.

Parameters:
sqlKey - a key to a SQL string
inputs - a map of name and value pairs
Returns:
int number of records deleted

deleteAll

public int deleteAll(java.util.Map<java.lang.String,java.lang.Object> conditions)

Deletes all the records that satisfy the condition.

See ActiveRecord class for conditions examples.

Parameters:
conditions - a map of column name and value pairs
Returns:
int number of records deleted

deleteAll

public int deleteAll(java.lang.String conditionsSQL)

Deletes all the records that satisfy the conditions.

See ActiveRecord class for conditionsSQL examples.

Parameters:
conditionsSQL - a SQL fragment string
Returns:
int number of records deleted

deleteAll

public int deleteAll(java.lang.String conditionsSQL,
                     java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)

Deletes all the records that satisfy the conditions.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

Parameters:
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
Returns:
int number of records deleted

updateAll

public int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData)

Updates all the records of a table.

fieldData map is used to construct SET clause of the generated SQL. It consists of column name and its value pairs in the map. Primary key column and read-only columns are not updatable.

Parameters:
fieldData - a map of field name and its data to be set on any records
Returns:
int number of records updated

updateAll

public int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData,
                     java.lang.String conditionsSQL)

Updates all the records that satisfy a set of conditions supplied.

See ActiveRecord class for conditionsSQL examples.

fieldData map is used to construct SET clause of the generated SQL. It consists of column name and its value pairs in the map. Primary key column and read-only columns are not updatable.

Parameters:
fieldData - a map of field name and its data to be set on any records that satisfy the conditions.
conditionsSQL - A SQL fragment string
Returns:
int number of records updated

updateAll

public int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData,
                     java.lang.String conditionsSQL,
                     java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)

Updates all the records that satisfy the conditions.

See ActiveRecord class for conditionsSQL and conditionsSQLData examples.

fieldData map is used to construct SET clause of the generated SQL. It consists of column name and its value pairs in the map. Primary key column and read-only columns are not updatable.

Parameters:
fieldData - a map of field name and its data to be set on any records that satisfy the conditions.
conditionsSQL - a SQL fragment string
conditionsSQLData - a data map for dynamic attributes in conditionsSQL
Returns:
int number of records updated

updateBySQL

public int updateBySQL(java.lang.String sql)
Updates all the records that satisfy the SQL statement.

Parameters:
sql - A valid SQL string
Returns:
int number of records updated

updateBySQL

public int updateBySQL(java.lang.String sql,
                       java.util.Map<java.lang.String,java.lang.Object> inputs)
Updates all the records that satisfy the SQL statement.

Parameters:
sql - A valid SQL string
inputs - a map of name and value pairs
Returns:
int number of records updated

updateBySQLKey

public int updateBySQLKey(java.lang.String sqlKey)
Updates all the records that satisfy the SQL specified by sqlKey .

Parameters:
sqlKey - a key to a SQL string.
Returns:
int number of records updated

updateBySQLKey

public int updateBySQLKey(java.lang.String sqlKey,
                          java.util.Map<java.lang.String,java.lang.Object> inputs)
Updates all the records that satisfy the SQL specified by sqlKey .

Parameters:
sqlKey - a key to a SQL string
inputs - a map of name and value pairs
Returns:
int number of records updated

convertToPrimaryKeyDataMap

public java.util.Map<java.lang.String,java.lang.Object> convertToPrimaryKeyDataMap(java.lang.String pkString)
Converts a primary key RESTful id string to primary key map.

Returns:
map of primary key data