public class Db extends Object
Constructor and Description |
---|
Db() |
Modifier and Type | Method and Description |
---|---|
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<Record> recordList,
int batchSize) |
static int[] |
batchUpdate(List<? extends Model> modelList,
int batchSize) |
static int[] |
batchUpdate(String tableName,
List<Record> recordList,
int batchSize) |
static int[] |
batchUpdate(String tableName,
String primaryKey,
List<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)
Delete record by id.
|
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> |
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)
Find record by id.
|
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 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 boolean |
tx(IAtom atom)
Execute transaction with default transaction level.
|
static boolean |
tx(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 findById(String tableName, String primaryKey, Object... idValue)
Example: Record user = Db.findById("user", "user_id", 123); Record userRole = Db.findById("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: ","idValue
- 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 deleteById(String tableName, String primaryKey, Object... idValue)
Example: Db.deleteById("user", "user_id", 15); Db.deleteById("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: ","idValue
- 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);
delete(String, String, Record)
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 save(String tableName, Record record)
save(String, String, Record)
public 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);
update(String, String, Record)
public static boolean tx(int transactionLevel, IAtom atom)
public static boolean tx(IAtom atom)
tx(int, IAtom)
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(String sql, Object[][] paras, int batchSize)
DbPro.batch(String, Object[][], int)
public static int[] batch(String sql, String columns, List modelOrRecordList, int batchSize)
DbPro.batch(String, String, List, int)
public static int[] batch(List<String> sqlList, int batchSize)
DbPro.batch(List, int)
public static int[] batchSave(List<? extends Model> modelList, int batchSize)
DbPro.batchSave(List, int)
public static int[] batchSave(String tableName, List<Record> recordList, int batchSize)
DbPro.batchSave(String, List, int)
public static int[] batchUpdate(List<? extends Model> modelList, int batchSize)
DbPro.batchUpdate(List, int)
public static int[] batchUpdate(String tableName, String primaryKey, List<Record> recordList, int batchSize)
public static int[] batchUpdate(String tableName, List<Record> recordList, int batchSize)
DbPro.batchUpdate(String, List, int)
public static int update(SqlPara sqlPara)
Copyright © 2018. All rights reserved.