本文整理汇总了Java中org.apache.ibatis.session.ResultHandler类的典型用法代码示例。如果您正苦于以下问题:Java ResultHandler类的具体用法?Java ResultHandler怎么用?Java ResultHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResultHandler类属于org.apache.ibatis.session包,在下文中一共展示了ResultHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParameterType
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
private Class<?> getParameterType(Method method) {
Class<?> parameterType = null;
Class<?>[] parameterTypes = method.getParameterTypes();
for (Class<?> currentParameterType : parameterTypes) {
if (!RowBounds.class.isAssignableFrom(currentParameterType)
&& !ResultHandler.class.isAssignableFrom(currentParameterType)) {
if (parameterType == null) {
parameterType = currentParameterType;
} else {
// issue #135
parameterType = ParamMap.class;
}
}
}
return parameterType;
}
示例2: selectNodePropertiesByTypes
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Override
public List<NodePropertyEntity> selectNodePropertiesByTypes(Set<QName> qnames)
{
final List<NodePropertyEntity> properties = new ArrayList<NodePropertyEntity>();
// qnames of properties that are encrypted
Set<Long> qnameIds = qnameDAO.convertQNamesToIds(qnames, false);
if(qnameIds.size() > 0)
{
IdsEntity param = new IdsEntity();
param.setIds(new ArrayList<Long>(qnameIds));
// TODO - use a callback approach
template.select(SELECT_PROPERTIES_BY_TYPES, param, new ResultHandler()
{
@Override
public void handleResult(ResultContext context)
{
properties.add((NodePropertyEntity)context.getResultObject());
}
});
}
return properties;
}
示例3: selectNodePropertiesByDataType
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Override
public List<NodePropertyEntity> selectNodePropertiesByDataType(QName dataType, long minNodeId, long maxNodeId)
{
int typeOrdinal = NodePropertyValue.convertToTypeOrdinal(dataType);
IdsEntity ids = new IdsEntity();
ids.setIdOne((long)typeOrdinal);
ids.setIdTwo(minNodeId);
ids.setIdThree(maxNodeId);
final List<NodePropertyEntity> properties = new ArrayList<NodePropertyEntity>();
template.select(SELECT_PROPERTIES_BY_ACTUAL_TYPE, ids, new ResultHandler()
{
@Override
public void handleResult(ResultContext context)
{
properties.add((NodePropertyEntity)context.getResultObject());
}
});
return properties;
}
示例4: selectNodesWithAspects
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Override
protected void selectNodesWithAspects(
List<Long> qnameIds,
Long minNodeId, Long maxNodeId,
final NodeRefQueryCallback resultsCallback)
{
ResultHandler resultHandler = new ResultHandler()
{
public void handleResult(ResultContext context)
{
NodeEntity entity = (NodeEntity) context.getResultObject();
Pair<Long, NodeRef> nodePair = new Pair<Long, NodeRef>(entity.getId(), entity.getNodeRef());
resultsCallback.handle(nodePair);
}
};
IdsEntity parameters = new IdsEntity();
parameters.setIdOne(minNodeId);
parameters.setIdTwo(maxNodeId);
parameters.setIds(qnameIds);
template.select(SELECT_NODES_WITH_ASPECT_IDS, parameters, resultHandler);
}
示例5: RollupResultHandler
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
/**
* @param keyProperties the properties that make up the unique key
* @param collectionProperty the property mapped using a nested <b>ResultMap</b>
* @param resultHandler the result handler that will receive the rolled-up results
* @param maxResults the maximum number of results to retrieve (-1 for no limit).
* Make sure that the query result limit is large enough to produce this
* at least this number of results
*/
public RollupResultHandler(Configuration configuration, String[] keyProperties, String collectionProperty, ResultHandler resultHandler, int maxResults)
{
if (keyProperties == null || keyProperties.length == 0)
{
throw new IllegalArgumentException("RollupRowHandler can only be used with at least one key property.");
}
if (collectionProperty == null)
{
throw new IllegalArgumentException("RollupRowHandler must have a collection property.");
}
this.configuration = configuration;
this.keyProperties = keyProperties;
this.collectionProperty = collectionProperty;
this.resultHandler = resultHandler;
this.maxResults = maxResults;
this.rawResults = new ArrayList<Object>(100);
}
示例6: getMapperSql
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
/**
* 通过Mapper接口和方法名
* @param session
* @param mapperInterface
* @param methodName
* @param args
* @return
*/
public static String getMapperSql(SqlSession session, Class mapperInterface, String methodName, Object... args) {
String fullMapperMethodName = mapperInterface.getCanonicalName() + "." + methodName;
if (args == null || args.length == 0) {
return getNamespaceSql(session, fullMapperMethodName, null);
}
Method method = getDeclaredMethods(mapperInterface, methodName);
Map params = new HashMap();
final Class<?>[] argTypes = method.getParameterTypes();
for (int i = 0; i < argTypes.length; i++) {
if (!RowBounds.class.isAssignableFrom(argTypes[i]) && !ResultHandler.class.isAssignableFrom(argTypes[i])) {
String paramName = "param" + String.valueOf(params.size() + 1);
paramName = getParamNameFromAnnotation(method, i, paramName);
params.put(paramName, i >= args.length ? null : args[i]);
}
}
if (useParameter(method, args)) {
return getNamespaceSql(session, fullMapperMethodName, args[0]);
}
return getNamespaceSql(session, fullMapperMethodName, params);
}
示例7: executeQueryCount
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private Long executeQueryCount(Executor executor, MappedStatement countMs, Object parameter,
BoundSql boundSql, RowBounds rowBounds,
ResultHandler resultHandler) throws IllegalAccessException,
SQLException {
CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT,
boundSql);
String orignSql = boundSql.getSql().replaceAll(";$", "");
// count sql
String countSql = PageSqlUtils.getCountSql(orignSql);
BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql,
boundSql.getParameterMappings(), parameter);
// 执行 count 查询
Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT,
resultHandler, countKey, countBoundSql);
Long count = (Long) ((List) countResultList).get(0);
return count;
}
示例8: executeQueryCount
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private Long executeQueryCount(Executor executor, MappedStatement countMs,
Object parameter, BoundSql boundSql,
RowBounds rowBounds, ResultHandler resultHandler) throws IllegalAccessException, SQLException {
CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT, boundSql);
String orignSql = boundSql.getSql().replaceAll(";$", "");
// count sql
String countSql = PageSqlUtils.getCountSql(orignSql);
BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(),
parameter);
// 执行 count 查询
Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT, resultHandler, countKey,
countBoundSql);
Long count = (Long) ((List) countResultList).get(0);
return count;
}
示例9: doQuery
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Override
public <E> List<E> doQuery(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)
throws SQLException {
Statement stmt = null;
try {
flushStatements();
Configuration configuration = ms.getConfiguration();
StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameterObject, rowBounds, resultHandler, boundSql);
Connection connection = getConnection(ms.getStatementLog());
stmt = handler.prepare(connection, transaction.getTimeout());
handler.parameterize(stmt);
return handler.<E>query(stmt, resultHandler);
} finally {
closeStatement(stmt);
}
}
示例10: RoutingStatementHandler
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
switch (ms.getStatementType()) {
case STATEMENT:
delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
break;
case PREPARED:
delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
break;
case CALLABLE:
delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);
break;
default:
throw new ExecutorException("Unknown statement type: " + ms.getStatementType());
}
}
示例11: BaseStatementHandler
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
this.configuration = mappedStatement.getConfiguration();
this.executor = executor;
this.mappedStatement = mappedStatement;
this.rowBounds = rowBounds;
this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
this.objectFactory = configuration.getObjectFactory();
if (boundSql == null) { // issue #435, get the key before calculating the statement
generateKeys(parameterObject);
boundSql = mappedStatement.getBoundSql(parameterObject);
}
this.boundSql = boundSql;
this.parameterHandler = configuration.newParameterHandler(mappedStatement, parameterObject, boundSql);
this.resultSetHandler = configuration.newResultSetHandler(executor, mappedStatement, rowBounds, parameterHandler, resultHandler, boundSql);
}
示例12: query
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Override
public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql)
throws SQLException {
Cache cache = ms.getCache();
if (cache != null) {
flushCacheIfRequired(ms);
if (ms.isUseCache() && resultHandler == null) {
ensureNoOutParams(ms, parameterObject, boundSql);
@SuppressWarnings("unchecked")
List<E> list = (List<E>) tcm.getObject(cache, key);
if (list == null) {
list = delegate.<E> query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
tcm.putObject(cache, key, list); // issue #578 and #116
}
return list;
}
}
return delegate.<E> query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);
}
示例13: testDeferLoadDuringResultHandler
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Test
public void testDeferLoadDuringResultHandler() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
class MyResultHandler implements ResultHandler {
@Override
public void handleResult(ResultContext context) {
Child child = (Child)context.getResultObject();
assertNotNull(child.getFather());
}
};
sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
} finally {
sqlSession.close();
}
}
示例14: testDeferLoadDuringResultHandlerWithLazyLoad
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Test
public void testDeferLoadDuringResultHandlerWithLazyLoad() {
SqlSession sqlSession = lazyLoadSqlSessionFactory.openSession();
try {
class MyResultHandler implements ResultHandler {
@Override
public void handleResult(ResultContext context) {
Child child = (Child)context.getResultObject();
assertNotNull(child.getFather());
}
};
sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
} finally {
sqlSession.close();
}
}
示例15: testUnorderedGetPersonWithHandler
import org.apache.ibatis.session.ResultHandler; //导入依赖的package包/类
@Test(expected=PersistenceException.class)
public void testUnorderedGetPersonWithHandler() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
sqlSession.select("getPersonsWithItemsOrdered", new ResultHandler() {
public void handleResult(ResultContext context) {
Person person = (Person) context.getResultObject();
if ("grandma".equals(person.getName())) {
Assert.assertEquals(2, person.getItems().size());
}
}
});
} finally {
sqlSession.close();
}
}