public class DbPro extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
protected int[] |
batch(Config config,
Connection conn,
List<String> sqlList,
int batchSize) |
protected int[] |
batch(Config config,
Connection conn,
String sql,
Object[][] paras,
int batchSize) |
protected int[] |
batch(Config config,
Connection conn,
String sql,
String columns,
List list,
int batchSize) |
int[] |
batch(List<String> sqlList,
int batchSize)
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
|
int[] |
batch(String sql,
Object[][] paras,
int batchSize)
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
|
int[] |
batch(String sql,
String columns,
List modelOrRecordList,
int batchSize)
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
|
int[] |
batchDelete(String tableName,
List<? extends Record> recordList,
int batchSize) |
int[] |
batchSave(List<? extends Model> modelList,
int batchSize)
Batch save models using the "insert into ..." sql generated by the first
model in modelList.
|
int[] |
batchSave(String tableName,
List<? extends Record> recordList,
int batchSize)
Batch save records using the "insert into ..." sql generated by the first
record in recordList.
|
int[] |
batchUpdate(List<? extends Model> modelList,
int batchSize)
Batch update models using the attrs names of the first model in modelList.
|
int[] |
batchUpdate(String tableName,
List<? extends Record> recordList,
int batchSize)
Batch update records with default primary key, using the columns names of the
first record in recordList.
|
int[] |
batchUpdate(String tableName,
String primaryKey,
List<? extends Record> recordList,
int batchSize)
Batch update records using the columns names of the first record in
recordList.
|
Long |
count(String sql) |
Long |
countTable(String table) |
int |
delete(String sql) |
int |
delete(String sql,
Object... paras)
Execute delete sql statement.
|
boolean |
delete(String tableName,
Record record)
Example:
String noteId="0000000";
Record removeRecordFilter = new Record();
removeRecordFilter.set("note_id", noteId);
Db.delete(ENoteTableNames.ENOTE_NOTE_TAG, removeRecordFilter);
|
boolean |
delete(String tableName,
String primaryKey,
Record record)
Delete record.
|
boolean |
deleteById(String tableName,
Object idValue)
Delete record by id with default primary key.
|
boolean |
deleteById(String tableName,
String primaryKey,
Object idValue) |
boolean |
deleteByIds(String tableName,
Record record)
Example:
boolean succeed = Db.use().delete("user", user);
|
boolean |
deleteByIds(String tableName,
String primaryKey,
Object... idValues)
Delete record by ids.
|
<T> Page<T> |
doPaginate(Class<T> clazz,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
protected Page<Record> |
doPaginate(int pageNumber,
int pageSize,
Boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
<T> Page<T> |
doPaginateByCache(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
Page<Record> |
doPaginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
<T> Page<T> |
doPaginateByFullSql(Class<T> clazz,
Config config2,
Connection conn,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String totalRowSql,
StringBuilder findSql,
Object[] paras) |
protected <T> Page<T> |
doPaginateByFullSql(Class<T> clazz,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String totalRowSql,
String findSql,
Object... paras) |
protected Page<Record> |
doPaginateByFullSql(Config config,
Connection conn,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String totalRowSql,
StringBuilder findSql,
Object... paras) |
protected Page<Record> |
doPaginateByFullSql(int pageNumber,
int pageSize,
Boolean isGroupBySql,
String totalRowSql,
String findSql,
Object... paras) |
protected Page<Record> |
doPaginateByFullSqlWithJsonFields(Config config,
Connection conn,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String totalRowSql,
StringBuilder findSql,
String[] jsonFields,
Object... paras) |
protected Page<Record> |
doPaginateJsonFields(int pageNumber,
int pageSize,
Boolean isGroupBySql,
String select,
String sqlExceptSelect,
String[] jsonFields,
Object... paras) |
void |
each(java.util.function.Function<Record,Boolean> func,
String sql,
Object... paras)
迭代处理每一个查询出来的 Record 对象
例子:
Db.each(record -> {
// 处理 record 的代码在此
// 返回 true 继续循环处理下一条数据,返回 false 立即终止循环
return true;
}, sql, paras);
|
protected Object |
execute(Config config,
ICallback callback)
Execute callback.
|
Object |
execute(ICallback callback) |
boolean |
exists(String sql,
Object[] paras) |
boolean |
exists(String tableName,
String fields,
Object... paras) |
protected <T> List<T> |
find(Class<T> clazz,
Config config,
Connection conn,
String sql,
Object... paras) |
<T> List<T> |
find(Class<T> clazz,
SqlPara sqlPara) |
<T> List<T> |
find(Class<T> clazz,
String sql,
Object... paras) |
protected List<Record> |
find(Config config,
Connection conn,
String sql,
Object... paras) |
List<Record> |
find(SqlPara sqlPara) |
List<Record> |
find(String sql) |
List<Record> |
find(String sql,
Object... paras) |
<T> List<T> |
findAll(Class<T> clazz,
String tableName) |
List<Record> |
findAll(String tableName) |
<T> List<T> |
findByCache(Class<T> clazz,
String cacheName,
Object key,
String sql) |
<T> List<T> |
findByCache(Class<T> clazz,
String cacheName,
Object key,
String sql,
Object... paras) |
List<Record> |
findByCache(String cacheName,
Object key,
String sql) |
List<Record> |
findByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find Record by cache.
|
List<Record> |
findByColumn(String tableName,
String column,
String value) |
<T> T |
findById(Class<T> clazz,
String tableName,
Object idValue) |
<T> T |
findById(Class<T> clazz,
String tableName,
String primaryKey,
Object idValue) |
Record |
findById(String tableName,
Object idValue)
Find record by id with default primary key.
|
Record |
findById(String tableName,
String primaryKey,
Object idValue) |
<T> T |
findByIds(Class<T> clazz,
String tableName,
String primaryKey,
Object... idValues) |
Record |
findByIds(String tableName,
String primaryKey,
Object... idValues)
Find record by ids.
|
List<Record> |
findColumns(String tableName,
String columns,
String primaryKey,
Object... idValues) |
<T> List<T> |
findColumnsAll(Class<T> clazz,
String tableName,
String columns) |
List<Record> |
findColumnsAll(String tableName,
String columns) |
<T> T |
findColumnsById(Class<T> clazz,
String tableName,
String columns,
Object idValue) |
<T> T |
findColumnsById(Class<T> clazz,
String tableName,
String columns,
String primaryKey,
Object... idValues) |
Record |
findColumnsById(String tableName,
String columns,
Object idValue) |
Record |
findColumnsById(String tableName,
String columns,
String primaryKey,
Object... idValues) |
<T> T |
findColumnsByIds(Class<T> clazz,
String tableName,
String columns,
String primaryKey,
Object... idValues) |
Record |
findColumnsByIds(String tableName,
String columns,
String primaryKey,
Object... idValues) |
<T> T |
findFirst(Class<T> clazz,
SqlPara sqlPara) |
<T> T |
findFirst(Class<T> clazz,
String sql,
Object... paras) |
Record |
findFirst(SqlPara sqlPara) |
Record |
findFirst(String sql) |
Record |
findFirst(String sql,
Object... paras)
Find first record.
|
<T> T |
findFirstByCache(Class<T> clazz,
String cacheName,
Object key,
String sql) |
<T> T |
findFirstByCache(Class<T> clazz,
String cacheName,
Object key,
String sql,
Object... paras) |
Record |
findFirstByCache(String cacheName,
Object key,
String sql) |
Record |
findFirstByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find first record by cache.
|
Record |
findFirstJsonField(String sql,
String[] jsonFields,
Object... paras) |
protected List<Record> |
findJsonField(Config config,
Connection conn,
String sql,
String[] jsonFields,
Object... paras) |
List<Record> |
findJsonField(String sql,
String[] jsonFields,
Object... paras) |
List<Record> |
findWithJsonField(String sql,
String[] jsonFields,
Object... paras) |
List<Record> |
findWithJsonFields(String sql,
String[] jsonFields) |
List<Record> |
findWithPrimaryKey(String tableName,
String primaryKey,
Object... idValues) |
Config |
getConfig() |
String |
getSql(String key) |
SqlPara |
getSqlPara(String key,
Map data) |
SqlPara |
getSqlPara(String key,
Model model) |
SqlPara |
getSqlPara(String key,
Object... paras) |
SqlPara |
getSqlPara(String key,
Record record) |
SqlPara |
getSqlParaByString(String content,
Map data) |
SqlPara |
getSqlParaByString(String content,
Object... paras) |
<T> Page<T> |
paginate(Class<T> clazz,
int pageNumber,
int pageSize,
boolean isGroupBySql,
SqlPara sqlPara) |
<T> Page<T> |
paginate(Class<T> clazz,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect) |
<T> Page<T> |
paginate(Class<T> clazz,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object[] paras) |
<T> Page<T> |
paginate(Class<T> clazz,
int pageNumber,
int pageSize,
SqlPara sqlPara) |
<T> Page<T> |
paginate(Class<T> clazz,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
<T> Page<T> |
paginate(Class<T> clazz,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object[] paras) |
protected Page<Record> |
paginate(Config config,
Connection conn,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras) |
Page<Record> |
paginate(int pageNumber,
int pageSize,
boolean isGroupBySql,
SqlPara sqlPara) |
Page<Record> |
paginate(int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect) |
Page<Record> |
paginate(int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
Page<Record> |
paginate(int pageNumber,
int pageSize,
SqlPara sqlPara) |
Page<Record> |
paginate(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
Page<Record> |
paginate(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras)
Paginate.
|
<T> Page<T> |
paginateByCache(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
SqlPara sqlPara) |
<T> Page<T> |
paginateByCache(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect) |
<T> Page<T> |
paginateByCache(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
<T> Page<T> |
paginateByCache(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
SqlPara sqlPara) |
<T> Page<T> |
paginateByCache(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
<T> Page<T> |
paginateByCache(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras) |
Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
SqlPara sqlPara) |
Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect) |
Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
SqlPara sqlPara) |
Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras)
Paginate by cache.
|
<T> Page<T> |
paginateByCacheByFullSql(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String totalRowSql,
String findSql,
Object... paras) |
<T> Page<T> |
paginateByCacheByFullSql(Class<T> clazz,
String cacheName,
Object key,
int pageNumber,
int pageSize,
String totalRowSql,
String findSql,
Object... paras) |
Page<Record> |
paginateByCacheByFullSql(String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String totalRowSql,
String findSql,
Object... paras) |
Page<Record> |
paginateByCacheByFullSql(String cacheName,
Object key,
int pageNumber,
int pageSize,
String totalRowSql,
String findSql,
Object... paras) |
<T> Page<T> |
paginateByFullSql(Class<T> clazz,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String totalRowSql,
String findSql,
Object... paras) |
<T> Page<T> |
paginateByFullSql(Class<T> clazz,
int pageNumber,
int pageSize,
String totalRowSql,
String findSql,
Object... paras) |
Page<Record> |
paginateByFullSql(int pageNumber,
int pageSize,
boolean isGroupBySql,
String totalRowSql,
String findSql,
Object... paras) |
Page<Record> |
paginateByFullSql(int pageNumber,
int pageSize,
String totalRowSql,
String findSql,
Object... paras) |
Page<Record> |
paginateJsonFields(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
String[] jsonFields) |
Page<Record> |
paginateJsonFields(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
String[] jsonFields,
Object... paras) |
protected <T> List<T> |
query(Config config,
Connection conn,
String sql,
Object... paras) |
<T> List<T> |
query(String sql) |
<T> List<T> |
query(String sql,
Object... paras) |
BigDecimal |
queryBigDecimal(String sql) |
BigDecimal |
queryBigDecimal(String sql,
Object... paras) |
BigInteger |
queryBigInteger(String sql) |
BigInteger |
queryBigInteger(String sql,
Object... paras) |
Boolean |
queryBoolean(String sql) |
Boolean |
queryBoolean(String sql,
Object... paras) |
Byte |
queryByte(String sql) |
Byte |
queryByte(String sql,
Object... paras) |
byte[] |
queryBytes(String sql) |
byte[] |
queryBytes(String sql,
Object... paras) |
<T> T |
queryColumn(String sql,
Object... paras)
Execute sql query just return one column.
|
Date |
queryDate(String sql) |
Date |
queryDate(String sql,
Object... paras) |
Double |
queryDouble(String sql) |
Double |
queryDouble(String sql,
Object... paras) |
<T> T |
queryFirst(String sql) |
<T> T |
queryFirst(String sql,
Object... paras)
Execute sql query and return the first result.
|
Float |
queryFloat(String sql) |
Float |
queryFloat(String sql,
Object... paras) |
Integer |
queryInt(String sql) |
Integer |
queryInt(String sql,
Object... paras) |
java.time.LocalDateTime |
queryLocalDateTime(String sql) |
java.time.LocalDateTime |
queryLocalDateTime(String sql,
Object... paras) |
Long |
queryLong(String sql) |
Long |
queryLong(String sql,
Object... paras) |
Number |
queryNumber(String sql) |
Number |
queryNumber(String sql,
Object... paras) |
Short |
queryShort(String sql) |
Short |
queryShort(String sql,
Object... paras) |
String |
queryStr(String sql) |
String |
queryStr(String sql,
Object... paras) |
Time |
queryTime(String sql) |
Time |
queryTime(String sql,
Object... paras) |
Timestamp |
queryTimestamp(String sql) |
Timestamp |
queryTimestamp(String sql,
Object... paras) |
protected boolean |
save(Config config,
Connection conn,
String tableName,
String primaryKey,
Record record) |
protected boolean |
save(Config config,
Connection conn,
String tableName,
String primaryKey,
Record record,
String[] jsonFields) |
boolean |
save(String tableName,
Record record) |
boolean |
save(String tableName,
Record record,
String[] jsonFields) |
boolean |
save(String tableName,
String primaryKey,
Record record)
Save record.
|
boolean |
save(String tableName,
String primaryKey,
Record record,
String[] jsonFields) |
DbTemplate |
template(String key,
Map data) |
DbTemplate |
template(String key,
Object... paras) |
DbTemplate |
templateByString(String content,
Map data) |
DbTemplate |
templateByString(String content,
Object... paras) |
protected boolean |
tx(Config config,
int transactionLevel,
IAtom atom)
Execute transaction.
|
boolean |
tx(IAtom atom)
Execute transaction with default transaction level.
|
boolean |
tx(int transactionLevel,
IAtom atom) |
Future<Boolean> |
txInNewThread(IAtom atom)
主要用于嵌套事务场景
实例:https://jfinal.com/feedback/4008
默认情况下嵌套事务会被合并成为一个事务,那么内层与外层任何地方回滚事务 所有嵌套层都将回滚事务,也就是说嵌套事务无法独立提交与回滚
使用 txInNewThread(...)
|
Future<Boolean> |
txInNewThread(int transactionLevel,
IAtom atom) |
protected int |
update(Config config,
Connection conn,
String sql,
Object... paras)
Execute sql update
|
protected boolean |
update(Config config,
Connection conn,
String tableName,
String primaryKey,
Record record) |
protected boolean |
update(Config config,
Connection conn,
String tableName,
String primaryKey,
Record record,
String[] jsonFields) |
int |
update(SqlPara sqlPara) |
int |
update(String sql) |
int |
update(String sql,
Object... paras)
Execute update, insert or delete sql statement.
|
boolean |
update(String tableName,
Record record)
Update record with default primary key.
|
boolean |
update(String tableName,
String primaryKey,
Record record)
Update Record.
|
boolean |
update(String tableName,
String primaryKey,
Record record,
String[] jsonFields) |
protected final Config config
public DbPro()
public DbPro(String configName)
public Config getConfig()
protected <T> List<T> query(Config config, Connection conn, String sql, Object... paras)
public <T> List<T> query(String sql)
sql - an SQL statementquery(String, Object...)public <T> T queryFirst(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter
placeholdersparas - the parameters of sqlpublic <T> T queryFirst(String sql)
sql - an SQL statementqueryFirst(String, Object...)public <T> T queryColumn(String sql, Object... paras)
T - the type of the column that in your sql's select statementsql - an SQL statement that may contain one or more '?' IN parameter
placeholdersparas - the parameters of sqlpublic BigDecimal queryBigDecimal(String sql, Object... paras)
public BigDecimal queryBigDecimal(String sql)
public BigInteger queryBigInteger(String sql, Object... paras)
public BigInteger queryBigInteger(String sql)
public byte[] queryBytes(String sql)
public java.time.LocalDateTime queryLocalDateTime(String sql)
protected int update(Config config, Connection conn, String sql, Object... paras) throws SQLException
SQLExceptionpublic int update(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter
placeholdersparas - the parameters of sqlINSERT, UPDATE, or
DELETE statements, or 0 for SQL statements that return
nothingpublic int update(String sql)
sql - an SQL statementupdate(String, Object...)protected List<Record> findJsonField(Config config, Connection conn, String sql, String[] jsonFields, Object... paras) throws SQLException
SQLExceptionprotected List<Record> find(Config config, Connection conn, String sql, Object... paras) throws SQLException
SQLExceptionprotected <T> List<T> find(Class<T> clazz, Config config, Connection conn, String sql, Object... paras)
public List<Record> findWithJsonField(String sql, String[] jsonFields, Object... paras)
public List<Record> find(String sql)
sql - the sql statementfindWithPrimaryKey(String, String, Object...)public Record findFirst(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter
placeholdersparas - the parameters of sqlpublic Record findFirstJsonField(String sql, String[] jsonFields, Object... paras)
public Record findFirst(String sql)
sql - an SQL statementfindFirst(String, Object...)public Record findById(String tableName, Object idValue)
Example:
Record user = Db.use().findById("user", 15);
tableName - the table name of the tableidValue - the id value of the recordpublic <T> T findColumnsById(Class<T> clazz, String tableName, String columns, Object idValue)
public Record findByIds(String tableName, String primaryKey, Object... idValues)
Example:
Record user = Db.use().findByIds("user", "user_id", 123);
Record userRole = Db.use().findByIds("user_role", "user_id, role_id", 123, 456);
tableName - the table name of the tableprimaryKey - the primary key of the table, composite primary key is
separated by comma character: ","idValues - the id value of the record, it can be composite id valuespublic <T> T findByIds(Class<T> clazz, String tableName, String primaryKey, Object... idValues)
public Record findColumnsByIds(String tableName, String columns, String primaryKey, Object... idValues)
public <T> T findColumnsByIds(Class<T> clazz, String tableName, String columns, String primaryKey, Object... idValues)
public List<Record> findWithPrimaryKey(String tableName, String primaryKey, Object... idValues)
public Record findColumnsById(String tableName, String columns, String primaryKey, Object... idValues)
public <T> T findColumnsById(Class<T> clazz, String tableName, String columns, String primaryKey, Object... idValues)
public List<Record> findColumns(String tableName, String columns, String primaryKey, Object... idValues)
public boolean deleteById(String tableName, Object idValue)
Example: Db.use().deleteById("user", 15);
tableName - the table name of the tableidValue - the id value of the recordpublic boolean deleteByIds(String tableName, String primaryKey, Object... idValues)
Example: Db.use().deleteByIds("user", "user_id", 15);
Db.use().deleteByIds("user_role", "user_id, role_id", 123, 456);
tableName - the table name of the tableprimaryKey - the primary key of the table, composite primary key is
separated by comma character: ","idValues - the id value of the record, it can be composite id valuespublic boolean delete(String tableName, String primaryKey, Record record)
Example:
boolean succeed = Db.use().delete("user", "id", user);
tableName - the table name of the tableprimaryKey - the primary key of the table, composite primary key is
separated by comma character: ","record - the recordpublic boolean deleteByIds(String tableName, Record record)
Example:
boolean succeed = Db.use().delete("user", user);
public boolean delete(String tableName, Record record)
Example:
String noteId="0000000";
Record removeRecordFilter = new Record();
removeRecordFilter.set("note_id", noteId);
Db.delete(ENoteTableNames.ENOTE_NOTE_TAG, removeRecordFilter);
public int delete(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter
placeholdersparas - the parameters of sqlDELETE statements, or 0 for SQL
statements that return nothingpublic int delete(String sql)
sql - an SQL statementdelete(String, Object...)public Page<Record> 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 <T> Page<T> paginate(Class<T> clazz, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object[] paras)
public Page<Record> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect)
public Page<Record> paginateJsonFields(int pageNumber, int pageSize, String select, String sqlExceptSelect, String[] jsonFields, Object... paras)
public Page<Record> paginateJsonFields(int pageNumber, int pageSize, String select, String sqlExceptSelect, String[] jsonFields)
public Page<Record> paginate(int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect)
public <T> Page<T> paginate(Class<T> clazz, int pageNumber, int pageSize, String select, String sqlExceptSelect)
public <T> Page<T> paginate(Class<T> clazz, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect)
public Page<Record> paginate(int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
public <T> Page<T> paginate(Class<T> clazz, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object[] paras)
protected Page<Record> doPaginateJsonFields(int pageNumber, int pageSize, Boolean isGroupBySql, String select, String sqlExceptSelect, String[] jsonFields, Object... paras)
protected Page<Record> doPaginate(int pageNumber, int pageSize, Boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
public <T> Page<T> doPaginate(Class<T> clazz, int pageNumber, int pageSize, Boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
protected Page<Record> doPaginateByFullSqlWithJsonFields(Config config, Connection conn, int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, StringBuilder findSql, String[] jsonFields, Object... paras)
protected Page<Record> doPaginateByFullSql(Config config, Connection conn, int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, StringBuilder findSql, Object... paras) throws SQLException
SQLExceptionpublic <T> Page<T> doPaginateByFullSql(Class<T> clazz, Config config2, Connection conn, int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, StringBuilder findSql, Object[] paras) throws SQLException
SQLExceptionprotected Page<Record> paginate(Config config, Connection conn, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras) throws SQLException
SQLExceptionprotected Page<Record> doPaginateByFullSql(int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, String findSql, Object... paras)
protected <T> Page<T> doPaginateByFullSql(Class<T> clazz, int pageNumber, int pageSize, Boolean isGroupBySql, String totalRowSql, String findSql, Object... paras)
public Page<Record> paginateByFullSql(int pageNumber, int pageSize, String totalRowSql, String findSql, Object... paras)
public Page<Record> paginateByFullSql(int pageNumber, int pageSize, boolean isGroupBySql, String totalRowSql, String findSql, Object... paras)
public <T> Page<T> paginateByFullSql(Class<T> clazz, int pageNumber, int pageSize, String totalRowSql, String findSql, Object... paras)
public <T> Page<T> paginateByFullSql(Class<T> clazz, int pageNumber, int pageSize, boolean isGroupBySql, String totalRowSql, String findSql, Object... paras)
protected boolean save(Config config, Connection conn, String tableName, String primaryKey, Record record)
protected boolean save(Config config, Connection conn, String tableName, String primaryKey, Record record, String[] jsonFields)
public boolean save(String tableName, String primaryKey, Record record)
Example:
Record userRole = new Record().set("user_id", 123).set("role_id", 456);
Db.use().save("user_role", "user_id, role_id", userRole);
tableName - the table name of the tableprimaryKey - the primary key of the table, composite primary key is
separated by comma character: ","record - the record will be savedpublic boolean save(String tableName, Record record, String[] jsonFields)
tableName - record - jsonFields - protected boolean update(Config config, Connection conn, String tableName, String primaryKey, Record record) throws SQLException
SQLExceptionprotected boolean update(Config config, Connection conn, String tableName, String primaryKey, Record record, String[] jsonFields) throws SQLException
SQLExceptionpublic boolean update(String tableName, String primaryKey, Record record)
Example: Db.use().update("user_role", "user_id, role_id", record);
tableName - the table name of the Record save toprimaryKey - the primary key of the table, composite primary key is
separated by comma character: ","record - the Record objectpublic boolean update(String tableName, String primaryKey, Record record, String[] jsonFields)
public boolean update(String tableName, Record record)
Example: Db.use().update("user", record);
protected Object execute(Config config, ICallback callback)
config - the Config objectcallback - the ICallback interfaceprotected boolean tx(Config config, int transactionLevel, IAtom atom)
config - the Config objecttransactionLevel - the transaction levelatom - the atom operationpublic boolean tx(IAtom atom)
tx(int, IAtom)public boolean tx(int transactionLevel,
IAtom atom)
public Future<Boolean> txInNewThread(IAtom atom)
实例:https://jfinal.com/feedback/4008
默认情况下嵌套事务会被合并成为一个事务,那么内层与外层任何地方回滚事务 所有嵌套层都将回滚事务,也就是说嵌套事务无法独立提交与回滚
使用 txInNewThread(...) 方法可以实现层之间的事务控制的独立性 由于事务处理是将 Connection 绑定到线程上的,所以 txInNewThread(...) 通过建立新线程来实现嵌套事务的独立控制
public List<Record> findByCache(String cacheName, Object key, String sql, Object... paras)
cacheName - the cache namekey - the key used to get date from cachefind(String, Object...)public <T> List<T> findByCache(Class<T> clazz, String cacheName, Object key, String sql, Object... paras)
public <T> List<T> findByCache(Class<T> clazz, String cacheName, Object key, String sql)
public Record findFirstByCache(String cacheName, Object key, String sql, Object... paras)
cacheName - the cache namekey - the key used to get date from cachesql - an SQL statement that may contain one or more '?' IN
parameter placeholdersparas - the parameters of sqlfindFirst(String, Object...)public <T> T findFirstByCache(Class<T> clazz, String cacheName, Object key, String sql, Object... paras)
public <T> T findFirstByCache(Class<T> clazz, String cacheName, Object key, String sql)
public <T> Page<T> doPaginateByCache(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, Boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
public Page<Record> doPaginateByCache(String cacheName, Object key, int pageNumber, int pageSize, Boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
public Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, SqlPara sqlPara)
public Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, SqlPara sqlPara)
public Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect)
public Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect)
public Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras)
paginate(int, int, String, String, Object...)public Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
public Page<Record> paginateByCacheByFullSql(String cacheName, Object key, int pageNumber, int pageSize, String totalRowSql, String findSql, Object... paras)
public Page<Record> paginateByCacheByFullSql(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String totalRowSql, String findSql, Object... paras)
public <T> Page<T> paginateByCacheByFullSql(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, String totalRowSql, String findSql, Object... paras)
public <T> Page<T> paginateByCacheByFullSql(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String totalRowSql, String findSql, Object... paras)
public <T> Page<T> paginateByCache(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, SqlPara sqlPara)
public <T> Page<T> paginateByCache(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, SqlPara sqlPara)
public <T> Page<T> paginateByCache(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect)
public <T> Page<T> paginateByCache(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect)
public <T> Page<T> paginateByCache(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras)
public <T> Page<T> paginateByCache(Class<T> clazz, String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
protected int[] batch(Config config, Connection conn, String sql, Object[][] paras, int batchSize) throws SQLException
SQLExceptionpublic int[] batch(String sql, Object[][] paras, int batchSize)
Example:
String sql = "insert into user(name, cash) values(?, ?)";
int[] result = Db.use().batch(sql, new Object[][]{{"James", 888}, {"zhanjin", 888}});
sql - The SQL to execute.paras - An array of query replacement parameters. Each row in this array
is one set of batch replacement values.protected int[] batch(Config config, Connection conn, String sql, String columns, List list, int batchSize) throws SQLException
SQLExceptionpublic int[] batch(String sql, String columns, List modelOrRecordList, int batchSize)
Example: String sql = "insert into user(name, cash) values(?, ?)"; int[] result = Db.use().batch(sql, "name, cash", modelList, 500);
sql - The SQL to execute.columns - the columns need be processed by sql.modelOrRecordList - model or record object list.batchSize - batch size.protected int[] batch(Config config, Connection conn, List<String> sqlList, int batchSize) throws SQLException
SQLExceptionpublic int[] batch(List<String> sqlList, int batchSize)
Example: int[] result = Db.use().batch(sqlList, 500);
sqlList - The SQL list to execute.batchSize - batch size.public int[] batchSave(List<? extends Model> modelList, int batchSize)
public int[] batchSave(String tableName, List<? extends Record> recordList, int batchSize)
tableName - the table namepublic int[] batchDelete(String tableName, List<? extends Record> recordList, int batchSize)
public int[] batchUpdate(List<? extends Model> modelList, int batchSize)
public int[] batchUpdate(String tableName, String primaryKey, List<? extends Record> recordList, int batchSize)
tableName - the table nameprimaryKey - the primary key of the table, composite primary key is
separated by comma character: ","public int[] batchUpdate(String tableName, List<? extends Record> recordList, int batchSize)
tableName - the table namepublic int update(SqlPara sqlPara)
public Page<Record> paginate(int pageNumber, int pageSize, boolean isGroupBySql, SqlPara sqlPara)
public <T> Page<T> paginate(Class<T> clazz, int pageNumber, int pageSize, boolean isGroupBySql, SqlPara sqlPara)
public void each(java.util.function.Function<Record,Boolean> func, String sql, Object... paras)
例子:
Db.each(record -> {
// 处理 record 的代码在此
// 返回 true 继续循环处理下一条数据,返回 false 立即终止循环
return true;
}, sql, paras);
public DbTemplate template(String key, Map data)
public DbTemplate template(String key, Object... paras)
public DbTemplate templateByString(String content, Map data)
public DbTemplate templateByString(String content, Object... paras)
Copyright © 2024. All rights reserved.