当前位置: 首页>>代码示例>>Java>>正文


Java TooManyResultsException类代码示例

本文整理汇总了Java中org.apache.ibatis.exceptions.TooManyResultsException的典型用法代码示例。如果您正苦于以下问题:Java TooManyResultsException类的具体用法?Java TooManyResultsException怎么用?Java TooManyResultsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TooManyResultsException类属于org.apache.ibatis.exceptions包,在下文中一共展示了TooManyResultsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: selectOne

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 * 查询一条记录
 * 
 * @param arg0
 * @param arg1
 * @return
 */
public <M extends BaseBean> M selectOne(String arg0, M param) {
	if (param == null) {
		return null;
	}
	
	SqlSession session = openSession();
	M bean = null;
	try {
		bean = session.selectOne(arg0, param);
	} catch (MyBatisSystemException e) {
		if (e != null && e.getCause() instanceof TooManyResultsException) {
		} else {
			throw e;
		}
	}
	return bean;
}
 
开发者ID:ImKarl,项目名称:ccshop,代码行数:25,代码来源:BaseDao.java

示例2: testDynamicSelectAll

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 * 查询全部
 */
@Test(expected = TooManyResultsException.class)
public void testDynamicSelectAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = mapper.selectOne(new Country());
    } finally {
        sqlSession.close();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:14,代码来源:TestSelectOne.java

示例3: testDynamicSelectAllByNull

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 * 入参为null时查询全部
 */
@Test(expected = TooManyResultsException.class)
public void testDynamicSelectAllByNull() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.selectOne(null);
    } finally {
        sqlSession.close();
    }
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:14,代码来源:TestSelectOne.java

示例4: getOne

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 * 获取List中最多只有一个的数据
 *
 * @param list List结果
 * @param <T>  泛型类型
 * @return result
 */
private <T> T getOne(List<T> list) {
    if (list.size() == 1) {
        return list.get(0);
    } else if (list.size() > 1) {
        throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne()," +
                " but found: " + list
                .size());
    } else {
        return null;
    }
}
 
开发者ID:drtrang,项目名称:spring-boot-autoconfigure,代码行数:19,代码来源:SqlMapper.java

示例5: findBy

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
@Override
public T findBy(String fieldName, Object value) throws TooManyResultsException {
    try {
        T model = modelClass.newInstance();
        Field field = modelClass.getDeclaredField(fieldName);
        field.setAccessible(true);
        field.set(model, value);
        return mapper.selectOne(model);
    } catch (ReflectiveOperationException e) {
        throw new ServiceException(e.getMessage(), e);
    }
}
 
开发者ID:pandboy,项目名称:pingguopai,代码行数:13,代码来源:AbstractServiceImpl.java

示例6: selectOne

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
@Override
public <T> T selectOne(String statement, Object parameter) {
  // Popular vote was to return null on 0 results and throw exception on too many.
  List<T> list = this.<T>selectList(statement, parameter);
  if (list.size() == 1) {
    return list.get(0);
  } else if (list.size() > 1) {
    throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne(), but found: " + list.size());
  } else {
    return null;
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:13,代码来源:DefaultSqlSession.java

示例7: shouldFailWithTooManyResultsException

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
@Test(expected=TooManyResultsException.class)
public void shouldFailWithTooManyResultsException() throws Exception {
  SqlSession session = sqlMapper.openSession(TransactionIsolationLevel.SERIALIZABLE);
  try {
    session.selectOne("org.apache.ibatis.domain.blog.mappers.AuthorMapper.selectAllAuthors");
  } finally {
    session.close();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:10,代码来源:SqlSessionTest.java

示例8: selectOne

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 * 源码解析: select一个元素
 */
@Override
public <T> T selectOne(String statement, Object parameter) {
  // Popular vote was to return null on 0 results and throw exception on too many.
  List<T> list = this.<T>selectList(statement, parameter);
  if (list.size() == 1) {
    // 源码解析: 结果集大小等于1, 直接返回
    return list.get(0);
  } else if (list.size() > 1) {
    // 源码解析: 结果集大小大于1, 抛出异常
    throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne(), but found: " + list.size());
  } else {
    return null;
  }
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:18,代码来源:DefaultSqlSession.java

示例9: selectOne

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
@Override
public <T> T selectOne(String statement, Object parameter) {
	List<T> list = this.<T> selectList(statement, parameter);
	if (list.size() == 1) {
		return list.get(0);
	} else if (list.size() > 1) {
		throw new TooManyResultsException(
				"Expected one result (or null) to be returned by selectOne(), but found: " + list.size());
	} else {
		return null;
	}
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:13,代码来源:DefaultSqlSessionHelper.java

示例10: selectOne

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
@Override
public <T> T selectOne(String statement, Object parameter) {
  // Popular vote was to return null on 0 results and throw exception on too many.
  //转而去调用selectList,很简单的,如果得到0条则返回null,得到1条则返回1条,得到多条报TooManyResultsException错
  List<T> list = this.<T>selectList(statement, parameter);
  if (list.size() == 1) {
    return list.get(0);
  } else if (list.size() > 1) {
    throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne(), but found: " + list.size());
  } else {
    return null;
  }
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:14,代码来源:DefaultSqlSession.java

示例11: testSelectOneByExampleException

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
@Test(expected = TooManyResultsException.class)
public void testSelectOneByExampleException() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151);
        example.or().andLessThan("id", 41);
        mapper.selectOneByExample(example);
    } finally {
        sqlSession.close();
    }
}
 
开发者ID:abel533,项目名称:Mapper,代码行数:14,代码来源:TestSelectOneByExample.java

示例12: getOneFromList

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 *	mybatis自带的条件查询返回的是一个list, 但是某些时候我们需要的是返回单条记录. <br/>
 *	该方法从mybatis的查询结果list中,取出为一个的第一条记录	
 * @author Hongbin Yuan
 * @param list		
 * @return	list 为空或者size为0,返回空; 
 * 			list 元素超过一个.
 * 			list 只包含单独一个元素, 返回该元素
 * @throws Exception	list 元素超过一个.
 */
public static <T> T getOneFromList(List<T> list) throws Exception{
	if(list == null || list.isEmpty()){
		return null;
	}
	if(list.size() > 1){
		 throw new TooManyResultsException("Expected one result (or null) to be returned, but found: " + list.size());
	}
	return list.get(0);
}
 
开发者ID:yuanmomo,项目名称:maven-archetype,代码行数:20,代码来源:MyBatisUtil.java

示例13: getOneFromList

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 *	mybatis自带的条件查询返回的是一个list, 但是某些时候我们需要的是返回单条记录. <br/>
 *	该方法从mybatis的查询结果list中,取出为一个的第一条记录	
 * @author Hongbin.Yuan
 * @param list		
 * @return	list 为空或者size为0,返回空; 
 * 			list 元素超过一个.
 * 			list 只包含单独一个元素, 返回该元素
 * @throws Exception	list 元素超过一个.
 */
public static <T> T getOneFromList(List<T> list) throws Exception{
	if(list == null || list.isEmpty()){
		return null;
	}
	if(list.size() > 1){
		 throw new TooManyResultsException("Expected one result (or null) to be returned, but found: " + list.size());
	}
	return list.get(0);
}
 
开发者ID:yuanmomo,项目名称:maven-archetype,代码行数:20,代码来源:MyBatisUtil.java

示例14: getOneStockModel

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 * 根据查询参数查询单个对象(此方法只用于提供精确查询单个对象,若结果数超过1,则会报错)
 *
 * @param stockQuery 商品库存记录查询参数对象
 * @return StockModel 商品库存记录领域对象
 */
public StockModel getOneStockModel(StockQuery stockQuery) throws TooManyResultsException;
 
开发者ID:xmomen,项目名称:dms-webapp,代码行数:8,代码来源:StockService.java

示例15: getOneStockRecordModel

import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
 * 根据查询参数查询单个对象(此方法只用于提供精确查询单个对象,若结果数超过1,则会报错)
 *
 * @param stockRecordQuery 商品库存查询参数对象
 * @return StockRecordModel 商品库存领域对象
 */
@Override
public StockRecordModel getOneStockRecordModel(StockRecordQuery stockRecordQuery) throws TooManyResultsException {
    return mybatisDao.getSqlSessionTemplate().selectOne(StockRecordMapperExt.StockRecordMapperNameSpace + "getStockRecordModel", stockRecordQuery);
}
 
开发者ID:xmomen,项目名称:dms-webapp,代码行数:11,代码来源:StockRecordServiceImpl.java


注:本文中的org.apache.ibatis.exceptions.TooManyResultsException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。