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 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(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(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 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) |
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 <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[] |
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 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(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(String configName) |
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);
public static Page<Record> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras)
#paginate(String, int, int, String, String, Object...)public static Page<Record> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect)
#paginate(String, int, int, String, String, Object...)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(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, String select, String sqlExceptSelect)
public static int[] batch(String sql, Object[][] paras, int batchSize)
#batch(String, String, Object[][], int)public static int[] batch(String sql, String columns, List modelOrRecordList, int batchSize)
#batch(String, String, String, List, int)Copyright © 2015. All rights reserved.