本文整理汇总了Java中org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultParameterHandler.setParameters方法的具体用法?Java DefaultParameterHandler.setParameters怎么用?Java DefaultParameterHandler.setParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.scripting.defaults.DefaultParameterHandler
的用法示例。
在下文中一共展示了DefaultParameterHandler.setParameters方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryTotal
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
/**
* 查询总记录条数
*
* @param sql
* @param mappedStatement
* @param boundSql
* @param page
*/
protected void queryTotal(boolean overflowCurrent, String sql, MappedStatement mappedStatement, BoundSql boundSql, Pagination page, Connection connection) {
try (PreparedStatement statement = connection.prepareStatement(sql)) {
DefaultParameterHandler parameterHandler = new MybatisDefaultParameterHandler(mappedStatement, boundSql.getParameterObject(), boundSql);
parameterHandler.setParameters(statement);
int total = 0;
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
total = resultSet.getInt(1);
}
}
page.setTotal(total);
/*
* 溢出总页数,设置第一页
*/
int pages = page.getPages();
if (overflowCurrent && (page.getCurrent() > pages)) {
// 设置为第一条
page.setCurrent(1);
}
} catch (Exception e) {
logger.error("Error: Method queryTotal execution error !", e);
}
}
示例2: getCount
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
public static int getCount(final MappedStatement ms, final Connection connection,
final Object parameterObject, Dialect dialect) throws SQLException {
BoundSql boundSql = ms.getBoundSql(parameterObject);
String countSql = dialect.getCountString(boundSql.getSql());
logger.debug("Total count SQL [{}]", countSql);
logger.debug("Parameters: {} ", parameterObject);
PreparedStatement stmt = null;
ResultSet rs;
try{
stmt = connection.prepareStatement(countSql);
DefaultParameterHandler handler = new DefaultParameterHandler(ms, parameterObject, boundSql);
handler.setParameters(stmt);
rs = stmt.executeQuery();
int count = 0;
if(rs.next()){
count = rs.getInt(1);
}
return count;
}finally {
closeStatement(stmt);
}
}
示例3: executeBatch
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
protected int executeBatch(MappedStatement mappedStatement,
BatchParameter<Object> paramObj,
PreparedStatement ps, BoundSql boundSql,
KeyGeneratorType keyGeneratorType) throws SQLException,
SecurityException, NoSuchFieldException,
IllegalArgumentException, IllegalAccessException {
int batchSize = paramObj.getBatchSize();
List<Object> parameterObject = paramObj.getData();
List<Object> batchParams = new ArrayList<Object>(batchSize);
for (Object pobject : parameterObject) {
DefaultParameterHandler handler = new DefaultParameterHandler(
mappedStatement, pobject, boundSql);
handler.setParameters(ps);
ps.addBatch();
batchParams.add(pobject);
if (batchParams.size() == batchSize) {
executeBatch(mappedStatement, ps, paramObj, keyGeneratorType,
batchParams);
batchParams.clear();
}
}
if (parameterObject.size() % batchSize != 0) {
executeBatch(mappedStatement, ps, paramObj, keyGeneratorType,
batchParams);
}
return 0;
}
示例4: getCount
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
/**
* 获取查询对象的总行数
* @param sql 获取总行数的SQL
* @param statementHandler
* @param configuration
* @param boundSql
* @param connection
* @throws Throwable
*/
public static void getCount(String sql, PreparedStatementHandler statementHandler,
Configuration configuration, BoundSql boundSql,
Connection connection)
throws Throwable{
Object parameterObject = statementHandler.getParameterHandler().getParameterObject();
if (logger.isDebugEnabled()) {
logger.debug("Total count SQL [{}] ", sql);
logger.debug("Total count Parameters: {} ", parameterObject);
}
PreparedStatement countStmt = null;
ResultSet rs = null;
try {
countStmt = connection.prepareStatement(sql);
final BoundSql countBS = new BoundSql(configuration, sql,
boundSql.getParameterMappings(), parameterObject);
MappedStatement mappedStatement = (MappedStatement) FieldUtils.readField(statementHandler, MAPPED_STATEMENT, true);
DefaultParameterHandler handler =
new DefaultParameterHandler(mappedStatement, parameterObject, countBS);
handler.setParameters(countStmt);
rs = countStmt.executeQuery();
int count = 0;
if (rs.next()) {
count = rs.getInt(1);
}
if (logger.isDebugEnabled()) {
logger.debug("Total count: {}", count);
}
totalRowCountHolder.set(count);
} finally {
try {
if (rs != null) {
rs.close();
}
} finally {
if (countStmt != null) {
countStmt.close();
}
}
}
}
示例5: intercept
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
if (invocation.getTarget() instanceof DefaultParameterHandler) {
DefaultParameterHandler parameterHandler = (DefaultParameterHandler) invocation
.getTarget();
MappedStatement mappedStatement = (MappedStatement) ReflectHelper
.getValueByFieldName(parameterHandler, "mappedStatement");
Object paramObj = ReflectHelper.getValueByFieldName(
parameterHandler, "parameterObject");
if (paramObj instanceof BatchInsertParameter) {
PreparedStatement ps = (PreparedStatement) invocation.getArgs()[0];
BoundSql boundSql = (BoundSql) ReflectHelper
.getValueByFieldName(parameterHandler, "boundSql");
@SuppressWarnings({ "unchecked", "rawtypes" })
List<Object> parameterObject = (List) ((BatchInsertParameter) paramObj)
.getData();
ps.clearBatch();
ps.clearParameters();
@SuppressWarnings("rawtypes")
int batchSize = ((BatchInsertParameter) paramObj)
.getBatchSize();
int i = 0;
for (Object pobject : parameterObject) {
DefaultParameterHandler handler = new DefaultParameterHandler(
mappedStatement, pobject, boundSql);
handler.setParameters(ps);
ps.addBatch();
i += 1;
if (i % batchSize == 0) {
ps.executeBatch();
}
}
if (parameterObject.size() % batchSize != 0) {
ps.executeBatch();
}
return i;
}
}
return invocation.proceed();
}