Java Code Examples for org.apache.ibatis.session.RowBounds#NO_ROW_OFFSET
The following examples show how to use
org.apache.ibatis.session.RowBounds#NO_ROW_OFFSET .
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 File: ActivityPostDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public List<ActivityPostEntity> selectPosts(ActivityPostEntity activityPost, int maxItems) throws SQLException { int rowLimit = maxItems < 0 ? RowBounds.NO_ROW_LIMIT : maxItems; RowBounds rowBounds = new RowBounds(RowBounds.NO_ROW_OFFSET, rowLimit); if ((activityPost.getJobTaskNode() != -1) && (activityPost.getMinId() != -1) && (activityPost.getMaxId() != -1) && (activityPost.getStatus() != null)) { return template.selectList("alfresco.activities.select_activity_posts_by_params", activityPost, rowBounds); } else if (activityPost.getStatus() != null) { return template.selectList("alfresco.activities.select_activity_posts_by_status", activityPost, rowBounds); } else { return new ArrayList<ActivityPostEntity>(0); } }
Example 2
Source File: ActivityFeedDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override 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); }
Example 3
Source File: PagePluging.java From aaden-pay with Apache License 2.0 | 5 votes |
void processIntercept(final Object[] queryArgs) { MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX]; Object parameter = queryArgs[PARAMETER_INDEX]; final RowBounds rowBounds = (RowBounds) queryArgs[ROWBOUNDS_INDEX]; int offset = rowBounds.getOffset(); int limit = rowBounds.getLimit(); if (dialect.supportsLimit() && (offset != RowBounds.NO_ROW_OFFSET || limit != RowBounds.NO_ROW_LIMIT)) { BoundSql boundSql = ms.getBoundSql(parameter); String sql = boundSql.getSql().trim(); if (dialect.supportsLimitOffset()) { sql = dialect.getLimitString(sql, offset, limit); offset = RowBounds.NO_ROW_OFFSET; } else { sql = dialect.getLimitString(sql, 0, limit); } limit = RowBounds.NO_ROW_LIMIT; queryArgs[ROWBOUNDS_INDEX] = new RowBounds(offset, limit); BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(), boundSql.getParameterObject()); for (ParameterMapping mapping : boundSql.getParameterMappings()) { String prop = mapping.getProperty(); if (boundSql.hasAdditionalParameter(prop)) { newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop)); } } MappedStatement newMs = copyFromMappedStatement(ms, new BoundSqlSqlSource(newBoundSql)); queryArgs[MAPPED_STATEMENT_INDEX] = newMs; } }
Example 4
Source File: PageInterceptor.java From Zebra with Apache License 2.0 | 5 votes |
@Override public Object intercept(Invocation invocation) throws Throwable { Object[] args = invocation.getArgs(); Object rowBound = args[2]; MappedStatement ms = (MappedStatement) args[0]; if (rowBound != null) { RowBounds rb = (RowBounds) rowBound; // without pagination if (rb.getOffset() == RowBounds.NO_ROW_OFFSET && rb.getLimit() == RowBounds.NO_ROW_LIMIT) { return invocation.proceed(); } else { BoundSql boundSql = ms.getBoundSql(args[1]); if (rowBound instanceof PageModel) { // physical pagination with PageModel PageModel pageModel = (PageModel) rowBound; Object count = queryCount(invocation, args, ms, boundSql); Object records = queryLimit(invocation, args, ms, boundSql, pageModel); pageModel.setRecordCount((Integer) ((List<?>) count).get(0)); pageModel.setRecords((List<?>) records); return null; } else { // physical pagination with RowBounds return queryLimit(invocation, args, ms, boundSql, rb); } } } else { // without pagination return invocation.proceed(); } }
Example 5
Source File: DefaultResultSetHandler.java From mybaties with Apache License 2.0 | 5 votes |
private void skipRows(ResultSet rs, RowBounds rowBounds) throws SQLException { if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) { if (rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET) { rs.absolute(rowBounds.getOffset()); } } else { for (int i = 0; i < rowBounds.getOffset(); i++) { rs.next(); } } }
Example 6
Source File: DefaultResultSetHandler.java From mybatis with Apache License 2.0 | 5 votes |
private void skipRows(ResultSet rs, RowBounds rowBounds) throws SQLException { if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY) { if (rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET) { rs.absolute(rowBounds.getOffset()); } } else { for (int i = 0; i < rowBounds.getOffset(); i++) { rs.next(); } } }
Example 7
Source File: MybatisUtils.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean isPagingRowBounds(RowBounds rowBounds) { if (rowBounds == null || rowBounds == RowBounds.DEFAULT) { return false; } return rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET || rowBounds.getLimit() != RowBounds.NO_ROW_LIMIT; }
Example 8
Source File: SqlUtils.java From mybatis-boost with MIT License | 4 votes |
public static String appendLimit(String sql, RowBounds rowBounds) { if (rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET || rowBounds.getLimit() != RowBounds.NO_ROW_LIMIT) { sql += " LIMIT " + rowBounds.getOffset() + ", " + rowBounds.getLimit(); } return sql; }
Example 9
Source File: SqlUtils.java From mybatis-boost with MIT License | 4 votes |
public static String appendLimitOffset(String sql, RowBounds rowBounds) { if (rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET || rowBounds.getLimit() != RowBounds.NO_ROW_LIMIT) { sql += " LIMIT " + rowBounds.getLimit() + " OFFSET " + rowBounds.getOffset(); } return sql; }
Example 10
Source File: ActivityFeedDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @Override 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"); }
Example 11
Source File: OffsetLimitInterceptor.java From AsuraFramework with Apache License 2.0 | 4 votes |
public Object intercept(final Invocation invocation) throws Throwable { final Executor executor = (Executor) invocation.getTarget(); final Object[] queryArgs = invocation.getArgs(); final MappedStatement ms = (MappedStatement)queryArgs[MAPPED_STATEMENT_INDEX]; final Object parameter = queryArgs[PARAMETER_INDEX]; final RowBounds rowBounds = (RowBounds)queryArgs[ROWBOUNDS_INDEX]; final PageBounds pageBounds = new PageBounds(rowBounds); if(pageBounds.getOffset() == RowBounds.NO_ROW_OFFSET && pageBounds.getLimit() == RowBounds.NO_ROW_LIMIT && pageBounds.getOrders().isEmpty()){ return invocation.proceed(); } final Dialect dialect; try { Class clazz = Class.forName(dialectClass); Constructor constructor = clazz.getConstructor(MappedStatement.class, Object.class, PageBounds.class); dialect = (Dialect)constructor.newInstance(new Object[]{ms, parameter, pageBounds}); } catch (Exception e) { throw new ClassNotFoundException("Cannot create dialect instance: "+dialectClass,e); } final BoundSql boundSql = ms.getBoundSql(parameter); queryArgs[MAPPED_STATEMENT_INDEX] = copyFromNewSql(ms,boundSql,dialect.getPageSQL(), dialect.getParameterMappings(), dialect.getParameterObject()); queryArgs[PARAMETER_INDEX] = dialect.getParameterObject(); queryArgs[ROWBOUNDS_INDEX] = new RowBounds(RowBounds.NO_ROW_OFFSET,RowBounds.NO_ROW_LIMIT); Boolean async = pageBounds.getAsyncTotalCount() == null ? asyncTotalCount : pageBounds.getAsyncTotalCount(); Future<List> listFuture = call(new Callable<List>() { public List call() throws Exception { return (List)invocation.proceed(); } }, async); if(pageBounds.isContainsTotalCount()){ Callable<Paginator> countTask = new Callable() { public Object call() throws Exception { Integer count; Cache cache = ms.getCache(); if(cache != null && ms.isUseCache() && ms.getConfiguration().isCacheEnabled()){ CacheKey cacheKey = executor.createCacheKey(ms,parameter,new PageBounds(),copyFromBoundSql(ms,boundSql,dialect.getCountSQL(), boundSql.getParameterMappings(), boundSql.getParameterObject())); count = (Integer)cache.getObject(cacheKey); if(count == null){ count = SQLHelp.getCount(ms,executor.getTransaction(),parameter,boundSql,dialect); cache.putObject(cacheKey, count); } }else{ count = SQLHelp.getCount(ms,executor.getTransaction(),parameter,boundSql,dialect); } return new Paginator(pageBounds.getPage(), pageBounds.getLimit(), count); } }; Future<Paginator> countFutrue = call(countTask, async); return new PageList(listFuture.get(),countFutrue.get()); } return listFuture.get(); }
Example 12
Source File: PaginationInterceptor.java From Shop-for-JavaWeb with MIT License | 4 votes |
@Override public Object intercept(Invocation invocation) throws Throwable { final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; // //拦截需要分页的SQL //// if (mappedStatement.getId().matches(_SQL_PATTERN)) { // if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(), _SQL_PATTERN) != -1) { Object parameter = invocation.getArgs()[1]; BoundSql boundSql = mappedStatement.getBoundSql(parameter); Object parameterObject = boundSql.getParameterObject(); //获取分页参数对象 Page<Object> page = null; if (parameterObject != null) { page = convertParameter(parameterObject, page); } //如果设置了分页对象,则进行分页 if (page != null && page.getPageSize() != -1) { if (StringUtils.isBlank(boundSql.getSql())){ return null; } String originalSql = boundSql.getSql().trim(); //得到总记录数 page.setCount(SQLHelper.getCount(originalSql, null, mappedStatement, parameterObject, boundSql, log)); //分页查询 本地化对象 修改数据库注意修改实现 String pageSql = SQLHelper.generatePageSql(originalSql, page, DIALECT); // if (log.isDebugEnabled()) { // log.debug("PAGE SQL:" + StringUtils.replace(pageSql, "\n", "")); // } invocation.getArgs()[2] = 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()[0] = newMs; } // } return invocation.proceed(); }
Example 13
Source File: DefaultResultSetHandler.java From mybaties with Apache License 2.0 | 4 votes |
private void ensureNoRowBounds() { if (configuration.isSafeRowBoundsEnabled() && rowBounds != null && (rowBounds.getLimit() < RowBounds.NO_ROW_LIMIT || rowBounds.getOffset() > RowBounds.NO_ROW_OFFSET)) { throw new ExecutorException("Mapped Statements with nested result mappings cannot be safely constrained by RowBounds. " + "Use safeRowBoundsEnabled=false setting to bypass this check."); } }
Example 14
Source File: DefaultResultSetHandler.java From mybatis with Apache License 2.0 | 4 votes |
private void ensureNoRowBounds() { if (configuration.isSafeRowBoundsEnabled() && rowBounds != null && (rowBounds.getLimit() < RowBounds.NO_ROW_LIMIT || rowBounds.getOffset() > RowBounds.NO_ROW_OFFSET)) { throw new ExecutorException("Mapped Statements with nested result mappings cannot be safely constrained by RowBounds. " + "Use safeRowBoundsEnabled=false setting to bypass this check."); } }