public class Db extends Object
| 构造器和说明 |
|---|
Db() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int[] |
batch(List<String> sqlList,
int batchSize) |
static int[] |
batch(String sql,
Object[][] paras,
int batchSize) |
static int[] |
batch(String sql,
String columns,
List modelOrRecordList,
int batchSize) |
static int[] |
batchSave(List<? extends Model> modelList,
int batchSize) |
static int[] |
batchSave(String tableName,
List<? extends Record> recordList,
int batchSize) |
static int[] |
batchUpdate(List<? extends Model> modelList,
int batchSize) |
static int[] |
batchUpdate(String tableName,
List<? extends Record> recordList,
int batchSize) |
static int[] |
batchUpdate(String tableName,
String primaryKey,
List<? extends Record> recordList,
int batchSize) |
static int |
delete(String sql) |
static int |
delete(String sql,
Object... paras)
Execute delete sql statement.
|
static boolean |
delete(String tableName,
Record record)
Example:
boolean succeed = Db.delete("user", user);
|
static boolean |
delete(String tableName,
String primaryKey,
Record record)
Delete record.
|
static boolean |
deleteById(String tableName,
Object idValue)
Delete record by id with default primary key.
|
static boolean |
deleteById(String tableName,
String primaryKey,
Object idValue) |
static boolean |
deleteByIds(String tableName,
String primaryKey,
Object... idValues)
Delete record by ids.
|
static Object |
execute(ICallback callback) |
static List<Record> |
find(SqlPara sqlPara) |
static List<Record> |
find(String sql) |
static List<Record> |
find(String sql,
Object... paras) |
static List<Record> |
findAll(String tableName) |
static List<Record> |
findByCache(String cacheName,
Object key,
String sql) |
static List<Record> |
findByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find Record by cache.
|
static Record |
findById(String tableName,
Object idValue)
Find record by id with default primary key.
|
static Record |
findById(String tableName,
String primaryKey,
Object idValue) |
static Record |
findByIds(String tableName,
String primaryKey,
Object... idValues)
Find record by ids.
|
static Record |
findFirst(SqlPara sqlPara) |
static Record |
findFirst(String sql) |
static Record |
findFirst(String sql,
Object... paras)
Find first record.
|
static Record |
findFirstByCache(String cacheName,
Object key,
String sql) |
static Record |
findFirstByCache(String cacheName,
Object key,
String sql,
Object... paras)
Find first record by cache.
|
static String |
getSql(String key) |
static SqlPara |
getSqlPara(String key,
Map data) |
static SqlPara |
getSqlPara(String key,
Model model) |
static SqlPara |
getSqlPara(String key,
Object... paras) |
static SqlPara |
getSqlPara(String key,
Record record) |
static SqlPara |
getSqlParaByString(String content,
Map data) |
static SqlPara |
getSqlParaByString(String content,
Object... paras) |
static Page<Record> |
paginate(int pageNumber,
int pageSize,
boolean isGroupBySql,
SqlPara sqlPara) |
static Page<Record> |
paginate(int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
static Page<Record> |
paginate(int pageNumber,
int pageSize,
SqlPara sqlPara) |
static Page<Record> |
paginate(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
static Page<Record> |
paginate(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras)
Paginate.
|
static Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
boolean isGroupBySql,
String select,
String sqlExceptSelect,
Object... paras) |
static Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
static Page<Record> |
paginateByCache(String cacheName,
Object key,
int pageNumber,
int pageSize,
String select,
String sqlExceptSelect,
Object... paras)
Paginate by cache.
|
static Page<Record> |
paginateByFullSql(int pageNumber,
int pageSize,
boolean isGroupBySql,
String totalRowSql,
String findSql,
Object... paras) |
static Page<Record> |
paginateByFullSql(int pageNumber,
int pageSize,
String totalRowSql,
String findSql,
Object... paras) |
static <T> List<T> |
query(String sql) |
static <T> List<T> |
query(String sql,
Object... paras) |
static BigDecimal |
queryBigDecimal(String sql) |
static BigDecimal |
queryBigDecimal(String sql,
Object... paras) |
static Boolean |
queryBoolean(String sql) |
static Boolean |
queryBoolean(String sql,
Object... paras) |
static Byte |
queryByte(String sql) |
static Byte |
queryByte(String sql,
Object... paras) |
static byte[] |
queryBytes(String sql) |
static byte[] |
queryBytes(String sql,
Object... paras) |
static <T> T |
queryColumn(String sql) |
static <T> T |
queryColumn(String sql,
Object... paras)
Execute sql query just return one column.
|
static Date |
queryDate(String sql) |
static Date |
queryDate(String sql,
Object... paras) |
static Double |
queryDouble(String sql) |
static Double |
queryDouble(String sql,
Object... paras) |
static <T> T |
queryFirst(String sql) |
static <T> T |
queryFirst(String sql,
Object... paras)
Execute sql query and return the first result.
|
static Float |
queryFloat(String sql) |
static Float |
queryFloat(String sql,
Object... paras) |
static Integer |
queryInt(String sql) |
static Integer |
queryInt(String sql,
Object... paras) |
static Long |
queryLong(String sql) |
static Long |
queryLong(String sql,
Object... paras) |
static Number |
queryNumber(String sql) |
static Number |
queryNumber(String sql,
Object... paras) |
static Short |
queryShort(String sql) |
static Short |
queryShort(String sql,
Object... paras) |
static String |
queryStr(String sql) |
static String |
queryStr(String sql,
Object... paras) |
static Time |
queryTime(String sql) |
static Time |
queryTime(String sql,
Object... paras) |
static Timestamp |
queryTimestamp(String sql) |
static Timestamp |
queryTimestamp(String sql,
Object... paras) |
static boolean |
save(String tableName,
Record record) |
static boolean |
save(String tableName,
String primaryKey,
Record record)
Save record.
|
static DbTemplate |
template(String key,
Map data)
使用 sql 模板进行查询,可以省去 Db.getSqlPara(...)
|
static DbTemplate |
template(String key,
Object... paras)
使用 sql 模板进行查询,可以省去 Db.getSqlPara(...)
|
static DbTemplate |
templateByString(String content,
Map data)
使用字符串变量作为 sql 模板进行查询,可省去外部 sql 文件来使用
sql 模板功能
例子:
String sql = "select * from blog where id = #para(id)";
Db.templateByString(sql, Kv.by("id", 123).find();
|
static DbTemplate |
templateByString(String content,
Object... paras)
使用字符串变量作为 sql 模板进行查询,可省去外部 sql 文件来使用
sql 模板功能
例子:
String sql = "select * from blog where id = #para(0)";
Db.templateByString(sql, 123).find();
|
static boolean |
tx(IAtom atom)
Execute transaction with default transaction level.
|
static boolean |
tx(int transactionLevel,
IAtom atom) |
static Future<Boolean> |
txInNewThread(IAtom atom)
Execute transaction with default transaction level.
|
static Future<Boolean> |
txInNewThread(int transactionLevel,
IAtom atom) |
static int |
update(SqlPara sqlPara) |
static int |
update(String sql) |
static int |
update(String sql,
Object... paras)
Execute update, insert or delete sql statement.
|
static boolean |
update(String tableName,
Record record)
Update record with default primary key.
|
static boolean |
update(String tableName,
String primaryKey,
Record record)
Update Record.
|
static DbPro |
use() |
static DbPro |
use(String configName) |
public static DbPro use()
public static <T> List<T> query(String sql, Object... paras)
#query(String, String, Object...)public static <T> List<T> query(String sql)
sql - an SQL statementquery(String, Object...)public static <T> T queryFirst(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter placeholdersparas - the parameters of sqlpublic static <T> T queryFirst(String sql)
sql - an SQL statementqueryFirst(String, Object...)public static <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 static <T> T queryColumn(String sql)
public static BigDecimal queryBigDecimal(String sql, Object... paras)
public static BigDecimal queryBigDecimal(String sql)
public static byte[] queryBytes(String sql)
public static 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 static int update(String sql)
sql - an SQL statementupdate(String, Object...)public static List<Record> find(String sql, Object... paras)
#find(String, String, Object...)public static List<Record> find(String sql)
sql - the sql statement#find(String, String, Object...)public static Record findFirst(String sql, Object... paras)
sql - an SQL statement that may contain one or more '?' IN parameter placeholdersparas - the parameters of sqlpublic static Record findFirst(String sql)
sql - an SQL statementfindFirst(String, Object...)public static Record findById(String tableName, Object idValue)
Example:
Record user = Db.findById("user", 15);
tableName - the table name of the tableidValue - the id value of the recordpublic static Record findByIds(String tableName, String primaryKey, Object... idValues)
Example:
Record user = Db.findByIds("user", "user_id", 123);
Record userRole = Db.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 static boolean deleteById(String tableName, Object idValue)
Example:
Db.deleteById("user", 15);
tableName - the table name of the tableidValue - the id value of the recordpublic static boolean deleteByIds(String tableName, String primaryKey, Object... idValues)
Example:
Db.deleteByIds("user", "user_id", 15);
Db.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 static boolean delete(String tableName, String primaryKey, Record record)
Example:
boolean succeed = Db.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 static boolean delete(String tableName, Record record)
Example:
boolean succeed = Db.delete("user", user);
public static 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 static int delete(String sql)
sql - an SQL statementdelete(String, Object...)public static 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 static Page<Record> paginate(int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
public static Page<Record> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect)
#paginate(String, int, int, String, String, Object...)public static Page<Record> paginateByFullSql(int pageNumber, int pageSize, String totalRowSql, String findSql, Object... paras)
public static Page<Record> paginateByFullSql(int pageNumber, int pageSize, boolean isGroupBySql, String totalRowSql, String findSql, Object... paras)
public static boolean save(String tableName, String primaryKey, Record record)
Example:
Record userRole = new Record().set("user_id", 123).set("role_id", 456);
Db.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 falsepublic static boolean update(String tableName, String primaryKey, Record record)
Example:
Db.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 static boolean update(String tableName, Record record)
Example:
Db.update("user", record);
public static boolean tx(IAtom atom)
tx(int, IAtom)public static boolean tx(int transactionLevel,
IAtom atom)
public static Future<Boolean> txInNewThread(IAtom atom)
public static 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 static 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 static Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras)
paginate(int, int, String, String, Object...)public static Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, boolean isGroupBySql, String select, String sqlExceptSelect, Object... paras)
public static Page<Record> paginateByCache(String cacheName, Object key, int pageNumber, int pageSize, String select, String sqlExceptSelect)
public static int[] batch(List<String> sqlList, int batchSize)
DbPro.batch(List, int)public static int[] batchSave(String tableName, List<? extends Record> recordList, int batchSize)
public static int[] batchUpdate(String tableName, String primaryKey, List<? extends Record> recordList, int batchSize)
public static int[] batchUpdate(String tableName, List<? extends Record> recordList, int batchSize)
public static int update(SqlPara sqlPara)
public static Page<Record> paginate(int pageNumber, int pageSize, boolean isGroupBySql, SqlPara sqlPara)
public static DbTemplate template(String key, Map data)
例子:
Db.template("blog.find", Kv.by("id", 123).find();
public static DbTemplate template(String key, Object... paras)
例子:
Db.template("blog.find", 123).find();
public static DbTemplate templateByString(String content, Map data)
例子:
String sql = "select * from blog where id = #para(id)";
Db.templateByString(sql, Kv.by("id", 123).find();
public static DbTemplate templateByString(String content, Object... paras)
例子: String sql = "select * from blog where id = #para(0)"; Db.templateByString(sql, 123).find();
Copyright © 2022. All rights reserved.