public class DbPro extends Object
Modifier and Type | Method and Description |
---|---|
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<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<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<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 = 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.
|
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) |
Object |
execute(ICallback callback) |
List<Record> |
find(SqlPara sqlPara) |
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(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) |
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) |
<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) |
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(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.
|
static DbPro |
use()
Deprecated.
|
static DbPro |
use(String configName)
Deprecated.
|
protected final Config config
public DbPro()
public DbPro(String configName)
@Deprecated public static DbPro use(String configName)
@Deprecated public static DbPro use()
public Config getConfig()
public <T> List<T> query(String sql, Object... paras)
#query(String, String, Object...)
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, Object... paras)
#find(String, 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);
delete(String, String, Record)
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
SQLException
protected 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)
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 save(String tableName, Record record)
save(String, String, Record)
public 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);
update(String, String, 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 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
SQLException
public int[] batch(String sql, Object[][] paras, int batchSize)
Example: String sql = "insert into user(name, cash) values(?, ?)"; int[] result = DbPro.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
SQLException
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(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
SQLException
public int[] batch(List<String> sqlList, int batchSize)
Example: int[] result = DbPro.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<Record> recordList, int batchSize)
tableName
- the table namepublic int[] batchUpdate(List<? extends Model> modelList, int batchSize)
public int[] batchUpdate(String tableName, String primaryKey, List<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<Record> recordList, int batchSize)
tableName
- the table namepublic int update(SqlPara sqlPara)
Copyright © 2018. All rights reserved.