|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.scooterframework.orm.activerecord.ActiveRecordClass
public abstract class ActiveRecordClass
ActiveRecord defines static operations that each subclass of
the ActiveRecord
class must implement. Scooter automatically add this method into the
compiled model (subclass of ActiveRecord) class in a web container.
| Constructor Summary | |
|---|---|
ActiveRecordClass()
|
|
| Method Summary | ||
|---|---|---|
static java.lang.Object |
average(java.lang.String field)
Calculates average of a field. |
|
static java.lang.Object |
average(java.lang.String field,
java.lang.String options)
Calculates average of a field. |
|
static java.lang.Object |
calculate(java.lang.String function,
java.lang.String field,
java.lang.String options)
Calculates by a function on a field. |
|
static java.util.List<java.lang.String> |
columnNames()
Returns a list of column names. |
|
static java.util.List<ColumnInfo> |
columns()
Returns a list of ColumnInfo instances. |
|
static java.lang.String |
connectionName()
Returns the connection name of associated with the record type. |
|
static long |
count()
Counts number of records. |
|
static long |
count(java.lang.String field)
Counts number of records for a field. |
|
static long |
count(java.lang.String field,
java.lang.String options)
Counts number of records for a field. |
|
static int |
deleteAll(java.util.Map<java.lang.String,java.lang.Object> conditions)
Deletes all the records that satisfy the conditions. |
|
static int |
deleteAll(java.lang.String conditionsSQL)
Deletes all the records that satisfy the conditions. |
|
static int |
deleteAll(java.lang.String conditionsSQL,
java.util.Map<java.lang.String,java.lang.Object> conditionsSQLData)
Deletes all the records that satisfy the conditions. |
|
static int |
deleteById(long id)
Deletes the record with the given id, assuming ID is the primary key column. |
|
static int |
deleteById(java.lang.Object id)
Deletes the record with the given id, assuming ID is the primary key column. |
|
static int |
deleteByPK(java.lang.String pkString)
Deletes the record with the given primary key string. |
|
static int |
deleteByPrimaryKeyMap(java.util.Map<java.lang.String,java.lang.Object> inputs)
Deletes the record with the given data map containing primary keys. |
|
static int |
deleteBySQL(java.lang.String sql)
Deletes all the records that satisfy the SQL statement. |
|
static 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. |
|
static int |
deleteBySQLKey(java.lang.String sqlKey)
Deletes all the records that satisfy the SQL specified by the sqlKey. |
|
static 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. |
|
static java.util.List<ActiveRecord> |
findAll()
Finds all the records of a table. |
|
static java.util.List<ActiveRecord> |
findAllBy(java.lang.String columns,
java.lang.Object[] values)
Finds all the records that satisfy the conditions. |
|
static 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. |
|
static 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. |
|
static java.util.List<ActiveRecord> |
findAllBySQL(java.lang.String sql)
Finds all the records that satisfy the SQL query. |
|
static 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. |
|
static java.util.List<ActiveRecord> |
findAllBySQLKey(java.lang.String sqlKey)
Finds all the records that satisfy the sql corresponding to the sql key. |
|
static 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. |
|
static
|
findById(long id)
Finds the record with the given id, assuming ID is the primary key column. |
|
static
|
findById(java.lang.Object id)
Finds the record with the given id, assuming ID is the primary key column. |
|
static
|
findByPK(java.lang.String pkString)
Finds the record with the given pkString. |
|
static
|
findByRESTfulId(java.lang.String restfulId)
Finds the record with the given restfulId. |
|
static
|
findFirst()
Finds the first record of a table. |
|
static
|
findFirstBy(java.lang.String columns,
java.lang.Object[] values)
Finds the first record that satisfy the conditions. |
|
static
|
findLast()
Finds the last record of a table. |
|
static
|
findLastBy(java.lang.String columns,
java.lang.Object[] values)
Finds the last record that satisfy the conditions. |
|
static QueryBuilder |
groupBy(java.lang.String groupBy)
Setup group-by clause. |
|
static QueryBuilder |
having(java.lang.String having)
Setup having clause. |
|
static
|
homeInstance()
Returns the home instance of the record type. |
|
static QueryBuilder |
includes(java.lang.String includes)
Setup associated models for eager loading. |
|
static QueryBuilder |
includes(java.lang.String includes,
boolean strict)
Setup associated models for eager loading. |
|
static QueryBuilder |
includes(java.lang.String includes,
java.lang.String joinType)
Setup associated models for eager loading. |
|
static QueryBuilder |
limit(int limit)
Setup limit for number of records per retrieval. |
|
static java.lang.Object |
maximum(java.lang.String field)
Calculates maximum of a field. |
|
static java.lang.Object |
maximum(java.lang.String field,
java.lang.String options)
Calculates maximum of a field. |
|
static java.lang.Object |
minium(java.lang.String field)
Calculates minimum of a field. |
|
static java.lang.Object |
minium(java.lang.String field,
java.lang.String options)
Calculates minimum of a field. |
|
static
|
newRecord()
Creates a new instance. |
|
static QueryBuilder |
offset(int offset)
Setup number of records to skip. |
|
static QueryBuilder |
orderBy(java.lang.String orderBy)
Setup group-by clause. |
|
static QueryBuilder |
page(int page)
Setup current page number. |
|
static java.util.List<java.lang.String> |
primaryKeyNames()
Returns a list of primary key column names. |
|
static java.util.List<java.lang.String> |
readOnlyColumnNames()
Returns a list of read-only column names. |
|
static RowInfo |
rowInfo()
Returns the RowInfo of the record. |
|
static java.lang.String |
simpleTableName()
Returns the simple table name of associated with the record type. |
|
static java.lang.Object |
sum(java.lang.String field)
Calculates sum of a field. |
|
static java.lang.Object |
sum(java.lang.String field,
java.lang.String options)
Calculates sum of a field. |
|
static java.lang.String |
tableName()
Returns the table name of associated with the record type. |
|
static int |
updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData)
Updates all the records of a table. |
|
static int |
updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData,
java.lang.String conditionsSQL)
Updates all the records that satisfy the conditions. |
|
static 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. |
|
static int |
updateBySQL(java.lang.String sql)
Updates all the records that satisfy the SQL statement. |
|
static 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. |
|
static int |
updateBySQLKey(java.lang.String sqlKey)
Updates all the records that satisfy the SQL specified by sqlKey . |
|
static 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 . |
|
static QueryBuilder |
where(java.lang.String conditionsSQL)
Setup where clause. |
|
static QueryBuilder |
where(java.lang.String conditionsSQL,
java.util.Map<java.lang.String,java.lang.Object> conditionsSQLDataMap)
Setup where clause. |
|
static 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 |
| Constructor Detail |
|---|
public ActiveRecordClass()
| Method Detail |
|---|
public static <T extends ActiveRecord> T newRecord()
The created instance is based on meta info for table as returned by
ActiveRecord.getTableName()
and database connection name as returned by
ActiveRecord.getConnectionName().
See ActiveRecord.ActiveRecord(String connectionName, String tableName).
public static QueryBuilder where(java.lang.String conditionsSQL)
Setup where clause.
conditionsSQL - a valid SQL query where clause string
public static QueryBuilder where(java.lang.String conditionsSQL,
java.lang.Object[] conditionsSQLData)
Setup where clause.
conditionsSQL - a valid SQL query where clause stringconditionsSQLData - an array of data for the conditionsSQL string
public static QueryBuilder where(java.lang.String conditionsSQL,
java.util.Map<java.lang.String,java.lang.Object> conditionsSQLDataMap)
Setup where clause.
conditionsSQL - a valid SQL query where clause stringconditionsSQLDataMap - a map of data for the keys in the conditionsSQL string
public static QueryBuilder includes(java.lang.String includes)
Setup associated models for eager loading.
includes - a string of associated models
public static QueryBuilder includes(java.lang.String includes,
java.lang.String joinType)
Setup associated models for eager loading.
includes - a string of associated modelsjoinType - type of join
public static 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.
includes - a string of associated modelsstrict - true if strict
public static QueryBuilder groupBy(java.lang.String groupBy)
Setup group-by clause.
groupBy - a valid SQL query group-by clause string
public static QueryBuilder having(java.lang.String having)
Setup having clause.
having - a valid SQL query having clause string
public static QueryBuilder orderBy(java.lang.String orderBy)
Setup group-by clause.
orderBy - a valid SQL query order-by clause string
public static QueryBuilder limit(int limit)
Setup limit for number of records per retrieval.
limit - number of records for each retrieval
public static QueryBuilder offset(int offset)
Setup number of records to skip.
offset - number of records to skip
public static QueryBuilder page(int page)
Setup current page number. All records in previous pages are skipped.
page - current page number
public static <T extends ActiveRecord> T findById(long id)
id - the id of the record
public static <T extends ActiveRecord> T findById(java.lang.Object id)
id - the id of the record
public static <T extends ActiveRecord> T findByRESTfulId(java.lang.String restfulId)
ActiveRecord.getRestfulId()
for definition of RESTfulId.
If there is no primary key, a null record is returned.
restfulId - the RESTful id of the record
public static <T extends ActiveRecord> T findByPK(java.lang.String pkString)
findByRESTfulId 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.
pkString - the primary key string of the record
public static java.util.List<ActiveRecord> findAllBySQL(java.lang.String sql)
Finds all the records that satisfy the SQL query.
sql - a valid SQL query string
public static 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.
sql - a valid SQL query stringinputs - a map of name and value pairs
public static java.util.List<ActiveRecord> findAllBySQLKey(java.lang.String sqlKey)
Finds all the records that satisfy the sql corresponding to the sql key.
sqlKey - a key to a sql string defined in sql.properties file
public static 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.
sqlKey - a key to a sql string defined in sql.properties fileinputs - a map of name and value pairs
public static <T extends ActiveRecord> T findFirstBy(java.lang.String columns,
java.lang.Object[] values)
Finds the first record that satisfy the conditions.
This is a dynamic finder method.
See top of the ActiveRecord
class for dynamic finder examples.
columns - a string of column names linked by "_and_".values - an Object[] array
public static <T extends ActiveRecord> T findLastBy(java.lang.String columns,
java.lang.Object[] values)
Finds the last record that satisfy the conditions.
This is a dynamic finder method.
See top of the ActiveRecord
class for dynamic finder examples.
columns - a string of column names linked by "_and_".values - an Object[] array
public static 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 top of the ActiveRecord
class for dynamic finder examples.
columns - a string of column names linked by "_and_".values - an Object[] array
public static 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 top of the ActiveRecord
class for dynamic finder examples.
columns - a string of column names linked by "_and_".values - an Object[] arrayoptions - a map of options
public static 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 top of the ActiveRecord
class for dynamic finder examples.
columns - a string of column names linked by "_and_".values - an Object[] arrayoptions - a string of options
public static java.util.List<ActiveRecord> findAll()
Finds all the records of a table.
public static <T extends ActiveRecord> T findFirst()
Finds the first record of a table.
public static <T extends ActiveRecord> T findLast()
Finds the last record of a table.
public static int updateBySQL(java.lang.String sql)
sql - A valid SQL string
public static int updateBySQL(java.lang.String sql,
java.util.Map<java.lang.String,java.lang.Object> inputs)
sql - A valid SQL stringinputs - a map of name and value pairs
public static int updateBySQLKey(java.lang.String sqlKey)
sqlKey - a key to a SQL string.
public static int updateBySQLKey(java.lang.String sqlKey,
java.util.Map<java.lang.String,java.lang.Object> inputs)
sqlKey - a key to a SQL stringinputs - a map of name and value pairs
public static int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData)
Updates all the records of a table.
This method sends a single SQL UPDATE statement to database. No callbacks are triggered. If callbacks are necessary for handling associations, use findAll method to retrieve a list of records and then call each record's update() method.
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.
fieldData - a map of field name and its data to be set on any records
public static int updateAll(java.util.Map<java.lang.String,java.lang.Object> fieldData,
java.lang.String conditionsSQL)
Updates all the records that satisfy the conditions.
See top of the ActiveRecord
class for conditionsSQL examples.
This method sends a single SQL UPDATE statement to database. No callbacks are triggered. If callbacks are necessary for handling associations, use findAll method to retrieve a list of records and then call each record's update() method.
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.
fieldData - a map of field name and its data to be set on any
records that satisfy the conditions.conditionsSQL - a SQL fragment string
public static 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 top of the ActiveRecord
class for conditionsSQL and conditionsSQLData examples.
This method sends a single SQL UPDATE statement to database. No callbacks are triggered. If callbacks are necessary for handling associations, use findAll method to retrieve a list of records and then call each record's update() method.
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.
fieldData - a map of field name and its data to be set.conditionsSQL - a SQL fragment stringconditionsSQLData - a data map for dynamic attributes in conditionsSQL
public static int deleteById(long id)
id - key to the object with field name "ID"
public static int deleteById(java.lang.Object id)
id - key to the object with field name "ID"
public static int deleteByPK(java.lang.String pkString)
ActiveRecord.getPK()
for format of the primary key string.
pkString - primary key string
public static int deleteByPrimaryKeyMap(java.util.Map<java.lang.String,java.lang.Object> inputs)
inputs - a map of name and value pairs
public static int deleteBySQL(java.lang.String sql)
sql - a key to a SQL string
public static int deleteBySQL(java.lang.String sql,
java.util.Map<java.lang.String,java.lang.Object> inputs)
sql - a key to a SQL stringinputs - a map of name and value pairs
public static int deleteBySQLKey(java.lang.String sqlKey)
sqlKey - a key to a SQL string
public static int deleteBySQLKey(java.lang.String sqlKey,
java.util.Map<java.lang.String,java.lang.Object> inputs)
sqlKey - a key to a SQL stringinputs - a map of name and value pairs
public static int deleteAll(java.util.Map<java.lang.String,java.lang.Object> conditions)
Deletes all the records that satisfy the conditions.
See top of the ActiveRecord
class for conditions examples.
This method sends a single SQL DELETE statement to database. No callbacks are triggered. If callbacks are necessary for handling associations, use findAll method to retrieve a list of records and then call each record's delete() method.
conditions - a map of column name and value pairs
public static int deleteAll(java.lang.String conditionsSQL)
Deletes all the records that satisfy the conditions.
See top of the ActiveRecord
class for conditionsSQL examples.
This method sends a single SQL DELETE statement to database. No callbacks are triggered. If callbacks are necessary for handling associations, use findAll method to retrieve a list of records and then call each record's delete() method.
conditionsSQL - a SQL fragment string
public static 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 top of the ActiveRecord
class for conditionsSQL and conditionsSQLData examples.
This method sends a single SQL DELETE statement to database. No callbacks are triggered. If callbacks are necessary for handling associations, use findAll method to retrieve a list of records and then call each record's delete() method.
conditionsSQL - a SQL fragment stringconditionsSQLData - a data map for dynamic attributes in conditionsSQL
public static long count()
public static long count(java.lang.String field)
field - name of the field
public static long count(java.lang.String field,
java.lang.String options)
field - name of the fieldoptions - options for calculation
public static java.lang.Object sum(java.lang.String field)
field - the column name
public static java.lang.Object sum(java.lang.String field,
java.lang.String options)
field - the column nameoptions - options of calculation
public static java.lang.Object average(java.lang.String field)
field - the column name
public static java.lang.Object average(java.lang.String field,
java.lang.String options)
field - the column nameoptions - options of calculation
public static java.lang.Object maximum(java.lang.String field)
field - the column name
public static java.lang.Object maximum(java.lang.String field,
java.lang.String options)
field - the column nameoptions - options of calculation
public static java.lang.Object minium(java.lang.String field)
field - the column name
public static java.lang.Object minium(java.lang.String field,
java.lang.String options)
field - the column nameoptions - options of calculation
public static java.lang.Object calculate(java.lang.String function,
java.lang.String field,
java.lang.String options)
function - the sql function namefield - the column nameoptions - options of calculation
public static <T extends ActiveRecord> T homeInstance()
public static java.util.List<java.lang.String> primaryKeyNames()
public static java.util.List<java.lang.String> readOnlyColumnNames()
public static java.util.List<java.lang.String> columnNames()
public static java.util.List<ColumnInfo> columns()
ColumnInfo instances.
public static RowInfo rowInfo()
RowInfo of the record.
public static java.lang.String connectionName()
public static java.lang.String tableName()
public static java.lang.String simpleTableName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||