public abstract class Model<M extends Model> extends Object implements Serializable
A clever person solves a problem. A wise person avoids it. A stupid person makes it.
| 构造器和说明 |
|---|
Model() |
| 限定符和类型 | 方法和说明 |
|---|---|
M |
clear()
Remove all attributes of this model.
|
boolean |
delete()
Delete model.
|
boolean |
deleteById(Object... idValues)
Delete model by composite id values.
|
boolean |
deleteById(Object idValue)
Delete model by id.
|
boolean |
equals(Object o) |
List<M> |
find(String sql) |
List<M> |
find(String sql,
Object... paras)
Find model.
|
List<M> |
findByCache(String cacheName,
Object key,
String sql) |
List<M> |
findByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find model by cache.
|
M |
findById(Object... idValues)
Find model by composite id values.
|
M |
findById(Object idValue)
Find model by id.
|
M |
findByIdLoadColumns(Object[] idValues,
String columns)
Find model by composite id values and load specific columns only.
|
M |
findByIdLoadColumns(Object idValue,
String columns)
Find model by id and load specific columns only.
|
M |
findFirst(String sql) |
M |
findFirst(String sql,
Object... paras)
Find first model.
|
M |
findFirstByCache(String cacheName,
Object key,
String sql) |
M |
findFirstByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find first model by cache.
|
<T> T |
get(String attr)
Get attribute of any mysql type
|
<T> T |
get(String attr,
Object defaultValue)
Get attribute of any mysql type.
|
String[] |
getAttrNames()
Return attribute names of this model.
|
protected Map<String,Object> |
getAttrs()
Return attribute Map.
|
Set<Map.Entry<String,Object>> |
getAttrsEntrySet()
Return attribute Set.
|
Object[] |
getAttrValues()
Return attribute values of this model.
|
BigDecimal |
getBigDecimal(String attr)
Get attribute of mysql type: decimal, numeric
|
BigInteger |
getBigInteger(String attr)
Get attribute of mysql type: unsigned bigint
|
Boolean |
getBoolean(String attr)
Get attribute of mysql type: bit, tinyint(1)
|
byte[] |
getBytes(String attr)
Get attribute of mysql type: binary, varbinary, tinyblob, blob, mediumblob, longblob
|
Date |
getDate(String attr)
Get attribute of mysql type: date, year
|
Double |
getDouble(String attr)
Get attribute of mysql type: real, double
|
Float |
getFloat(String attr)
Get attribute of mysql type: float
|
Integer |
getInt(String attr)
Get attribute of mysql type: int, integer, tinyint(n) n > 1, smallint, mediumint
|
Long |
getLong(String attr)
Get attribute of mysql type: bigint, unsign int
|
Number |
getNumber(String attr)
Get attribute of any type that extends from Number
|
String |
getStr(String attr)
Get attribute of mysql type: varchar, char, enum, set, text, tinytext, mediumtext, longtext
|
Time |
getTime(String attr)
Get attribute of mysql type: time
|
Timestamp |
getTimestamp(String attr)
Get attribute of mysql type: timestamp, datetime
|
int |
hashCode() |
M |
keep(String... attrs)
Keep attributes of this model and remove other attributes.
|
M |
keep(String attr)
Keep attribute of this model and remove other attributes.
|
Page<M> |
paginate(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
Page<M> |
paginate(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras)
Paginate.
|
Page<M> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
Page<M> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras)
Paginate by cache.
|
M |
put(Map<String,Object> map)
Put map to the model without check attribute name.
|
M |
put(Model model)
Put other model to the model without check attribute name.
|
M |
put(Record record)
Put record to the model without check attribute name.
|
M |
put(String key,
Object value)
Put key value pair to the model without check attribute name.
|
M |
remove(String... attrs)
Remove attributes of this model.
|
M |
remove(String attr)
Remove attribute of this model.
|
M |
removeNullValueAttrs()
Remove attributes if it is null.
|
boolean |
save()
Save model.
|
M |
set(String attr,
Object value)
Set attribute to model.
|
M |
setAttrs(M model)
Set attributes with other model.
|
M |
setAttrs(Map<String,Object> attrs)
Set attributes with Map.
|
String |
toJson()
Return json string of this model.
|
Record |
toRecord()
Convert model to record.
|
String |
toString() |
boolean |
update()
Update model.
|
M |
use(String configName)
Switching data source, dialect and all config by configName
|
public M set(String attr, Object value)
attr - the attribute name of the modelvalue - the value of the attributeActiveRecordException - if the attribute is not exists of the modelpublic M put(String key, Object value)
public Record toRecord()
public <T> T get(String attr)
public <T> T get(String attr, Object defaultValue)
public String getStr(String attr)
public Integer getInt(String attr)
public BigInteger getBigInteger(String attr)
public Timestamp getTimestamp(String attr)
public BigDecimal getBigDecimal(String attr)
public byte[] getBytes(String attr)
public Page<M> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras)
pageNumber - the page numberpageSize - the page sizeselect - the select part of the sql statementsqlExceptSelect - the sql statement excluded select partparas - the parameters of sqlpublic Page<M> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect)
protected Map<String,Object> getAttrs()
Danger! The update method will ignore the attribute if you change it directly. You must use set method to change attribute that update method can handle it.
public boolean save()
public boolean delete()
public boolean deleteById(Object idValue)
idValue - the id value of the modelpublic boolean deleteById(Object... idValues)
idValues - the composite id values of the modelpublic boolean update()
public List<M> find(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter placeholdersparas - the parameters of sqlpublic List<M> find(String sql)
find(String, Object...)public M findFirst(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter placeholdersparas - the parameters of sqlpublic M findFirst(String sql)
sql - an SQL statementfindFirst(String, Object...)public M findById(Object idValue)
Example: User user = User.dao.findById(123);
idValue - the id value of the modelpublic M findById(Object... idValues)
Example: User user = User.dao.findById(123, 456);
idValues - the composite id values of the modelpublic M findByIdLoadColumns(Object idValue, String columns)
Example: User user = User.dao.findByIdLoadColumns(123, "name, age");
idValue - the id value of the modelcolumns - the specific columns to loadpublic M findByIdLoadColumns(Object[] idValues, String columns)
Example:
User user = User.dao.findByIdLoadColumns(new Object[]{123, 456}, "name, age");
idValues - the composite id values of the modelcolumns - the specific columns to loadpublic M setAttrs(M model)
model - the Modelpublic M setAttrs(Map<String,Object> attrs)
attrs - attributes of this modelpublic M remove(String attr)
attr - the attribute name of the modelpublic M remove(String... attrs)
attrs - the attribute names of the modelpublic M removeNullValueAttrs()
public M keep(String... attrs)
attrs - the attribute names of the modelpublic M keep(String attr)
attr - the attribute name of the modelpublic M clear()
public List<M> findByCache(String cacheName, Object key, String sql, Object... paras)
cacheName - the cache namekey - the key used to get data from cachefind(String, Object...)public M findFirstByCache(String cacheName, Object key, String sql, Object... paras)
cacheName - the cache namekey - the key used to get data from cachesql - an SQL statement that may contain one or more '?' IN parameter placeholdersparas - the parameters of sqlfindFirst(String, Object...)public Page<M> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras)
cacheName - the cache namekey - the key used to get date from cachepaginate(int, int, String, String, Object...)public Page<M> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect)
public String[] getAttrNames()
public Object[] getAttrValues()
public String toJson()
Copyright © 2015. All rights reserved.