本文整理汇总了Java中org.apache.ibatis.executor.parameter.ParameterHandler类的典型用法代码示例。如果您正苦于以下问题:Java ParameterHandler类的具体用法?Java ParameterHandler怎么用?Java ParameterHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParameterHandler类属于org.apache.ibatis.executor.parameter包,在下文中一共展示了ParameterHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DefaultResultSetHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler, ResultHandler<?> resultHandler, BoundSql boundSql,
RowBounds rowBounds) {
this.executor = executor;
this.configuration = mappedStatement.getConfiguration();
this.mappedStatement = mappedStatement;
this.rowBounds = rowBounds;
this.parameterHandler = parameterHandler;
this.boundSql = boundSql;
this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
this.objectFactory = configuration.getObjectFactory();
this.reflectorFactory = configuration.getReflectorFactory();
this.resultHandler = resultHandler;
}
示例2: shouldRetainColumnNameCase
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
/**
* Contrary to the spec, some drivers require case-sensitive column names when getting result.
*
* @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a>
*/
@Test
public void shouldRetainColumnNameCase() throws Exception {
final MappedStatement ms = getMappedStatement();
final Executor executor = null;
final ParameterHandler parameterHandler = null;
final ResultHandler resultHandler = null;
final BoundSql boundSql = null;
final RowBounds rowBounds = new RowBounds(0, 100);
final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);
when(stmt.getResultSet()).thenReturn(rs);
when(rs.getMetaData()).thenReturn(rsmd);
when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY);
when(rs.next()).thenReturn(true).thenReturn(false);
when(rs.getInt("CoLuMn1")).thenReturn(100);
when(rs.wasNull()).thenReturn(false);
when(rsmd.getColumnCount()).thenReturn(1);
when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1");
when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER);
when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName());
when(stmt.getConnection()).thenReturn(conn);
when(conn.getMetaData()).thenReturn(dbmd);
when(dbmd.supportsMultipleResultSets()).thenReturn(false); // for simplicity.
final List<Object> results = fastResultSetHandler.handleResultSets(stmt);
assertEquals(1, results.size());
assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1"));
}
示例3: DefaultResultSetHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler, ResultHandler resultHandler, BoundSql boundSql,
RowBounds rowBounds) {
this.executor = executor;
this.configuration = mappedStatement.getConfiguration();
this.mappedStatement = mappedStatement;
this.rowBounds = rowBounds;
this.parameterHandler = parameterHandler;
this.boundSql = boundSql;
this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
this.objectFactory = configuration.getObjectFactory();
this.resultHandler = resultHandler;
}
示例4: getTotalCount
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
/**
* 获取总记录数
*
* @param sql 原始sql语句
* @param conn
* @param ms
* @param boundSql
* @return
* @throws SQLException
*/
private int getTotalCount(String sql, Connection conn, MappedStatement ms, BoundSql boundSql) throws SQLException {
int start = sql.indexOf("from");
if (start == -1) {
throw new RuntimeException("statement has no 'from' keyword");
}
int stop = sql.indexOf("order by");
if (stop == -1) {
stop = sql.length();
}
String countSql = "select count(0) " + sql.substring(start, stop);
BoundSql countBoundSql = new BoundSql(ms.getConfiguration(), countSql, boundSql.getParameterMappings(), boundSql.getParameterObject());
ParameterHandler parameterHandler = new DefaultParameterHandler(ms, boundSql.getParameterObject(), countBoundSql);
PreparedStatement stmt = null;
ResultSet rs = null;
int count = 0;
try {
stmt = conn.prepareStatement(countSql);
// 通过parameterHandler给PreparedStatement对象设置参数
parameterHandler.setParameters(stmt);
rs = stmt.executeQuery();
if (rs.next()) {
count = rs.getInt(1);
}
} finally {
CloseableUtil.closeQuietly(rs);
CloseableUtil.closeQuietly(stmt);
}
return count;
}
示例5: FastResultSetHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
public FastResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler, ResultHandler resultHandler, BoundSql boundSql, RowBounds rowBounds) {
this.executor = executor;
this.configuration = mappedStatement.getConfiguration();
this.mappedStatement = mappedStatement;
this.rowBounds = rowBounds;
this.parameterHandler = parameterHandler;
this.boundSql = boundSql;
this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
this.objectFactory = configuration.getObjectFactory();
this.resultHandler = resultHandler;
}
示例6: getParameters
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
private List<String> getParameters(MappedStatement ms, Object parameterObject, BoundSql boundSql) throws SQLException {
// DefaultParameterHandler is the only implementation of parameterHandler interface currently. it may be changed later.
// need additional codes to find a appropriate implementation in that case.
ParameterHandler parameterHandler = new DefaultParameterHandler(ms, parameterObject, boundSql);
PreparedStatementParameterLogger parameterLogger = new PreparedStatementParameterLogger();
parameterHandler.setParameters(parameterLogger);
return parameterLogger.getParameters();
}
示例7: DefaultResultSetHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler, ResultHandler<?> resultHandler, BoundSql boundSql,
RowBounds rowBounds) {
this.executor = executor;
this.configuration = mappedStatement.getConfiguration();
this.mappedStatement = mappedStatement;
this.rowBounds = rowBounds;
this.parameterHandler = parameterHandler;
this.boundSql = boundSql;
this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
this.objectFactory = configuration.getObjectFactory();
this.reflectorFactory = configuration.getReflectorFactory();
this.resultHandler = resultHandler;
this.primitiveTypes = new PrimitiveTypes();
}
示例8: createParameterHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject,
BoundSql boundSql) {
/* 使用自定义 ParameterHandler */
return new MybatisDefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
示例9: createParameterHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
示例10: getParameterHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler getParameterHandler() {
return delegate.getParameterHandler();
}
示例11: getParameterHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler getParameterHandler() {
return parameterHandler;
}
示例12: intercept
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
StopWatch stopWatch = new StopWatch("MyBatis Pagination Plugin");
stopWatch.start("Get page object");
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
Pagination page = null;
ParameterHandler parameterHandler = statementHandler.getParameterHandler();
Object parameterObject = parameterHandler.getParameterObject();
if (parameterObject instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> params = (Map<String, Object>) parameterObject;
for (Map.Entry<String, Object> entry : params.entrySet()) {
Object parameter = entry.getValue();
if (parameter instanceof Pagination) {
page = (Pagination) parameter;
break;
}
}
}
stopWatch.stop();
if (page == null) {
return invocation.proceed();
}
stopWatch.start("Count result");
String originSql = statementHandler.getBoundSql().getSql();
logger.debug("Original SQL: {}", originSql);
// 查询总记录数
Configuration configuration = (Configuration) metaObject.getValue(DELEGATE_CONFIGURATION);
int rowCount = getQueryCount(configuration, statementHandler);
stopWatch.stop();
// 根据查询得到的总记录数初始化分页对象
page.setRowCount(rowCount);
page.initialize();
stopWatch.start("Generate page sql");
// 分页查询 本地化对象 修改数据库注意修改实现
String pageSql = generatePageSql(originSql, page, dialect);
logger.debug("Pagination SQL: {}", pageSql);
metaObject.setValue(DELEGATE_BOUND_SQL, pageSql);
metaObject.setValue(DELEGATE_ROW_BOUNDS_OFFSET, RowBounds.NO_ROW_OFFSET);
metaObject.setValue(DELEGATE_ROW_BOUNDS_LIMIT, RowBounds.NO_ROW_LIMIT);
stopWatch.stop();
if (logger.isDebugEnabled()) {
logger.debug(stopWatch.prettyPrint());
}
return invocation.proceed();
}
示例13: createParameterHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
示例14: createParameterHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
//返回默认的参数处理器
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
示例15: createParameterHandler
import org.apache.ibatis.executor.parameter.ParameterHandler; //导入依赖的package包/类
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}