public class DbPro extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
boolean |
delete(String tableName,
Record record)
Example:
boolean succeed = DbPro.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)
Delete record by id.
|
Object |
execute(ICallback callback) |
List<Record> |
find(String sql) |
List<Record> |
find(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.
|
Record |
findById(String tableName,
Object idValue)
Find record by id with default primary key.
|
Record |
findById(String tableName,
String primaryKey,
Object... idValue)
Find record by id.
|
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.
|
Page<Record> |
paginate(int pageNumber,
int pageSize,
String select,
String sqlExceptSelect) |
Page<Record> |
paginate(int pageNumber,
int pageSize,
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.
|
<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[] |
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) |
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) |
boolean |
save(String tableName,
Record record) |
boolean |
save(String tableName,
String primaryKey,
Record record)
Save record.
|
boolean |
tx(IAtom atom)
Execute transaction with default transaction level.
|
boolean |
tx(int transactionLevel,
IAtom atom) |
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.
|
static DbPro |
use() |
static DbPro |
use(String configName) |
public DbPro()
public DbPro(String configName)
public static DbPro use()
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 <T> T queryColumn(String sql)
public BigDecimal queryBigDecimal(String sql, Object... paras)
public BigDecimal queryBigDecimal(String sql)
public byte[] queryBytes(String sql)
public 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...)public 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 = DbPro.use().findById("user", 15);
tableName - the table name of the tableidValue - the id value of the recordpublic Record findById(String tableName, String primaryKey, Object... idValue)
Example:
Record user = DbPro.use().findById("user", "user_id", 123);
Record userRole = DbPro.use().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 boolean deleteById(String tableName, Object idValue)
Example: DbPro.use().deleteById("user", 15);
tableName - the table name of the tableidValue - the id value of the recordpublic boolean deleteById(String tableName, String primaryKey, Object... idValue)
Example: DbPro.use().deleteById("user", "user_id", 15);
DbPro.use().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 boolean delete(String tableName, String primaryKey, Record record)
Example:
boolean succeed = DbPro.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 = DbPro.use().delete("user", user);
public Page<Record> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect, Object... paras)
#paginate(String, int, int, String, String, Object...)public Page<Record> paginate(int pageNumber, int pageSize, String select, String sqlExceptSelect)
#paginate(String, int, int, String, String, Object...)public boolean save(String tableName, String primaryKey, Record record)
Example:
Record userRole = new Record().set("user_id", 123).set("role_id", 456);
DbPro.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 falsepublic boolean update(String tableName, String primaryKey, Record record)
Example: DbPro.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: DbPro.use().update("user", record);
public boolean tx(int transactionLevel,
IAtom atom)
public boolean tx(IAtom atom)
tx(int, IAtom)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 int[] batch(String sql, Object[][] paras, int batchSize)
Example:
String sql = "insert into user(name, cash) values(?, ?)";
int[] result = DbPro.use().batch("myConfig", 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.public int[] batch(String sql, String columns, List modelOrRecordList, int batchSize)
Example:
String sql = "insert into user(name, cash) values(?, ?)";
int[] result = DbPro.use().batch("myConfig", 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.Copyright © 2015. All rights reserved.