List of usage examples for org.apache.ibatis.session RowBounds RowBounds
public RowBounds(int offset, int limit)
From source file:net.sourceforge.guacamole.net.auth.mysql.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 MySQLConnectionRecord documenting the history of this * connection./* w w w. j av a 2 s . c o m*/ */ public List<MySQLConnectionRecord> 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<MySQLConnectionRecord> connectionRecords = new ArrayList<MySQLConnectionRecord>(); 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) MySQLConnectionRecord connectionRecord; if (user_count > 0 && endDate == null) { connectionRecord = new MySQLConnectionRecord(startDate, endDate, username, true); user_count--; } // If no active users, or end date is recorded, connection is not // active. else connectionRecord = new MySQLConnectionRecord(startDate, endDate, username, false); connectionRecords.add(connectionRecord); } return connectionRecords; }
From source file:org.activiti.content.engine.impl.persistence.entity.TableDataManagerImpl.java
License:Apache License
@Override @SuppressWarnings("unchecked") public TablePage getTablePage(TablePageQueryImpl tablePageQuery, int firstResult, int maxResults) { TablePage tablePage = new TablePage(); @SuppressWarnings("rawtypes") List tableData = getDbSqlSession().getSqlSession().selectList("selectTableData", tablePageQuery, new RowBounds(firstResult, maxResults)); tablePage.setTableName(tablePageQuery.getTableName()); tablePage.setTotal(getTableCount(tablePageQuery.getTableName())); tablePage.setRows((List<Map<String, Object>>) tableData); tablePage.setFirstResult(firstResult); return tablePage; }
From source file:org.activiti.engine.impl.persistence.db.DbSqlSession.java
License:Apache License
@SuppressWarnings("unchecked") public List selectList(String statement, Object parameter, int offset, int maxResults) { statement = dbSqlSessionFactory.mapStatement(statement); List loadedObjects = sqlSession.selectList(statement, parameter, new RowBounds(offset, maxResults)); return filterLoadedObjects(loadedObjects); }
From source file:org.activiti.impl.persistence.IbatisPersistenceSession.java
License:Apache License
public List<JobImpl> findNextJobsToExecute(int maxJobsPerAcquisition) { Date now = Clock.getCurrentTime(); RowBounds rowBounds = new RowBounds(0, maxJobsPerAcquisition); List<JobImpl> jobs = sqlSession.selectList(statement("selectNextJobsToExecute"), now, rowBounds); if (jobs != null) { loaded.add(jobs);/*from w w w. j av a2 s .c o m*/ } return jobs; }
From source file:org.activiti.impl.persistence.IbatisPersistenceSession.java
License:Apache License
@SuppressWarnings("unchecked") public List<Job> dynamicFindJobs(Map<String, Object> params, Page page) { final String query = "org.activiti.persistence.selectJobByDynamicCriteria"; if (page == null) { return sqlSession.selectList(query, params); } else {/*from ww w .jav a 2 s . c o m*/ return sqlSession.selectList(query, params, new RowBounds(page.getOffset(), page.getMaxResults())); } }
From source file:org.activiti.impl.persistence.IbatisPersistenceSession.java
License:Apache License
@SuppressWarnings("unchecked") public List<Task> dynamicFindTasks(Map<String, Object> params, Page page) { final String query = statement("selectTaskByDynamicCriteria"); if (page == null) { return sqlSession.selectList(query, params); } else {/* w w w. jav a 2s .com*/ return sqlSession.selectList(query, params, new RowBounds(page.getOffset(), page.getMaxResults())); } }
From source file:org.activiti.impl.persistence.IbatisPersistenceSession.java
License:Apache License
@SuppressWarnings("unchecked") public TablePage getTablePage(String tableName, int offset, int maxResults, String sortColumn, SortOrder sortOrder) {// w ww . j av a 2s .c o m TablePage tablePage = new TablePage(); Map<String, String> params = new HashMap<String, String>(); params.put("tableName", tableName); if (sortColumn != null) { params.put("sortColumn", sortColumn); if (sortOrder.equals(SortOrder.ASCENDING)) { params.put("sortOrder", "asc"); } else { params.put("sortOrder", "desc"); } tablePage.setSort(sortColumn); tablePage.setOrder(sortOrder); } List<Map<String, Object>> tableData = (List<Map<String, Object>>) sqlSession .selectList(statement("selectTableData"), params, new RowBounds(offset, maxResults)); tablePage.setTableName(tableName); tablePage.setStart(offset); tablePage.setTotal(getTableCount(tableName)); tablePage.setRows(tableData); return tablePage; }
From source file:org.alfresco.repo.domain.activities.ibatis.ActivityFeedDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w. ja v a 2s.c o m public List<ActivityFeedEntity> selectUserFeedEntries(String feedUserId, String siteId, boolean excludeThisUser, boolean excludeOtherUsers, long minFeedId, int maxFeedSize) throws SQLException { ActivityFeedQueryEntity params = new ActivityFeedQueryEntity(); params.setFeedUserId(feedUserId); if (minFeedId > -1) { params.setMinId(minFeedId); } int rowLimit = maxFeedSize < 0 ? RowBounds.NO_ROW_LIMIT : maxFeedSize; RowBounds rowBounds = new RowBounds(RowBounds.NO_ROW_OFFSET, rowLimit); if (siteId != null) { // given site params.setSiteNetwork(siteId); if (excludeThisUser && excludeOtherUsers) { // effectively NOOP - return empty feed return new ArrayList<ActivityFeedEntity>(0); } if ((!excludeThisUser) && (!excludeOtherUsers)) { // no excludes => everyone => where feed user is me return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser_and_site", params, rowBounds); } else if ((excludeThisUser) && (!excludeOtherUsers)) { // exclude feed user => others => where feed user is me and post user is not me return template.selectList( "alfresco.activities.select.select_activity_feed_for_feeduser_others_and_site", params, rowBounds); } else if ((excludeOtherUsers) && (!excludeThisUser)) { // exclude others => me => where feed user is me and post user is me return template.selectList( "alfresco.activities.select.select_activity_feed_for_feeduser_me_and_site", params, rowBounds); } } else { // all sites if (excludeThisUser && excludeOtherUsers) { // effectively NOOP - return empty feed return new ArrayList<ActivityFeedEntity>(0); } if (!excludeThisUser && !excludeOtherUsers) { // no excludes => everyone => where feed user is me return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser", params, rowBounds); } else if (excludeThisUser) { // exclude feed user => others => where feed user is me and post user is not me return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser_others", params, rowBounds); } else if (excludeOtherUsers) { // exclude others => me => where feed user is me and post user is me return template.selectList("alfresco.activities.select.select_activity_feed_for_feeduser_me", params, rowBounds); } } // belts-and-braces throw new AlfrescoRuntimeException("Unexpected: invalid arguments"); }
From source file:org.alfresco.repo.domain.activities.ibatis.ActivityFeedDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") private List<ActivityFeedEntity> filterByNetwork(String networkId, String siteId, String sql, ActivityFeedQueryEntity params, PagingRequest pagingRequest) { int expectedSkipCount = pagingRequest.getSkipCount(); // +1 to calculate hasMoreItems int expectedMaxItems = (pagingRequest.getMaxItems() == CannedQueryPageDetails.DEFAULT_PAGE_SIZE ? pagingRequest.getMaxItems() : pagingRequest.getMaxItems() + 1); int skipCount = 0; int maxItems = fetchBatchSize; List<ActivityFeedEntity> ret = new LinkedList<ActivityFeedEntity>(); int numMatchingItems = 0; int numAddedItems = 0; boolean skipping = true; List<ActivityFeedEntity> feedEntries = null; // fetch activities in batches of size "maxItems" // iterate through them, filtering out any that don't match the networkId do {/*from w w w. j a v a 2 s .c om*/ RowBounds rowBounds = new RowBounds(skipCount, maxItems); feedEntries = template.selectList(sql, params, rowBounds); Iterator<ActivityFeedEntity> feedEntriesIt = feedEntries.iterator(); while (feedEntriesIt.hasNext() && numAddedItems < expectedMaxItems) { ActivityFeedEntity activityFeedEntry = feedEntriesIt.next(); if (siteId == null) { // note: pending requirements for THOR-224, for now assume all activities are within context of site and filter by current tenant if (!networkId.equals(tenantService.getDomain(activityFeedEntry.getSiteNetwork()))) { continue; } } numMatchingItems++; if (skipping) { if (numMatchingItems > expectedSkipCount) { skipping = false; } else { continue; } } ret.add(activityFeedEntry); numAddedItems++; } skipCount += feedEntries.size(); } while (feedEntries != null && feedEntries.size() > 0 && numAddedItems < expectedMaxItems); return ret; }
From source file:org.alfresco.repo.domain.activities.ibatis.ActivityFeedDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*w w w .ja v a2s. c om*/ public List<ActivityFeedEntity> selectSiteFeedEntries(String siteId, int maxFeedSize) throws SQLException { ActivityFeedQueryEntity params = new ActivityFeedQueryEntity(); params.setSiteNetwork(siteId); int rowLimit = maxFeedSize < 0 ? RowBounds.NO_ROW_LIMIT : maxFeedSize; RowBounds rowBounds = new RowBounds(RowBounds.NO_ROW_OFFSET, rowLimit); // for given site return template.selectList("alfresco.activities.select.select_activity_feed_for_site", params, rowBounds); }