本文整理汇总了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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例14: getOneStockModel
import org.apache.ibatis.exceptions.TooManyResultsException; //导入依赖的package包/类
/**
* 根据查询参数查询单个对象(此方法只用于提供精确查询单个对象,若结果数超过1,则会报错)
*
* @param stockQuery 商品库存记录查询参数对象
* @return StockModel 商品库存记录领域对象
*/
public StockModel getOneStockModel(StockQuery stockQuery) throws TooManyResultsException;
示例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);
}