| Method from com.ibatis.sqlmap.engine.execution.SqlExecutor Detail: |
public void addBatch(RequestScope request,
Connection conn,
String sql,
Object[] parameters) throws SQLException {
Batch batch = (Batch) request.getSession().getBatch();
if (batch == null) {
batch = new Batch();
request.getSession().setBatch(batch);
}
batch.addBatch(request, conn, sql, parameters);
}
Adds a statement to a batch |
public void cleanup(SessionScope session) {
Batch batch = (Batch) session.getBatch();
if (batch != null) {
batch.cleanupBatch();
session.setBatch(null);
}
}
Clean up any batches on the session |
public int executeBatch(SessionScope session) throws SQLException {
int rows = 0;
Batch batch = (Batch) session.getBatch();
if (batch != null) {
try {
rows = batch.executeBatch();
} finally {
batch.cleanupBatch();
}
}
return rows;
}
Execute a batch of statements |
public void executeQuery(RequestScope request,
Connection conn,
String sql,
Object[] parameters,
int skipResults,
int maxResults,
RowHandlerCallback callback) throws SQLException {
ErrorContext errorContext = request.getErrorContext();
errorContext.setActivity("executing query");
errorContext.setObjectId(sql);
PreparedStatement ps = null;
ResultSet rs = null;
try {
errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
Integer rsType = request.getStatement().getResultSetType();
if (rsType != null) {
ps = conn.prepareStatement(sql, rsType.intValue(), ResultSet.CONCUR_READ_ONLY);
} else {
ps = conn.prepareStatement(sql);
}
Integer fetchSize = request.getStatement().getFetchSize();
if (fetchSize != null) {
ps.setFetchSize(fetchSize.intValue());
}
errorContext.setMoreInfo("Check the parameters (set parameters failed).");
request.getParameterMap().setParameters(request, ps, parameters);
errorContext.setMoreInfo("Check the statement (query failed).");
ps.execute();
rs = ps.getResultSet();
errorContext.setMoreInfo("Check the results (failed to retrieve results).");
handleResults(request, rs, skipResults, maxResults, callback);
// clear out remaining results
while (ps.getMoreResults());
} finally {
try {
closeResultSet(rs);
} finally {
closeStatement(ps);
}
}
}
Long form of the method to execute a query |
public void executeQueryProcedure(RequestScope request,
Connection conn,
String sql,
Object[] parameters,
int skipResults,
int maxResults,
RowHandlerCallback callback) throws SQLException {
ErrorContext errorContext = request.getErrorContext();
errorContext.setActivity("executing query procedure");
errorContext.setObjectId(sql);
CallableStatement cs = null;
ResultSet rs = null;
try {
errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
cs = conn.prepareCall(sql);
ParameterMap parameterMap = request.getParameterMap();
ParameterMapping[] mappings = parameterMap.getParameterMappings();
errorContext.setMoreInfo("Check the output parameters (register output parameters failed).");
registerOutputParameters(cs, mappings);
errorContext.setMoreInfo("Check the parameters (set parameters failed).");
parameterMap.setParameters(request, cs, parameters);
errorContext.setMoreInfo("Check the statement (update procedure failed).");
cs.execute();
rs = cs.getResultSet();
errorContext.setMoreInfo("Check the results (failed to retrieve results).");
handleResults(request, rs, skipResults, maxResults, callback);
errorContext.setMoreInfo("Check the output parameters (retrieval of output parameters failed).");
retrieveOutputParameters(cs, mappings, parameters);
} finally {
try {
closeResultSet(rs);
} finally {
closeStatement(cs);
}
}
}
Execute a stored procedure |
public int executeUpdate(RequestScope request,
Connection conn,
String sql,
Object[] parameters) throws SQLException {
//
// Public Methods
//
ErrorContext errorContext = request.getErrorContext();
errorContext.setActivity("executing update");
errorContext.setObjectId(sql);
PreparedStatement ps = null;
int rows = 0;
try {
errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
ps = conn.prepareStatement(sql);
errorContext.setMoreInfo("Check the parameters (set parameters failed).");
request.getParameterMap().setParameters(request, ps, parameters);
errorContext.setMoreInfo("Check the statement (update failed).");
ps.execute();
rows = ps.getUpdateCount();
}
finally {
closeStatement(ps);
}
return rows;
}
|
public int executeUpdateProcedure(RequestScope request,
Connection conn,
String sql,
Object[] parameters) throws SQLException {
ErrorContext errorContext = request.getErrorContext();
errorContext.setActivity("executing update procedure");
errorContext.setObjectId(sql);
CallableStatement cs = null;
int rows = 0;
try {
errorContext.setMoreInfo("Check the SQL Statement (preparation failed).");
cs = conn.prepareCall(sql);
ParameterMap parameterMap = request.getParameterMap();
ParameterMapping[] mappings = parameterMap.getParameterMappings();
errorContext.setMoreInfo("Check the output parameters (register output parameters failed).");
registerOutputParameters(cs, mappings);
errorContext.setMoreInfo("Check the parameters (set parameters failed).");
parameterMap.setParameters(request, cs, parameters);
errorContext.setMoreInfo("Check the statement (update procedure failed).");
cs.execute();
rows = cs.getUpdateCount();
errorContext.setMoreInfo("Check the output parameters (retrieval of output parameters failed).");
retrieveOutputParameters(cs, mappings, parameters);
} finally {
closeStatement(cs);
}
return rows;
}
Execute a stored procedure that updates data |