Java Code Examples for org.apache.ibatis.session.RowBounds

The following examples show how to use org.apache.ibatis.session.RowBounds. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mybaties   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldInsertNewAuthorByProc() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    Author author = new Author(97, "someone", "******", "[email protected]", null, null);
    MappedStatement insertStatement = ExecutorTestHelper.prepareInsertAuthorProc(config);
    MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
    int rows = executor.update(insertStatement, author);
    List<Author> authors = executor.query(selectStatement, 97, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    executor.flushStatements();
    executor.rollback(true);
    assertEquals(1, authors.size());
    assertEquals(author.toString(), authors.get(0).toString());
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 2
Source Project: mybatis   Source File: CachingExecutor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public <E> List<E> query(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql)
    throws SQLException {
  Cache cache = ms.getCache();
  //默认情况下是没有开启缓存的(二级缓存).要开启二级缓存,你需要在你的 SQL 映射文件中添加一行: <cache/>
  //简单的说,就是先查CacheKey,查不到再委托给实际的执行器去查
  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);
}
 
Example 3
Source Project: mybatis   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSelectDiscriminatedPost() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    MappedStatement selectStatement = ExecutorTestHelper.prepareSelectDiscriminatedPost(config);
    List<Map<String,String>> products = executor.query(selectStatement, null, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    assertEquals(5, products.size());
    for (Map<String,String> m : products) {
      if ("IMAGES".equals(m.get("SECTION"))) {
        assertNull(m.get("subject"));
      } else {
        assertNotNull(m.get("subject"));
      }
    }
  } finally {
    executor.close(false);
  }
}
 
Example 4
Source Project: QuickProject   Source File: SortListInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object intercept(Invocation invocation) throws Throwable {
       List<Sort> sortList = getSortList();
       if (sortList == null || sortList.size() == 0) {
           return invocation.proceed();
       }

       Executor executor = (Executor) invocation.getTarget();
       Object[] args = invocation.getArgs();
       MappedStatement ms = (MappedStatement) args[0];
       Object parameter = args[1];
       RowBounds rowBounds = (RowBounds) args[2];
       ResultHandler resultHandler = (ResultHandler) args[3];

       // 计算修改BoundSql
       BoundSql boundSql = ms.getBoundSql(parameter);
       MetaObject boundSqlHandler = MetaObject.forObject(boundSql, new DefaultObjectFactory(), new DefaultObjectWrapperFactory());
       Dialect dialect = DialectParser.parse(ms.getConfiguration());
       String sql = (String) boundSqlHandler.getValue("sql");
       sql = dialect.addSortString(sql, sortList);
       boundSqlHandler.setValue("sql", sql);

       // 继续执行原来的代码
       CacheKey key = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
       return executor.query(ms, parameter, rowBounds, resultHandler, key, boundSql);
}
 
Example 5
Source Project: mybatis   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldInsertNewAuthorUsingSimpleNonPreparedStatements() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    Author author = new Author(99, "someone", "******", "[email protected]", null, null);
    MappedStatement insertStatement = ExecutorTestHelper.createInsertAuthorWithIDof99MappedStatement(config);
    MappedStatement selectStatement = ExecutorTestHelper.createSelectAuthorWithIDof99MappedStatement(config);
    int rows = executor.update(insertStatement, null);
    List<Author> authors = executor.query(selectStatement, 99, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    executor.flushStatements();
    executor.rollback(true);
    assertEquals(1, authors.size());
    assertEquals(author.toString(), authors.get(0).toString());
    assertTrue(1 == rows || BatchExecutor.BATCH_UPDATE_RETURN_VALUE == rows);
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 6
Source Project: Milkomeda   Source File: SundialInterceptor.java    License: MIT License 6 votes vote down vote up
private void updateSql(String sql, Invocation invocation, MappedStatement ms, Object[] args, BoundSql boundSql) {
    BoundSql boundSqlNew = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(), boundSql.getParameterObject());
    MappedStatement mappedStatement = copyFrom(ms, new BoundSqlSqlSource(boundSqlNew));
    // 替换映射的语句
    args[0] = mappedStatement;

    // 针对查询方式的参数替换
    if (ms.getSqlCommandType() == SqlCommandType.SELECT) {
        Executor executor = (Executor) invocation.getTarget();
        Object parameter = args[1];
        RowBounds rowBounds = (RowBounds) args[2];
        // 6个参数时(因为分页插件的原因导致问题,需要修改对应的类型值)
        if (args.length == 6) {
            args[4] = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
            args[5] = boundSqlNew;
        }
    }
}
 
Example 7
Source Project: mybaties   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldInsertNewAuthorWithBeforeAutoKey() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    Author author = new Author(-1, "someone", "******", "[email protected]", null, Section.NEWS);
    MappedStatement insertStatement = ExecutorTestHelper.prepareInsertAuthorMappedStatementWithBeforeAutoKey(config);
    MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
    int rows = executor.update(insertStatement, author);
    assertTrue(rows > 0 || rows == BatchExecutor.BATCH_UPDATE_RETURN_VALUE);
    if (rows == BatchExecutor.BATCH_UPDATE_RETURN_VALUE) {
      executor.flushStatements();
    }
    assertEquals(123456, author.getId());
    if (author.getId() != BatchExecutor.BATCH_UPDATE_RETURN_VALUE) {
      List<Author> authors = executor.query(selectStatement, author.getId(), RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
      executor.rollback(true);
      assertEquals(1, authors.size());
      assertEquals(author.toString(), authors.get(0).toString());
      assertTrue(author.getId() >= 10000);
    }
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 8
Source Project: mybatis   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSelectTwoSetsOfAuthorsViaProc() throws Exception {
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    MappedStatement selectStatement = ExecutorTestHelper.prepareSelectTwoSetsOfAuthorsProc(config);
    List<List<Author>> authorSets = executor.query(selectStatement, new HashMap<String, Object>() {
      {
        put("id1", 101);
        put("id2", 102);
      }
    }, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    assertEquals(2, authorSets.size());
    for (List<Author> authors : authorSets) {
      assertEquals(2, authors.size());
      for (Object author : authors) {
        assertTrue(author instanceof Author);
      }
    }
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 9
Source Project: mybaties   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFetchOneOrphanedPostWithNoBlog() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    MappedStatement selectBlog = ExecutorTestHelper.prepareComplexSelectBlogMappedStatement(config);
    MappedStatement selectPost = ExecutorTestHelper.prepareSelectPostMappedStatement(config);
    config.addMappedStatement(selectBlog);
    config.addMappedStatement(selectPost);
    List<Post> posts = executor.query(selectPost, 5, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    executor.flushStatements();
    executor.rollback(true);
    assertEquals(1, posts.size());
    Post post = posts.get(0);
    assertNull(post.getBlog());
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 10
@Test
public void shouldHandleRowBounds() throws Exception {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
  Date targetMonth = fmt.parse("2014-01-01");
  final List<Account> accounts = new ArrayList<Account>();
  try {
    sqlSession.select("collectPageByBirthMonth", targetMonth, new RowBounds(1, 2), new ResultHandler() {
      @Override
      public void handleResult(ResultContext context) {
        Account account = (Account) context.getResultObject();
        accounts.add(account);
      }
    });
  } finally {
    sqlSession.close();
  }
  assertEquals(2, accounts.size());
  assertEquals("Bob2", accounts.get(0).getAccountName());
  assertEquals("Bob3", accounts.get(1).getAccountName());
}
 
Example 11
@Override
public void getContentUrlsOrphaned(
        final ContentUrlHandler contentUrlHandler,
        final Long maxOrphanTimeExclusive,
        final int maxResults)
{
    ParameterCheck.mandatory("maxOrphanTimeExclusive", maxOrphanTimeExclusive);
    
    ContentUrlOrphanQuery query = new ContentUrlOrphanQuery();
    query.setMaxOrphanTimeExclusive(maxOrphanTimeExclusive);
    List<ContentUrlEntity> results = template.selectList(SELECT_CONTENT_URLS_ORPHANED, 
                                                                                  query, 
                                                                                  new RowBounds(0, maxResults));
    // Pass the result to the callback
    for (ContentUrlEntity result : results)
    {
        contentUrlHandler.handle(
                result.getId(),
                result.getContentUrl(),
                result.getOrphanTime());
    }
}
 
Example 12
Source Project: Mybatis-PageHelper   Source File: RowBoundsTest.java    License: MIT License 6 votes vote down vote up
/**
 * 使用Mapper接口调用时,使用PageHelper.startPage效果更好,不需要添加Mapper接口参数
 */
@Test
public void testWithRowboundsAndCountTrue() {
    SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        //limit=0,这时候相当于用分页插件求count,但是前提必须是配置rounbounds方式求count,否则都是-1
        //这里由于没有配置,应该都是-1
        List<User> list = userMapper.selectAll(new RowBounds(1, -1));
        PageInfo<User> page = new PageInfo<User>(list);
        assertEquals(0, list.size());
        assertEquals(183, page.getTotal());

        //pageSize<0的时候同上
        list = userMapper.selectAll(new RowBounds(1, -100));
        page = new PageInfo<User>(list);
        assertEquals(0, list.size());
        assertEquals(183, page.getTotal());
    } finally {
        sqlSession.close();
    }
}
 
Example 13
Source Project: mybatis   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFetchPostWithBlogWithCompositeKey() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    MappedStatement selectBlog = ExecutorTestHelper.prepareSelectBlogByIdAndAuthor(config);
    MappedStatement selectPost = ExecutorTestHelper.prepareSelectPostWithBlogByAuthorMappedStatement(config);
    config.addMappedStatement(selectBlog);
    config.addMappedStatement(selectPost);
    List<Post> posts = executor.query(selectPost, 2, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    executor.flushStatements();
    assertEquals(1, posts.size());
    Post post = posts.get(0);
    assertNotNull(post.getBlog());
    assertEquals(101, post.getBlog().getAuthor().getId());
    executor.rollback(true);
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 14
Source Project: mybaties   Source File: RoutingStatementHandler.java    License: Apache License 2.0 6 votes vote down vote up
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {

    //根据语句类型,委派到不同的语句处理器(STATEMENT|PREPARED|CALLABLE)
    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());
    }

  }
 
Example 15
Source Project: mybatis   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUpdateAuthor() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    Author author = new Author(101, "someone", "******", "[email protected]", null, Section.NEWS);
    MappedStatement updateStatement = ExecutorTestHelper.prepareUpdateAuthorMappedStatement(config);
    MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
    int rows = executor.update(updateStatement, author);
    List<Author> authors = executor.query(selectStatement, 101, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    executor.flushStatements();
    executor.rollback(true);
    assertEquals(1, authors.size());
    assertEquals(author.toString(), authors.get(0).toString());
    assertTrue(1 == rows || BatchExecutor.BATCH_UPDATE_RETURN_VALUE == rows);
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 16
Source Project: mybaties   Source File: BaseExecutorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapConstructorResults() throws Exception {
  
  Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
  try {
    MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatementWithConstructorResults(config);
    List<Author> authors = executor.query(selectStatement, 102, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
    executor.flushStatements();
    executor.rollback(true);
    assertEquals(1, authors.size());

    Author author = authors.get(0);
    assertEquals(102, author.getId());
  } finally {
    executor.rollback(true);
    executor.close(false);
  }
}
 
Example 17
Source Project: mybatis   Source File: BaseExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private <E> List<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
  List<E> list;
  //先向缓存中放入占位符???
  localCache.putObject(key, EXECUTION_PLACEHOLDER);
  try {
    list = doQuery(ms, parameter, rowBounds, resultHandler, boundSql);
  } finally {
    //最后删除占位符
    localCache.removeObject(key);
  }
  //加入缓存
  localCache.putObject(key, list);
  //如果是存储过程,OUT参数也加入缓存
  if (ms.getStatementType() == StatementType.CALLABLE) {
    localOutputParameterCache.putObject(key, parameter);
  }
  return list;
}
 
Example 18
Source Project: Mybatis-PageHelper   Source File: BasicTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testNamespace1() {
    SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
    try {
        Map<String, Object> map = new HashMap<String, Object>();
        User user = new User();
        user.setName("刘睿");
        map.put("user", user);
        //同时测试不可变Map
        map = Collections.unmodifiableMap(map);
        List<User> list = sqlSession.selectList("select1", map, new RowBounds(1, 10));
        assertEquals(1, list.size());
        //判断查询结果的位置是否正确
        assertEquals(78, list.get(0).getId());
    } finally {
        sqlSession.close();
    }
}
 
Example 19
Source Project: blog   Source File: BlogController.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@ResponseBody
@GetMapping("/blog")
public String rowBounds() {
	int pageSize = 10;
	int totalCount = blogRepository.countBlogs();
	int totalPages = (totalCount % pageSize == 0) ? totalCount / pageSize : totalCount / pageSize + 1;
	System.out.println("[pageSize=" + pageSize + ",totalCount=" + totalCount + ",totalPages=" + totalPages + "]");
	for (int currentPage = 0; currentPage < totalPages; currentPage++) {
		List<Blog> blogs = blogRepository.selectBlogs("zhaohui", new RowBounds(currentPage * pageSize, pageSize));
		System.err.println("currentPage=" + (currentPage + 1) + ",current size:" + blogs.size());
		for(Blog blog:blogs){
			System.out.println(blog);
		}
	}
	return "ok";
}
 
Example 20
Source Project: mybatis   Source File: MapperMethod.java    License: Apache License 2.0 6 votes vote down vote up
private <E> Object executeForMany(SqlSession sqlSession, Object[] args) {
  List<E> result;
  Object param = method.convertArgsToSqlCommandParam(args);
  //代入RowBounds
  if (method.hasRowBounds()) {
    RowBounds rowBounds = method.extractRowBounds(args);
    result = sqlSession.<E>selectList(command.getName(), param, rowBounds);
  } else {
    result = sqlSession.<E>selectList(command.getName(), param);
  }
  // issue #510 Collections & arrays support
  if (!method.getReturnType().isAssignableFrom(result.getClass())) {
    if (method.getReturnType().isArray()) {
      return convertToArray(result);
    } else {
      return convertToDeclaredCollection(sqlSession.getConfiguration(), result);
    }
  }
  return result;
}
 
Example 21
Source Project: mybaties   Source File: BatchExecutor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int doUpdate(MappedStatement ms, Object parameterObject) throws SQLException {
  final Configuration configuration = ms.getConfiguration();
  final StatementHandler handler = configuration.newStatementHandler(this, ms, parameterObject, RowBounds.DEFAULT, null, null);
  final BoundSql boundSql = handler.getBoundSql();
  final String sql = boundSql.getSql();
  final Statement stmt;
  if (sql.equals(currentSql) && ms.equals(currentStatement)) {
    int last = statementList.size() - 1;
    stmt = statementList.get(last);
    BatchResult batchResult = batchResultList.get(last);
    batchResult.addParameterObject(parameterObject);
  } else {
    Connection connection = getConnection(ms.getStatementLog());
    stmt = handler.prepare(connection);
    currentSql = sql;
    currentStatement = ms;
    statementList.add(stmt);
    batchResultList.add(new BatchResult(ms, sql, parameterObject));
  }
  handler.parameterize(stmt);
  handler.batch(stmt);
  return BATCH_UPDATE_RETURN_VALUE;
}
 
Example 22
Source Project: mybaties   Source File: DefaultSqlSession.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <K, V> Map<K, V> selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) {
  //转而去调用selectList
  final List<?> list = selectList(statement, parameter, rowBounds);
  final DefaultMapResultHandler<K, V> mapResultHandler = new DefaultMapResultHandler<K, V>(mapKey,
      configuration.getObjectFactory(), configuration.getObjectWrapperFactory());
  final DefaultResultContext context = new DefaultResultContext();
  for (Object o : list) {
    //循环用DefaultMapResultHandler处理每条记录
    context.nextResultObject(o);
    mapResultHandler.handleResult(context);
  }
  //注意这个DefaultMapResultHandler里面存了所有已处理的记录(内部实现可能就是一个Map),最后再返回一个Map
  return mapResultHandler.getMappedResults();
}
 
Example 23
Source Project: mybaties   Source File: BindingTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSelectListOfPostsLikeTwoParameters() {
  SqlSession session = sqlSessionFactory.openSession();
  try {
    BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
    List<Post> posts = mapper.selectPostsLikeSubjectAndBody(new RowBounds(1,1),"%a%","%a%");
    assertEquals(1, posts.size());
  } finally {
    session.close();
  }
}
 
Example 24
Source Project: mybatis   Source File: DefaultSqlSession.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) {
  try {
    MappedStatement ms = configuration.getMappedStatement(statement);
    executor.query(ms, wrapCollection(parameter), rowBounds, handler);
  } catch (Exception e) {
    throw ExceptionFactory.wrapException("Error querying database.  Cause: " + e, e);
  } finally {
    ErrorContext.instance().reset();
  }
}
 
Example 25
Source Project: nexus-public   Source File: EntityExecutor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CacheKey createCacheKey(final MappedStatement ms,
                               final Object parameterObject,
                               final RowBounds rowBounds,
                               final BoundSql boundSql)
{
  return delegate.createCacheKey(ms, parameterObject, rowBounds, boundSql);
}
 
Example 26
@Override
public <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds)
{
    long startTime = System.currentTimeMillis();
    try
    {
        return this.sqlSession.selectList(statement, parameter, rowBounds);
    }
    finally
    {
        reportQueryExecuted(startTime, SELECT_LABEL, statement);
    }
}
 
Example 27
Source Project: Mybatis-PageHelper   Source File: SqlServer2012RowBoundsDialect.java    License: MIT License 5 votes vote down vote up
@Override
public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) {
    StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14);
    sqlBuilder.append(sql);
    sqlBuilder.append(" OFFSET ");
    sqlBuilder.append(rowBounds.getOffset());
    sqlBuilder.append(" ROWS ");
    pageKey.update(rowBounds.getOffset());
    sqlBuilder.append(" FETCH NEXT ");
    sqlBuilder.append(rowBounds.getLimit());
    sqlBuilder.append(" ROWS ONLY");
    pageKey.update(rowBounds.getLimit());
    return sqlBuilder.toString();
}
 
Example 28
Source Project: syhthems-platform   Source File: DataPointServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public DataPoint selectTop(DataPointQueryVO dataPointQueryVO) {
    Assert.notNull(dataPointQueryVO, "查询参数不能为空");
    Assert.notNull(dataPointQueryVO.getDeviceId(), "设备ID不能为空");
    Assert.notNull(dataPointQueryVO.getDataStreamId(), "数据流参数不能为空");
    Example dataPointExample = new Example(DataPoint.class);
    dataPointExample.createCriteria().andEqualTo(DataPoint.DEVICE_ID, dataPointQueryVO.getDeviceId())
            .andEqualTo(DataPoint.DATA_STREAM_ID, dataPointQueryVO.getDataStreamId());
    dataPointExample.orderBy(DataPoint.DATA_POINT_TIMESTAMP).desc();
    List<DataPoint> dataPoints = super.selectByExampleAndRowBounds(dataPointExample, new RowBounds(1, 1));
    if (CollectionUtils.isEmpty(dataPoints)) {
        return null;
    }
    return dataPoints.get(0);
}
 
Example 29
Source Project: unimall   Source File: RoleServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Page<RoleDO> list(String name, Integer page, Integer limit, Long adminId) throws ServiceException {
    Wrapper<RoleDO> wrapper = new EntityWrapper<RoleDO>();
    if (!StringUtils.isEmpty(name)) {
        wrapper.like("name", name);
    }
    List<RoleDO> roleDOS = roleMapper.selectPage(new RowBounds((page - 1) * limit, limit), wrapper);
    Integer count = roleMapper.selectCount(wrapper);
    return new Page<RoleDO>(roleDOS, page, limit, count);
}
 
Example 30
Source Project: mybaties   Source File: DefaultResultSetHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void handleRowValues(ResultSetWrapper rsw, ResultMap resultMap, ResultHandler resultHandler, RowBounds rowBounds, ResultMapping parentMapping) throws SQLException {
  if (resultMap.hasNestedResultMaps()) {
    ensureNoRowBounds();
    checkResultHandler();
    handleRowValuesForNestedResultMap(rsw, resultMap, resultHandler, rowBounds, parentMapping);
  } else {
    handleRowValuesForSimpleResultMap(rsw, resultMap, resultHandler, rowBounds, parentMapping);
  }
}