public class CrudModelImpl extends Object implements CrudModelInf
| Modifier and Type | Method and Description |
|---|---|
int[] |
batchDelete(Connection conn,
Collection<? extends DBObject> modelList,
int batchSize)
Batch delete records using the columns names of the record in recordList.
|
int[] |
batchDelete(Connection conn,
Collection<? extends DBObject> modelList,
int batchSize,
boolean useFirstSql) |
int[] |
batchInsert(Connection conn,
Collection<? extends DBObject> modelList,
boolean insertFast,
boolean useOptimisticLock,
int batchSize)
Batch save models using the "insert into ..." sql generated by the model in modelList.
|
int[] |
batchInsert(Connection conn,
Collection<? extends DBObject> modelList,
boolean insertFast,
boolean useOptimisticLock,
int batchSize,
boolean useAll)
批量插入
|
int[] |
batchUpdate(Connection conn,
Collection<? extends DBObject> modelList,
int batchSize)
Batch update models using the attrs names of the model in
modelList.
|
int[] |
batchUpdate(Connection conn,
Collection<? extends DBObject> modelList,
int batchSize,
boolean useNvl) |
boolean |
createTable(Connection conn,
Class<?> clz)
创建表
|
int |
delete(Connection conn,
DBObject obj)
删除方法
|
<T extends DBObject> |
deleteByPrimaryKeys(Connection conn,
Class<T> clz,
Object... keyParams)
根据主键删除
|
int |
deleteCascade(Connection conn,
DBObject obj,
DBCascadeField... fields)
将对象删除的同时,也将符合一个正则表达式的所有关联字段关联的对象统统删除
注意:
|
<T extends DBObject> |
deleteLinks(Connection con,
T obj,
DBCascadeField... fields)
仅删除对象所有的关联字段,并不包括对象本身。
注意:
|
<T extends DBObject> |
deleteRelation(Connection con,
T obj,
DBCascadeField... fields)
多对多
|
boolean |
dropTable(Connection conn,
Class<?> clz)
删除表
|
int |
execute(Connection conn,
SQLContext context)
Execute sql update
|
<T extends DBObject> |
exists(Connection conn,
T query)
查询对象是否存在
|
<T extends DBObject> |
existsByPrimaryKeys(Connection conn,
Class<T> clz,
Object... keyParams)
根据主键查询是否存在
|
<T extends DBObject> |
fetchCascade(Connection conn,
T query,
Class<T> clz,
DBCascadeField... fields)
fixme beetsql hibernate 使用了一级缓存,导致比他们慢
根据查询条件查询列表并根据级联字段查询级联对象
|
<T extends DBObject> |
fetchLinks(Connection conn,
T obj)
根据一个正则表达式,获取对象所有的关联字段
|
<T extends DBObject> |
fetchLinks(Connection conn,
T obj,
DBCascadeField... fields)
根据字段,获取对象所有的关联字段
|
protected <T extends DBObject> |
fetchLinks(Connection conn,
T obj,
String... fields) |
static CrudModelImpl |
getInstance() |
int |
insert(Connection conn,
DBObject obj)
插入
|
int |
insert(Connection conn,
DBObject obj,
boolean fast,
boolean useOptimisticLock) |
int |
insertCascade(Connection conn,
DBObject obj,
DBCascadeField... fields)
将对象插入数据库同时,也将符合一个正则表达式的所有关联字段关联的对象统统插入相应的数据库
|
<T extends DBObject> |
insertLinks(Connection con,
T obj,
DBCascadeField... fields)
仅将对象所有的关联字段插入到数据库中,并不包括对象本身
|
<T extends DBObject> |
insertRelation(Connection con,
T obj,
DBCascadeField... fields)
将对象的一个或者多个,多对多的关联信息,插入数据表
|
int |
merge(Connection conn,
DBObject obj)
合并记录
|
<T> T |
select(Connection conn,
ResultSetCallback<T> rsh,
SQLContext context) |
<T extends DBObject> |
selectByPrimaryKeys(Connection conn,
Class<T> clz,
Object... keyParams) |
<T extends DBObject> |
selectCount(Connection conn,
T query)
查询总数
|
<T extends DBObject> |
selectIterator(Connection conn,
OrmIterator<T> ormIt,
T query)
查询结果返回迭代
|
<T extends DBObject> |
selectIterator(Connection conn,
OrmIterator<T> ormIt,
T query,
long start,
int limit)
查询结果返回迭代(分页查询)
|
<T> List<T> |
selectList(Connection conn,
Class<T> beanClass,
SQLContext context) |
<T> List<T> |
selectList(Connection conn,
Class<T> beanClass,
SQLContext context,
long start,
int limit) |
<T extends DBObject> |
selectList(Connection conn,
T query)
查询列表
|
<T extends DBObject> |
selectList(Connection conn,
T query,
long start,
int limit) |
<T extends DBObject> |
selectListForUpdate(Connection conn,
T query)
悲观锁(Pessimistic Lock)
|
List<Map<String,Object>> |
selectListMap(Connection conn,
SQLContext context) |
<T> T |
selectOne(Connection conn,
Class<T> beanClass,
SQLContext context) |
<T extends DBObject> |
selectOne(Connection conn,
T query)
查询一条记录,如果结果不唯一则抛出异常
|
<T extends DBObject> |
selectOneForUpdate(Connection conn,
T query)
悲观锁(Pessimistic Lock)
|
<T> Page<T> |
selectPage(Connection conn,
long start,
int limit,
Class<T> beanClass,
SQLContext context) |
<T> Page<T> |
selectPage(Connection conn,
long start,
int limit,
Class<T> beanClass,
SQLContext context,
PageStrategy strategy) |
<T extends DBObject> |
selectPage(Connection conn,
T query,
long start,
int limit)
查询并分页
|
<T extends DBObject> |
selectStream(Connection conn,
OrmStream<T> ormStream,
T query)
查询结果返回迭代
|
int |
update(Connection conn,
DBObject obj)
更新对象(不区分乐观锁条件)
|
protected SQLContext |
update(Connection conn,
DBObject obj,
boolean useOptimisticLock) |
<T extends DBObject> |
updateAndSet(Connection conn,
T obj)
乐观锁(Optimistic Lock), 以特定字段的值作为限制条件,更新对象,并更新该字段的值.参考字段的Java属性名.必须设置了@Version标签
注意:对于时间作为乐观锁,由于数据库和java时间存在差异,如果需要设置更新后的值,需要重新调用OptimisticLock.setNewOptimisticLockValues查询方法设置最新的值. |
int |
updateCascade(Connection conn,
DBObject obj,
DBCascadeField... fields)
将对象更新的同时,也将符合一个正则表达式的所有关联字段关联的对象统统更新
|
<T extends DBObject> |
updateLinks(Connection con,
T obj,
DBCascadeField... fields)
仅更新对象所有的关联字段,并不包括对象本身
|
<T extends DBObject> |
updateRelation(Connection con,
T obj,
DBCascadeField... fields)
多对多关联是通过一个中间表将两条数据表记录关联起来。
|
<T extends DBObject> |
updateWithVersion(Connection conn,
T obj)
乐观锁(Optimistic Lock)
根据乐观锁条件更新,并会更新数据库中的乐观锁条件.但不会更新对象的乐观锁字段的值. |
public static CrudModelImpl getInstance()
public <T extends DBObject> boolean existsByPrimaryKeys(Connection conn, Class<T> clz, Object... keyParams)
CrudModelInfexistsByPrimaryKeys in interface CrudModelInfclz - 实体类keyParams - 主键列public <T extends DBObject> boolean exists(Connection conn, T query)
CrudModelInfexists in interface CrudModelInfquery - 查询实体public <T extends DBObject> T selectByPrimaryKeys(Connection conn, Class<T> clz, Object... keyParams)
selectByPrimaryKeys in interface CrudModelInfpublic <T> T select(Connection conn, ResultSetCallback<T> rsh, SQLContext context)
public List<Map<String,Object>> selectListMap(Connection conn, SQLContext context)
selectListMap in interface CrudModelInfpublic <T> T selectOne(Connection conn, Class<T> beanClass, SQLContext context)
selectOne in interface CrudModelInfpublic <T> List<T> selectList(Connection conn, Class<T> beanClass, SQLContext context)
selectList in interface CrudModelInfpublic <T> List<T> selectList(Connection conn, Class<T> beanClass, SQLContext context, long start, int limit)
selectList in interface CrudModelInfpublic <T> Page<T> selectPage(Connection conn, long start, int limit, Class<T> beanClass, SQLContext context)
selectPage in interface CrudModelInfconn - start - 0开始limit - 限制多少条数据beanClass - context - 如果为分页参数,内部的listSql--带分页参数,countSql不能为空public <T> Page<T> selectPage(Connection conn, long start, int limit, Class<T> beanClass, SQLContext context, PageStrategy strategy)
selectPage in interface CrudModelInfcontext - 如果为分页参数,内部的listSql--带分页参数,countSql不能为空strategy - 分页策略public <T extends DBObject> Long selectCount(Connection conn, T query)
CrudModelInfselectCount in interface CrudModelInfpublic <T extends DBObject> T selectOne(Connection conn, T query)
CrudModelInfselectOne in interface CrudModelInfpublic <T extends DBObject> T selectOneForUpdate(Connection conn, T query)
CrudModelInfselectOneForUpdate in interface CrudModelInfpublic <T extends DBObject> List<T> selectList(Connection conn, T query)
CrudModelInfselectList in interface CrudModelInfquery - 查询请求。
public <T extends DBObject> List<T> selectList(Connection conn, T query, long start, int limit)
selectList in interface CrudModelInfpublic <T extends DBObject> List<T> selectListForUpdate(Connection conn, T query)
CrudModelInfselectListForUpdate in interface CrudModelInfpublic <T extends DBObject> Page<T> selectPage(Connection conn, T query, long start, int limit)
CrudModelInfselectPage in interface CrudModelInfquery - 查询请求start - 起始记录,offset。从0开始。limit - 限制记录条数。如每页10条传入10。public <T extends DBObject> void selectIterator(Connection conn, OrmIterator<T> ormIt, T query)
CrudModelInfselectIterator in interface CrudModelInfpublic <T extends DBObject> void selectIterator(Connection conn, OrmIterator<T> ormIt, T query, long start, int limit)
CrudModelInfselectIterator in interface CrudModelInfpublic <T extends DBObject> void selectStream(Connection conn, OrmStream<T> ormStream, T query)
CrudModelInfselectStream in interface CrudModelInfpublic int insert(Connection conn, DBObject obj)
CrudModelInfinsert in interface CrudModelInfpublic int insert(Connection conn, DBObject obj, boolean fast, boolean useOptimisticLock)
insert in interface CrudModelInffast - 是否是快速插入public int insertCascade(Connection conn, DBObject obj, DBCascadeField... fields)
CrudModelInf关于关联字段更多信息,请参看 '@One' | '@Many' | '@ManyMany' 更多的描述
insertCascade in interface CrudModelInffields - 指定字段,控制力度更细,至少一个或多个 描述了什么样的关联字段将被关注。如果为 null,则表示全部的关联字段都会被插入public int update(Connection conn, DBObject obj)
CrudModelInfupdate in interface CrudModelInfprotected SQLContext update(Connection conn, DBObject obj, boolean useOptimisticLock)
conn - obj - useOptimisticLock - 是否使用乐观锁public <T extends DBObject> int updateAndSet(Connection conn, T obj)
CrudModelInf
1.对于数字,则+1;
2.对于日期取当前时间戳.
3.对于字符串,取UUID的值.
执行的sql如下:
update t_user set age=30, city="广州", version=version+1 where name="wendal" and version=124;updateAndSet in interface CrudModelInfobj - 需要更新的对象, 必须带主键,并设置过主键的值.public <T extends DBObject> int updateWithVersion(Connection conn, T obj)
CrudModelInfupdateWithVersion in interface CrudModelInfobj - 需要更新的对象, 必须有@Version属性public int updateCascade(Connection conn, DBObject obj, DBCascadeField... fields)
CrudModelInf关于关联字段更多信息,请参看 '@One' | '@Many' | '@ManyMany' 更多的描述
updateCascade in interface CrudModelInfobj - 数据对象fields - 指定字段,控制力度更细,至少一个或多个,描述了什么样的关联字段将被关注。如果为 null,则表示全部的关联字段都会被更新public int merge(Connection conn, DBObject obj)
CrudModelInfmerge in interface CrudModelInfpublic <T extends DBObject> int deleteByPrimaryKeys(Connection conn, Class<T> clz, Object... keyParams)
CrudModelInfdeleteByPrimaryKeys in interface CrudModelInfpublic int delete(Connection conn, DBObject obj)
CrudModelInfdelete in interface CrudModelInfpublic int execute(Connection conn, SQLContext context)
execute in interface CrudModelInfconn - context - public int deleteCascade(Connection conn, DBObject obj, DBCascadeField... fields)
CrudModelInfJava 对象的字段会被保留,这里的删除,将只会删除数据库中的记录
关于关联字段更多信息,请参看 '@One' | '@Many' | '@ManyMany' 更多的描述
deleteCascade in interface CrudModelInffields - 指定字段,控制力度更细,至少一个或多个 描述了什么样的关联字段将被关注。如果为 null,则表示全部的关联字段都会被删除public int[] batchInsert(Connection conn, Collection<? extends DBObject> modelList, boolean insertFast, boolean useOptimisticLock, int batchSize)
batchInsert in interface CrudModelInfpublic int[] batchInsert(Connection conn, Collection<? extends DBObject> modelList, boolean insertFast, boolean useOptimisticLock, int batchSize, boolean useAll)
CrudModelInfbatchInsert in interface CrudModelInfuseAll - 是否使用一条语句做完插入public int[] batchUpdate(Connection conn, Collection<? extends DBObject> modelList, int batchSize)
batchUpdate in interface CrudModelInfpublic int[] batchUpdate(Connection conn, Collection<? extends DBObject> modelList, int batchSize, boolean useNvl)
batchUpdate in interface CrudModelInfuseNvl - 是否使用数据库方法排除null值public int[] batchDelete(Connection conn, Collection<? extends DBObject> modelList, int batchSize)
batchDelete in interface CrudModelInfmodelList - the table namebatchSize - the primary key of the table, composite primary key is
separated by comma character: ","public int[] batchDelete(Connection conn, Collection<? extends DBObject> modelList, int batchSize, boolean useFirstSql)
batchDelete in interface CrudModelInfuseFirstSql - 是否使用第一个对象生成的sql语句为准public boolean createTable(Connection conn, Class<?> clz)
CrudModelInfcreateTable in interface CrudModelInfpublic boolean dropTable(Connection conn, Class<?> clz)
CrudModelInfdropTable in interface CrudModelInfpublic <T extends DBObject> List<T> fetchCascade(Connection conn, T query, Class<T> clz, DBCascadeField... fields)
CrudModelInffetchCascade in interface CrudModelInfpublic <T extends DBObject> T fetchLinks(Connection conn, T obj)
CrudModelInffetchLinks in interface CrudModelInfobj - 数据对象,不可以是Class啊!!!传对象或集合啊!!!OneToOne,
ManyToMany,
OneToManypublic <T extends DBObject> T fetchLinks(Connection conn, T obj, DBCascadeField... fields)
CrudModelInffetchLinks in interface CrudModelInfobj - 数据对象,不可以是Class啊!!!传对象或集合啊!!!OneToOne,
ManyToMany,
OneToManyprotected <T extends DBObject> T fetchLinks(Connection conn, T obj, String... fields)
public <T extends DBObject> T insertLinks(Connection con, T obj, DBCascadeField... fields)
CrudModelInfinsertLinks in interface CrudModelInfobj - 数据对象fields - 字段名称,描述了什么样的关联字段将被关注。如果为 null,则表示全部的关联字段都会被插入OneToOne,
ManyToMany,
OneToManypublic <T extends DBObject> T insertRelation(Connection con, T obj, DBCascadeField... fields)
CrudModelInfinsertRelation in interface CrudModelInfobj - 对象fields - 正则表达式,描述了那种多对多关联字段将被执行该操作ManyToManypublic <T extends DBObject> int updateLinks(Connection con, T obj, DBCascadeField... fields)
CrudModelInfupdateLinks in interface CrudModelInfcon - 连接obj - 数据对象fields - 字段名称,描述了什么样的关联字段将被关注。如果为 null,则表示全部的关联字段都会被更新OneToOne,
ManyToMany,
OneToManypublic <T extends DBObject> int updateRelation(Connection con, T obj, DBCascadeField... fields)
CrudModelInf而这个中间表可能还有其他的字段,比如描述关联的权重等
这个操作可以让你一次更新某一个对象中多个多对多关联的数据
updateRelation in interface CrudModelInfcon - 数据库连接obj - 数据对象fields - 字段名称,描述了那种多对多关联字段将被执行该操作ManyToManypublic <T extends DBObject> int deleteLinks(Connection con, T obj, DBCascadeField... fields)
CrudModelInfJava 对象的字段会被保留,这里的删除,将只会删除数据库中的记录
关于关联字段更多信息,请参看 '@One' | '@Many' | '@ManyMany' 更多的描述
deleteLinks in interface CrudModelInfT - con - obj - 数据对象fields - 正则表达式,描述了什么样的关联字段将被关注。如果为 null,则表示全部的关联字段都会被删除OneToOne,
ManyToOne,
ManyToManypublic <T extends DBObject> int deleteRelation(Connection con, T obj, DBCascadeField... fields)
deleteRelation in interface CrudModelInfT - con - obj - fields - 正则表达式,描述了那种多对多关联字段将被执行该操作ManyToManyCopyright © 2020. All rights reserved.