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[] |
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.
|
int |
delete(String sql) |
int |
delete(String sql,
Object... paras)
Execute delete sql statement.
|
boolean |
delete(String tableName,
Record record)
Example:
boolean succeed = Db.use().delete("user", user);
|
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,
String primaryKey,
Object... idValues)
Delete record by ids.
|
protected Page<Record> |
doPaginate(int pageNumber,
int pageSize,
Boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
protected Page<Record> |
doPaginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
Boolean isGroupBySql,
String select,
String sqlExceptSelect,
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 Object |
execute(Config config,
ICallback callback)
Execute callback.
|
Object |
execute(ICallback callback) |
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) |
List<Record> |
findAll(String tableName) |
List<Record> |
findByCache(String cacheName,
Object key,
String sql) |
List<Record> |
findByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find Record by cache.
|
Record |
findById(String tableName,
Object idValue)
Find record by id with default primary key.
|
Record |
findById(String tableName,
String primaryKey,
Object idValue) |
Record |
findByIds(String tableName,
String primaryKey,
Object... idValues)
Find record by ids.
|
Record |
findFirst(SqlPara sqlPara) |
Record |
findFirst(String sql) |
Record |
findFirst(String sql,
Object... paras)
Find first record.
|
Record |
findFirstByCache(String cacheName,
Object key,
String sql) |
Record |
findFirstByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find first record by cache.
|
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) |
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,
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.
|
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,
String select,
String sqlExceptSelect) |
Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras)
Paginate by cache.
|
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) |
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) |
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) |
<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) |
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) |
boolean |
save(String tableName,
Record record) |
boolean |
save(String tableName,
String primaryKey,
Record record)
Save record.
|
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)
Execute transaction with default transaction level.
|
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) |
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.
|
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) throws SQLException
SQLExceptionpublic <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 <T> T queryColumn(String sql)
public BigDecimal queryBigDecimal(String sql, Object... paras)
public BigDecimal queryBigDecimal(String sql)
public byte[] queryBytes(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> find(Config config, Connection conn, String sql, Object... paras) throws SQLException
SQLExceptionpublic List<Record> find(String sql)
sql - the sql statement#find(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 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 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 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 delete(String tableName, Record record)
Example:
boolean succeed = Db.use().delete("user", user);
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 Page<Record> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect)
#paginate(String, int, int, String, String, Object...)public Page<Record> paginate(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)
protected Page<Record> doPaginateByFullSql(Config config, 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)
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)
protected boolean save(Config config, Connection conn, String tableName, String primaryKey, Record record) throws SQLException
SQLExceptionpublic 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 savedtrue - if save succeed otherwise falseprotected boolean update(Config config, Connection conn, String tableName, String primaryKey, Record record) 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 objecttrue - if update succeed otherwise falsepublic 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)
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 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 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, String select, String sqlExceptSelect)
public Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
protected Page<Record> doPaginateByCache(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[] 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 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 © 2022. All rights reserved.