List of usage examples for org.apache.ibatis.session RowBounds RowBounds
public RowBounds(int offset, int limit)
From source file:com.vicky.common.utils.service.MybatisBaseService.java
/** * ??/*from ww w .ja va 2 s .c o m*/ * <p> * @param page ? * @param conditions ? * @param orders ?? * @return List? * @throws java.lang.Exception */ public List<T> list(Page page, List<Condition> conditions, List<Order> orders) throws Exception { // RowBounds rowBounds = new RowBounds(page.getPageOffset(), page.getPageSize()); //? Example example = new Example(this.getTClass()); Example.Criteria criteria = example.createCriteria(); for (Condition condition : conditions) { switch (condition.getCondition()) { case Condition.EQUAL: criteria.andEqualTo(condition.getProperty(), condition.getValue()); break; case Condition.NOTEQUAL: criteria.andNotEqualTo(condition.getProperty(), condition.getValue()); break; case Condition.GREATER_THAN: criteria.andGreaterThan(condition.getProperty(), condition.getValue()); break; case Condition.GREATER_THAN_OR_EQUAL: criteria.andGreaterThanOrEqualTo(condition.getProperty(), condition.getValue()); break; case Condition.LESS_THAN: criteria.andLessThan(condition.getProperty(), condition.getValue()); break; case Condition.LESS_THAN_OR_EQUAL: criteria.andLessThanOrEqualTo(condition.getProperty(), condition.getValue()); break; case Condition.LIKEC: criteria.andLike(condition.getProperty(), "%" + (String) condition.getValue() + "%"); break; case Condition.LIKER: criteria.andLike(condition.getProperty(), (String) condition.getValue()); break; case Condition.NOTLIKEC: criteria.andNotLike(condition.getProperty(), "%" + (String) condition.getValue() + "%"); break; case Condition.NOTLIKER: criteria.andNotLike(condition.getProperty(), (String) condition.getValue()); break; case Condition.IN: criteria.andIn(condition.getProperty(), condition.getInSet()); break; case Condition.NOTIN: criteria.andNotIn(condition.getProperty(), condition.getNotInSet()); break; case Condition.NULL: criteria.andIsNull(condition.getProperty()); break; case Condition.NOTNULL: criteria.andIsNotNull(condition.getProperty()); break; default: throw new StatusMsgException("???" + condition.getCondition()); } } for (Order order : orders) { if (order.getType().equals(Order.ASC)) { example.orderBy(order.getProperty()).asc(); } else { example.orderBy(order.getProperty()).desc(); } } return this.getMapper().selectByExampleAndRowBounds(example, rowBounds); }
From source file:com.vicky.modules.collectmgr.controller.CollectUserController.java
@RequestMapping("getList") @ResponseBody/* w ww . ja va 2 s. com*/ public Map<String, Object> getList(String username, Integer pageIndex, Integer pageSize) { Map<String, Object> map = new HashMap<>(); int index = Page.DEFAULT_PAGE_INDEX; int limit = Page.DEFAULT_PAGE_SIZE; if (pageIndex != null) { index = pageIndex; } if (pageSize != null) { limit = pageSize; } RowBounds rowBounds = new RowBounds((index - 1) * limit, limit); int total = this.collectUserService.getListCount(username); List<Map<String, Object>> maps = this.collectUserService.getList(username, rowBounds); map.put(Page.TOTAL_KEY, total); map.put(Page.DATA_KEY, maps); return map; }
From source file:com.vicky.modules.commentmgr.controller.CommentFloorController.java
@RequestMapping("getList") @ResponseBody/*from w w w. ja v a2 s.co m*/ public Map<String, Object> getList(String videoId, Integer pageIndex, Integer pageSize) { Map<String, Object> map = new HashMap<>(); int index = Page.DEFAULT_PAGE_INDEX; int limit = Page.DEFAULT_PAGE_SIZE; if (pageIndex != null) { index = pageIndex; } if (pageSize != null) { limit = pageSize; } RowBounds rowBounds = new RowBounds((index - 1) * limit, limit); int total = this.floorService.getListCount(videoId); List<Map<String, Object>> maps = this.floorService.getList(videoId, rowBounds); map.put(Page.TOTAL_KEY, total); map.put(Page.DATA_KEY, maps); return map; }
From source file:com.wsun.seap.dao.interceptor.PaginationInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { // ??/*from w ww . java 2 s .c om*/ final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX]; // ?SQL // ?? Object parameterObj = invocation.getArgs()[PARAMETER_INDEX]; // ??QueryParam Object parameter; if (parameterObj instanceof QueryParam) { // ?QueryParam,??Map parameter = ((QueryParam) parameterObj).getAllParam(); invocation.getArgs()[PARAMETER_INDEX] = parameter; } else { parameter = parameterObj; } BoundSql boundSql = mappedStatement.getBoundSql(parameter); if (StringUtils.isBlank(boundSql.getSql())) { return null; } // ??RowBounds RowBounds rowBounds = (RowBounds) invocation.getArgs()[ROWBOUNDS_INDEX]; // if (rowBounds != null && rowBounds != RowBounds.DEFAULT) { String originalSql = boundSql.getSql().trim(); // ??sql String pageSql = dialect.getLimitString(originalSql, rowBounds.getOffset(), rowBounds.getLimit()); invocation.getArgs()[ROWBOUNDS_INDEX] = new RowBounds(RowBounds.NO_ROW_OFFSET, RowBounds.NO_ROW_LIMIT); BoundSql newBoundSql = new BoundSql(mappedStatement.getConfiguration(), pageSql, boundSql.getParameterMappings(), boundSql.getParameterObject()); MappedStatement newMs = copyFromMappedStatement(mappedStatement, new BoundSqlSqlSource(newBoundSql)); invocation.getArgs()[MAPPED_STATEMENT_INDEX] = newMs; } return invocation.proceed(); }
From source file:egovframework.rte.psl.dataaccess.EgovAbstractMapper.java
License:Apache License
/** * SQL mapping ? .//from w w w . j a va 2 s. com * ( - pageIndex pageSize skipResults, maxResults ibatis ) * * @param queryId - SQL mapping ID * @param parameterObject - SQL mapping ??( ) ? ?( VO ? Map) * @param pageIndex - ? * @param pageSize - ? (pageSize) * * @return List ? - SQL mapping ?? resultType/resultMap ? ? ?( VO ? Map) List */ public List<?> listWithPaging(String queryId, Object parameterObject, int pageIndex, int pageSize) { int skipResults = pageIndex * pageSize; //int maxResults = (pageIndex * pageSize) + pageSize; RowBounds rowBounds = new RowBounds(skipResults, pageSize); return getSqlSession().selectList(queryId, parameterObject, rowBounds); }
From source file:jp.terasoluna.fw.batch.util.JobUtil.java
License:Apache License
/** * <h6>?.</h6>/*from w w w .ja v a 2 s.c o m*/ * @param jobAppCd * @param curAppStatusList ??? * @param systemDao DAO * @param beginIndex ?? * @param maxCount ?? * @return */ public static List<BatchJobListResult> selectJobList(String jobAppCd, List<String> curAppStatusList, SystemDao systemDao, int beginIndex, int maxCount) { BatchJobListParam param = new BatchJobListParam(); // param.setJobAppCd(jobAppCd); // ?? if (curAppStatusList != null) { param.setCurAppStatusList(curAppStatusList); } List<BatchJobListResult> result = null; try { if (beginIndex == -1 || maxCount == -1) { result = systemDao.selectJobList(param); } else { RowBounds rowBounds = new RowBounds(beginIndex, maxCount); result = systemDao.selectJobList(rowBounds, param); } } catch (Exception e) { throw new BatchException(LOGGER.getLogMessage(LogId.EAL025039), e); } return result; }
From source file:mbg.test.mb3.annotated.flat.FlatJava5Test.java
License:Apache License
@Test public void testPKFieldsSelectByExampleBetweenWithRowbounds() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {/* w w w .ja v a 2s.c om*/ PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class); Pkfields record = new Pkfields(); record.setFirstname("Fred"); record.setLastname("Flintstone"); record.setId1(1); record.setId2(1); mapper.insert(record); record = new Pkfields(); record.setFirstname("Wilma"); record.setLastname("Flintstone"); record.setId1(1); record.setId2(2); mapper.insert(record); record = new Pkfields(); record.setFirstname("Pebbles"); record.setLastname("Flintstone"); record.setId1(1); record.setId2(3); mapper.insert(record); record = new Pkfields(); record.setFirstname("Barney"); record.setLastname("Rubble"); record.setId1(2); record.setId2(1); mapper.insert(record); record = new Pkfields(); record.setFirstname("Betty"); record.setLastname("Rubble"); record.setId1(2); record.setId2(2); mapper.insert(record); record = new Pkfields(); record.setFirstname("Bamm Bamm"); record.setLastname("Rubble"); record.setId1(2); record.setId2(3); mapper.insert(record); PkfieldsExample example = new PkfieldsExample(); example.createCriteria().andId2Between(1, 3); example.setOrderByClause("ID1, ID2"); RowBounds rb = new RowBounds(2, 3); List<Pkfields> answer = mapper.selectByExampleWithRowbounds(example, rb); assertEquals(3, answer.size()); assertEquals("Pebbles", answer.get(0).getFirstname()); assertEquals("Barney", answer.get(1).getFirstname()); assertEquals("Betty", answer.get(2).getFirstname()); } finally { sqlSession.close(); } }
From source file:mbg.test.mb3.dsql.miscellaneous.MiscellaneousTest.java
License:Apache License
@Test public void testRegexRenameRowbounds() { SqlSession sqlSession = sqlSessionFactory.openSession(); try {// w ww .j a v a 2 s. c om RegexrenameMapper mapper = sqlSession.getMapper(RegexrenameMapper.class); Regexrename record = new Regexrename(); record.setId(1); record.setAddress("123 Main Street"); record.setName("Fred"); record.setZipCode("99999"); mapper.insert(record); record = new Regexrename(); record.setId(2); record.setAddress("234 Elm Street"); record.setName("Barney"); record.setZipCode("99999"); mapper.insert(record); record = new Regexrename(); record.setId(3); record.setAddress("345 Maple Street"); record.setName("Wilma"); record.setZipCode("99999"); mapper.insert(record); record = new Regexrename(); record.setId(4); record.setAddress("456 Oak Street"); record.setName("Betty"); record.setZipCode("99999"); mapper.insert(record); RowBounds rowBounds = new RowBounds(0, 2); List<Regexrename> records = mapper.selectByExample(rowBounds).orderBy(regexrename.id).build().execute(); assertEquals(2, records.size()); assertEquals(records.get(0).getId().intValue(), 1); assertEquals(records.get(1).getId().intValue(), 2); rowBounds = new RowBounds(2, 4); records = mapper.selectByExample(rowBounds).orderBy(regexrename.id).build().execute(); assertEquals(2, records.size()); assertEquals(records.get(0).getId().intValue(), 3); assertEquals(records.get(1).getId().intValue(), 4); } finally { sqlSession.close(); } }
From source file:net.sourceforge.guacamole.net.auth.mariadb.service.ConnectionService.java
License:Open Source License
/** * Retrieves the history of the connection having the given ID. * * @param connectionID The ID of the connection to retrieve the history of. * @return A list of MariaDBConnectionRecord documenting the history of this * connection./*from ww w .j ava 2 s . c o m*/ */ public List<MariaDBConnectionRecord> retrieveHistory(int connectionID) { // Retrieve history records relating to given connection ID ConnectionHistoryExample example = new ConnectionHistoryExample(); example.createCriteria().andConnection_idEqualTo(connectionID); // We want to return the newest records first example.setOrderByClause("start_date DESC"); // Set the maximum number of history records returned to 100 RowBounds rowBounds = new RowBounds(0, 100); // Retrieve all connection history entries List<ConnectionHistory> connectionHistories = connectionHistoryDAO.selectByExampleWithRowbounds(example, rowBounds); // Convert history entries to connection records List<MariaDBConnectionRecord> connectionRecords = new ArrayList<MariaDBConnectionRecord>(); Set<Integer> userIDSet = new HashSet<Integer>(); for (ConnectionHistory history : connectionHistories) { userIDSet.add(history.getUser_id()); } // Determine whether connection is currently active int user_count = activeConnectionMap.getCurrentUserCount(connectionID); // Get all the usernames for the users who are in the history Map<Integer, String> usernameMap = userService.retrieveUsernames(userIDSet); // Create the new ConnectionRecords for (ConnectionHistory history : connectionHistories) { Date startDate = history.getStart_date(); Date endDate = history.getEnd_date(); String username = usernameMap.get(history.getUser_id()); // If there are active users, list the top N not-ended connections // as active (best guess) MariaDBConnectionRecord connectionRecord; if (user_count > 0 && endDate == null) { connectionRecord = new MariaDBConnectionRecord(startDate, endDate, username, true); user_count--; } // If no active users, or end date is recorded, connection is not // active. else connectionRecord = new MariaDBConnectionRecord(startDate, endDate, username, false); connectionRecords.add(connectionRecord); } return connectionRecords; }
From source file:net.sourceforge.guacamole.net.auth.mssql.service.ConnectionService.java
License:Open Source License
/** * Retrieves the history of the connection having the given ID. * * @param connectionID The ID of the connection to retrieve the history of. * @return A list of MSSQLConnectionRecord documenting the history of this * connection.// w ww .ja v a 2s. c o m */ public List<MSSQLConnectionRecord> retrieveHistory(int connectionID) { // Retrieve history records relating to given connection ID ConnectionHistoryExample example = new ConnectionHistoryExample(); example.createCriteria().andConnection_idEqualTo(connectionID); // We want to return the newest records first example.setOrderByClause("start_date DESC"); // Set the maximum number of history records returned to 100 RowBounds rowBounds = new RowBounds(0, 100); // Retrieve all connection history entries List<ConnectionHistory> connectionHistories = connectionHistoryDAO.selectByExampleWithRowbounds(example, rowBounds); // Convert history entries to connection records List<MSSQLConnectionRecord> connectionRecords = new ArrayList<MSSQLConnectionRecord>(); Set<Integer> userIDSet = new HashSet<Integer>(); for (ConnectionHistory history : connectionHistories) { userIDSet.add(history.getUser_id()); } // Determine whether connection is currently active int user_count = activeConnectionMap.getCurrentUserCount(connectionID); // Get all the usernames for the users who are in the history Map<Integer, String> usernameMap = userService.retrieveUsernames(userIDSet); // Create the new ConnectionRecords for (ConnectionHistory history : connectionHistories) { Date startDate = history.getStart_date(); Date endDate = history.getEnd_date(); String username = usernameMap.get(history.getUser_id()); // If there are active users, list the top N not-ended connections // as active (best guess) MSSQLConnectionRecord connectionRecord; if (user_count > 0 && endDate == null) { connectionRecord = new MSSQLConnectionRecord(startDate, endDate, username, true); user_count--; } // If no active users, or end date is recorded, connection is not // active. else connectionRecord = new MSSQLConnectionRecord(startDate, endDate, username, false); connectionRecords.add(connectionRecord); } return connectionRecords; }