|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.dbutils.AbstractQueryRunner
org.apache.commons.dbutils.QueryRunner
com.github.drinkjava2.jdbpro.ImprovedQueryRunner
public class ImprovedQueryRunner
ImprovedQueryRunner made below improvements compare DbUtils's QueryRunner:
1) Override close() and prepareConnection() method of QueryRunner, use a
ConnectionManager to manage connection, ConnectionManager can get connection
from DataSource or ThreadLocal or some other 3rd party tools like Spring.
2) Override some methods to add logger support
3) Override some execute/update/query methods to support batch operation and
AroundSqlHandler
| Field Summary | |
|---|---|
protected Boolean |
allowShowSQL
|
protected Integer |
batchSize
|
protected ConnectionManager |
connectionManager
|
protected IocTool |
iocTool
An IOC tool is needed if want use SqlMapper style and Annotation has parameters |
protected DbProLogger |
logger
|
protected DbPro[] |
masters
|
protected SqlOption |
masterSlaveOption
|
protected String |
name
|
protected DbPro[] |
slaves
|
protected SqlHandler[] |
sqlHandlers
|
protected SqlTemplateEngine |
sqlTemplateEngine
|
| Fields inherited from class org.apache.commons.dbutils.AbstractQueryRunner |
|---|
ds |
| Constructor Summary | |
|---|---|
ImprovedQueryRunner()
|
|
ImprovedQueryRunner(DataSource ds)
|
|
ImprovedQueryRunner(DataSource ds,
ConnectionManager cm)
|
|
| Method Summary | ||
|---|---|---|
void |
close(Connection conn)
|
|
void |
fillStatement(PreparedStatement stmt,
Object... params)
|
|
protected String |
formatParametersForLoggerOutput(Object... params)
Format parameters for logger output, subClass can override this method to customise parameters format |
|
protected String |
formatSqlForLoggerOutput(String sql)
Format SQL for logger output, subClass can override this method to customise SQL format |
|
Boolean |
getAllowShowSQL()
|
|
Integer |
getBatchSize()
|
|
ConnectionManager |
getConnectionManager()
|
|
IocTool |
getIocTool()
|
|
DbProLogger |
getLogger()
|
|
DbPro[] |
getMasters()
|
|
SqlOption |
getMasterSlaveOption()
|
|
String |
getName()
|
|
DbPro[] |
getSlaves()
|
|
ThreadLocal<ArrayList<PreparedSQL>> |
getSqlBatchCache()
|
|
SqlHandler[] |
getSqlHandlers()
|
|
SqlTemplateEngine |
getSqlTemplateEngine()
|
|
static SqlHandler[] |
getThreadLocalSqlHandlers()
Get current thread's ThreadLocal SqlHandler |
|
boolean |
isBatchEnabled()
|
|
static Object[][] |
listListToArray2D(List<List<?>> paramList)
Convert Objects List to 2d array for insertBatch use, insertBatch's last parameter is a 2d array, not easy to use |
|
int[] |
nBatch(Connection conn,
String sql,
List<Object[]> params)
Execute a batch of SQL INSERT, UPDATE, or DELETE queries. |
|
int[] |
nBatch(String sql,
List<Object[]> params)
Execute a batch of SQL INSERT, UPDATE, or DELETE queries. |
|
void |
nBatchBegin()
Start batch sql |
|
void |
nBatchEnd()
Stop batch sql |
|
|
nBatchFlush()
Force flush cached SQLs |
|
|
nInsertBatch(Connection conn,
String sql,
org.apache.commons.dbutils.ResultSetHandler<T> rsh,
List<Object[]> params)
Executes the given batch of INSERT SQL statements. |
|
|
nInsertBatch(String sql,
org.apache.commons.dbutils.ResultSetHandler<T> rsh,
List<Object[]> params)
Executes the given batch of INSERT SQL statements. |
|
static Object[][] |
objectsListToArray2D(List<Object[]> paramList)
Convert List List to 2d array for insertBatch use, insertBatch's last parameter is a 2d array, not easy to use |
|
protected CallableStatement |
prepareCall(Connection conn,
String sql)
|
|
Connection |
prepareConnection()
|
|
protected PreparedStatement |
prepareStatement(Connection conn,
String sql)
|
|
long |
queryForLongValue(Connection conn,
String sql,
Object... params)
Query for a long value |
|
long |
queryForLongValue(String sql,
Object... params)
Query for a long value |
|
|
queryForObject(Connection conn,
String sql,
Object... params)
Query for an Object, only return the first row and first column's value if more than one column or more than 1 rows returned, a null object may return if no result found, SQLException may be threw if some SQL operation Exception happen. |
|
|
queryForObject(String sql,
Object... params)
Query for an Object, only return the first row and first column's value if more than one column or more than 1 rows returned, a null object may return if no result found, SQLException may be threw if some SQL operation Exception happen. |
|
protected
|
runExecute(PreparedSQL ps)
Executes the PreparedSQL query statement |
|
protected
|
runInsert(PreparedSQL ps)
Executes the PreparedSQL insert statement |
|
Object |
runPreparedSQL(PreparedSQL ps)
This is the core method of whole project, handle a PreparedSQL instance and return a result |
|
protected
|
runQuery(PreparedSQL ps)
Executes the PreparedSQL query statement |
|
Object |
runRealSqlMethod(PreparedSQL ps)
Execute real SQL operation according PreparedSql's SqlType |
|
protected int |
runUpdate(PreparedSQL ps)
Executes the PreparedSQL update statement |
|
void |
setAllowShowSQL(Boolean allowShowSQL)
Deprecated. |
|
void |
setBatchSize(Integer batchSize)
Deprecated. |
|
void |
setConnectionManager(ConnectionManager connectionManager)
Deprecated. |
|
void |
setIocTool(IocTool iocTool)
Deprecated. |
|
void |
setLogger(DbProLogger logger)
Deprecated. |
|
void |
setMasters(DbPro[] masters)
Deprecated. |
|
void |
setMasterSlaveOption(SqlOption masterSlaveOption)
Deprecated. |
|
void |
setName(String name)
This method is not thread safe, suggest only use at program starting |
|
void |
setSlaves(DbPro[] slaves)
Deprecated. |
|
void |
setSqlHandlers(SqlHandler[] sqlHandlers)
Deprecated. |
|
void |
setSqlTemplateEngine(SqlTemplateEngine sqlTemplateEngine)
Deprecated. |
|
static void |
setThreadLocalSqlHandlers(SqlHandler... handlers)
Set current thread's ThreadLocal SqlHandler |
|
| Methods inherited from class org.apache.commons.dbutils.QueryRunner |
|---|
batch, batch, execute, execute, execute, execute, insert, insert, insert, insert, insertBatch, insertBatch, query, query, query, query, query, query, query, query, update, update, update, update, update, update |
| Methods inherited from class org.apache.commons.dbutils.AbstractQueryRunner |
|---|
close, close, fillStatementWithBean, fillStatementWithBean, getDataSource, isPmdKnownBroken, prepareStatement, rethrow, wrap |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected SqlTemplateEngine sqlTemplateEngine
protected ConnectionManager connectionManager
protected Boolean allowShowSQL
protected SqlOption masterSlaveOption
protected DbProLogger logger
protected Integer batchSize
protected SqlHandler[] sqlHandlers
protected DbPro[] slaves
protected DbPro[] masters
protected String name
protected IocTool iocTool
| Constructor Detail |
|---|
public ImprovedQueryRunner()
public ImprovedQueryRunner(DataSource ds)
public ImprovedQueryRunner(DataSource ds,
ConnectionManager cm)
| Method Detail |
|---|
public void close(Connection conn)
throws SQLException
close in class org.apache.commons.dbutils.AbstractQueryRunnerSQLException
public Connection prepareConnection()
throws SQLException
prepareConnection in class org.apache.commons.dbutils.AbstractQueryRunnerSQLException
protected CallableStatement prepareCall(Connection conn,
String sql)
throws SQLException
prepareCall in class org.apache.commons.dbutils.AbstractQueryRunnerSQLException
protected PreparedStatement prepareStatement(Connection conn,
String sql)
throws SQLException
prepareStatement in class org.apache.commons.dbutils.AbstractQueryRunnerSQLException
public void fillStatement(PreparedStatement stmt,
Object... params)
throws SQLException
fillStatement in class org.apache.commons.dbutils.AbstractQueryRunnerSQLExceptionprotected String formatSqlForLoggerOutput(String sql)
protected String formatParametersForLoggerOutput(Object... params)
public <T> T nBatchFlush()
public void nBatchBegin()
public void nBatchEnd()
public <T> T queryForObject(Connection conn,
String sql,
Object... params)
throws SQLException
sql - The SQLparams - The parameters
SQLException
public long queryForLongValue(Connection conn,
String sql,
Object... params)
throws SQLException
sql - The SQLparams - The parameters
SQLException
public <T> T queryForObject(String sql,
Object... params)
throws SQLException
sql - The SQLparams - The parameters
SQLException
public long queryForLongValue(String sql,
Object... params)
throws SQLException
sql - The SQLparams - The parameters
SQLExceptionpublic Object runPreparedSQL(PreparedSQL ps)
public Object runRealSqlMethod(PreparedSQL ps)
protected <T> T runQuery(PreparedSQL ps)
ps - The PreparedSQL
protected <T> T runInsert(PreparedSQL ps)
ps - The PreparedSQL
protected <T> T runExecute(PreparedSQL ps)
ps - The PreparedSQL
protected int runUpdate(PreparedSQL ps)
ps - The PreparedSQL
public int[] nBatch(String sql,
List<Object[]> params)
sql - The SQL to execute.params - A List of parameter list.
public int[] nBatch(Connection conn,
String sql,
List<Object[]> params)
throws SQLException
conn - The Connection to use to run the query. The caller is responsible
for closing this Connection.sql - The SQL to execute.params - A List of parameter list.
SQLException
public <T> T nInsertBatch(String sql,
org.apache.commons.dbutils.ResultSetHandler<T> rsh,
List<Object[]> params)
T - The type of object that the handler returnssql - The SQL statement to execute.rsh - The handler used to create the result object from the
ResultSet of auto-generated keys.params - A List of parameter list.
public <T> T nInsertBatch(Connection conn,
String sql,
org.apache.commons.dbutils.ResultSetHandler<T> rsh,
List<Object[]> params)
T - The type of object that the handler returnsconn - The connection to use to run the query.sql - The SQL to execute.rsh - The handler used to create the result object from the
ResultSet of auto-generated keys.params - A List of parameter list.
public static Object[][] listListToArray2D(List<List<?>> paramList)
public static Object[][] objectsListToArray2D(List<Object[]> paramList)
public static SqlHandler[] getThreadLocalSqlHandlers()
public static void setThreadLocalSqlHandlers(SqlHandler... handlers)
public Boolean getAllowShowSQL()
@Deprecated public void setAllowShowSQL(Boolean allowShowSQL)
public SqlTemplateEngine getSqlTemplateEngine()
@Deprecated public void setSqlTemplateEngine(SqlTemplateEngine sqlTemplateEngine)
public ConnectionManager getConnectionManager()
@Deprecated public void setConnectionManager(ConnectionManager connectionManager)
public DbProLogger getLogger()
@Deprecated public void setLogger(DbProLogger logger)
public Integer getBatchSize()
@Deprecated public void setBatchSize(Integer batchSize)
public SqlHandler[] getSqlHandlers()
@Deprecated public void setSqlHandlers(SqlHandler[] sqlHandlers)
public DbPro[] getSlaves()
@Deprecated public void setSlaves(DbPro[] slaves)
public DbPro[] getMasters()
@Deprecated public void setMasters(DbPro[] masters)
public IocTool getIocTool()
@Deprecated public void setIocTool(IocTool iocTool)
public SqlOption getMasterSlaveOption()
@Deprecated public void setMasterSlaveOption(SqlOption masterSlaveOption)
public String getName()
public void setName(String name)
public boolean isBatchEnabled()
public ThreadLocal<ArrayList<PreparedSQL>> getSqlBatchCache()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||