List of usage examples for org.apache.ibatis.session RowBounds DEFAULT
RowBounds DEFAULT
To view the source code for org.apache.ibatis.session RowBounds DEFAULT.
Click Source Link
From source file:com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.java
License:Apache License
private int getKey(String id, final Object parameterObject) throws SQLException { int key = Integer.MIN_VALUE; String selectKeyId = selectKeyIdFor(id); final MappedStatement keyStatement; if (configuration.getMappedStatementNames().contains(selectKeyId)) { keyStatement = configuration.getMappedStatement(selectKeyId); } else {/*from w w w .j a v a2s . co m*/ keyStatement = null; } if (keyStatement != null) { List results = (List) transactionManager.doInTransaction(new TransactionScope() { public Object execute(Transaction transaction) throws SQLException { transaction.setCommitRequired(true); Executor executor = transaction.getExecutor(); return executor.query(keyStatement, parameterObject, RowBounds.DEFAULT, null); } }); try { key = (Integer) ((Map) results.get(0)).values().iterator().next(); } catch (Exception e) { //Ignore...sometimes code sucks. This is a good example. } } try { String property = keyStatement.getResultMaps().get(0).getResultMappings().get(0).getProperty(); SystemMetaObject.forObject(parameterObject).setValue(property, key); } catch (Exception e) { //Ignore...sometimes code sucks. This is a good example. } return key; }
From source file:com.jdonee.framework.util.pagehelper.PageHelper.java
License:Open Source License
/** * Mybatis/* w w w . ja v a 2s. c o m*/ * * @param invocation ? * @return * @throws Throwable */ @Override public Object intercept(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else { // RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; // ? Page page = getPage(rowBounds); // pageSizeZero if (pageSizeZero && page.getPageSize() == 0) { // ? Object result = invocation.proceed(); // ? page.addAll((List) result); // page.setPageNum(1); // ?pageSize=total page.setPageSize(page.size()); // ??total page.setTotal(page.size()); // ?Page - ??? return page; } // ?total??count if (page.isCount()) { BoundSql boundSql = ms.getBoundSql(parameterObject); // ?MappedStatement?qs args[0] = SQLUTIL.getCountMappedStatement(ms, boundSql); // Object result = invocation.proceed(); // page.setTotal((Integer) ((List) result).get(0)); if (page.getTotal() == 0) { return page; } } // pageSize>0pageSize<=0???count if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0) || rowBounds != RowBounds.DEFAULT)) { BoundSql boundSql = ms.getBoundSql(parameterObject); // ?MappedStatement?qs args[0] = SQLUTIL.getPageMappedStatement(ms, boundSql); // parameterObject? args[1] = SQLUTIL.setPageParameter(parameterObject, boundSql, page); // Object result = invocation.proceed(); // ? page.addAll((List) result); } // return page; } }
From source file:com.jeeplus.weixin.common.pagination.PageHelper.java
License:Open Source License
/** * Mybatis/* w ww .ja v a 2 s . c om*/ * * @param invocation * @return * @throws Throwable */ @Override public Object intercept(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else { //RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; BoundSql boundSql = ms.getBoundSql(parameterObject); //? Page page = getPage(rowBounds); //MappedStatement MappedStatement qs = newMappedStatement(ms, new BoundSqlSqlSource(boundSql)); //?MappedStatement?qs? args[0] = qs; MetaObject msObject = forObject(qs); String sql = (String) msObject.getValue(BOUND_SQL); //?total??count if (page.isCount()) { //count - ?sql msObject.setValue(BOUND_SQL, getCountSql(sql)); // Object result = invocation.proceed(); // page.setTotal((Integer) ((List) result).get(0)); } //sql - ?sql msObject.setValue(BOUND_SQL, getPageSql(sql, page)); //?? msObject.setValue("resultMaps", ms.getResultMaps()); // Object result = invocation.proceed(); //? page.addAll((List) result); // return page; } }
From source file:com.klt.utilities.page.PageHelper.java
License:Open Source License
/** * Mybatis/*from w w w . j av a 2s .c om*/ * * @param invocation * @return * @throws Throwable */ @Override public Object intercept(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else { // RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; BoundSql boundSql = ms.getBoundSql(parameterObject); // ? Page page = getPage(rowBounds); // pageSizeZero if (pageSizeZero && page.getPageSize() == 0) { // ? Object result = invocation.proceed(); // ? page.addAll((List) result); // ?pageSize=total page.setPageSize(page.size()); // ??total page.setTotal(page.size()); // ?Page - ??? return page; } // MappedStatement MappedStatement qs = newMappedStatement(ms, new BoundSqlSqlSource(boundSql)); // ?MappedStatement?qs? args[0] = qs; MetaObject msObject = forObject(qs); String sql = (String) msObject.getValue(BOUND_SQL); // ?total??count if (page.isCount()) { // count - ?sql msObject.setValue(BOUND_SQL, getCountSql(sql)); // Object result = invocation.proceed(); // page.setTotal((Integer) ((List) result).get(0)); if (page.getTotal() == 0) { return page; } } // pageSize>0pageSize<=0???count if (page.getPageSize() > 0) { // sql - ?sql msObject.setValue(BOUND_SQL, getPageSql(sql, page)); // ?? msObject.setValue("resultMaps", ms.getResultMaps()); // Object result = invocation.proceed(); // ? page.addAll((List) result); } // return page; } }
From source file:com.linju.framework.pager.SqlUtil.java
License:Open Source License
/** * Mybatis// w w w.j av a2 s. co m * * @param invocation ? * @return * @throws Throwable */ private Object _processPage(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (SqlUtil.getLocalPage() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else { //RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; //? Page page = getPage(rowBounds); //pageSizeZero if ((page.getPageSizeZero() != null && page.getPageSizeZero()) && page.getPageSize() == 0) { //? Object result = invocation.proceed(); //? page.addAll((List) result); // page.setPageNum(1); //?pageSize=total page.setPageSize(page.size()); //??total page.setTotal(page.size()); //?Page - ??? return page; } //?ms MappedStatement ms = (MappedStatement) args[0]; SqlSource sqlSource = ms.getSqlSource(); //?total??count if (page.isCount()) { //?MappedStatement?qs msUtils.processCountMappedStatement(ms, sqlSource, args); // Object result = invocation.proceed(); // page.setTotal((Integer) ((List) result).get(0)); if (page.getTotal() == 0) { return page; } } //pageSize>0pageSize<=0???count if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0) || rowBounds != RowBounds.DEFAULT)) { //?MappedStatement?qs msUtils.processPageMappedStatement(ms, sqlSource, page, args); // Object result = invocation.proceed(); //? page.addAll((List) result); } // return page; } }
From source file:com.luopeng.comm.PageHelper.java
License:Open Source License
/** * Mybatis/*from ww w .j a va 2 s .c o m*/ * * @param invocation ? * @return * @throws Throwable */ public Object intercept(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else { //RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; //? Page page = getPage(rowBounds); //pageSizeZero if (pageSizeZero && page.getPageSize() == 0) { //? Object result = invocation.proceed(); //? page.addAll((List) result); // page.setPageNum(1); //?pageSize=total page.setPageSize(page.size()); //??total page.setTotal(page.size()); //?Page - ??? return page; } //?total??count if (page.isCount()) { BoundSql boundSql = ms.getBoundSql(parameterObject); //?MappedStatement?qs args[0] = SQLUTIL.getCountMappedStatement(ms, boundSql); // Object result = invocation.proceed(); // page.setTotal((Integer) ((List) result).get(0)); if (page.getTotal() == 0) { return page; } } //pageSize>0pageSize<=0???count if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0) || rowBounds != RowBounds.DEFAULT)) { BoundSql boundSql = ms.getBoundSql(parameterObject); //?MappedStatement?qs args[0] = SQLUTIL.getPageMappedStatement(ms, boundSql); //parameterObject? args[1] = SQLUTIL.setPageParameter(parameterObject, boundSql, page); // Object result = invocation.proceed(); //? page.addAll((List) result); } // return page; } }
From source file:com.luxoft.mybatis.splitter.ReusingBatchExecutor.java
License:Apache License
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(); PreparedStatementKey key = new PreparedStatementKey(boundSql.getSql(), ms); StatementData statementData = statementsData.get(key); if (retainExecuteOrder && statementData != null && !key.equals(lastKey)) { statementData = null;//from w w w.j a v a2 s . c o m executeUpTo(key, true); } if (statementData == null) { statementData = unusedStatementData.remove(key); if (statementData == null) { Connection connection = getConnection(ms.getStatementLog()); Statement stmt = handler.prepare(connection); statementData = new StatementData(stmt); } statementsData.put(key, statementData); } lastKey = key; statementData.addParameterObject(parameterObject); handler.parameterize(statementData.getStatement()); handler.batch(statementData.getStatement()); return BATCH_UPDATE_RETURN_VALUE; }
From source file:com.luxoft.mybatis.splitter.UpdateSplitterPlugin.java
License:Apache License
@Override public Object intercept(Invocation invocation) throws Throwable { MappedStatement ms = (MappedStatement) invocation.getArgs()[0]; Object parameterObject = invocation.getArgs()[1]; final Configuration configuration = ms.getConfiguration(); final StatementHandler handler = configuration.newStatementHandler((Executor) invocation.getTarget(), ms, parameterObject, RowBounds.DEFAULT, null, null); final BoundSql boundSql = handler.getBoundSql(); final String sql = boundSql.getSql(); List<String> splitted = splitter.split(sql); int rc = 0;//from w w w . j a va2 s. c om List<ParameterMapping> fullParameterMappings = new ArrayList<ParameterMapping>( boundSql.getParameterMappings()); for (String sqlPart : splitted) { if (skipEmptyStatements && sqlPart.length() == 0) { continue; } int numParams = 0; for (int index = sqlPart.indexOf('?'); index >= 0; index = sqlPart.indexOf('?', index + 1)) { numParams++; } MappedStatement subStatement = subStatements.get(ms); if (subStatement == null) { subStatement = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), new SwitchingSqlSource(configuration), ms.getSqlCommandType()).cache(ms.getCache()) .databaseId(ms.getDatabaseId()).fetchSize(ms.getFetchSize()) .timeout(ms.getTimeout()).flushCacheRequired(ms.isFlushCacheRequired()) .useCache(ms.isUseCache()).build(); subStatements.put(ms, subStatement); } List<ParameterMapping> subParameterMappings = fullParameterMappings.subList(0, numParams); ((SwitchingSqlSource) subStatement.getSqlSource()).switchParams(sqlPart, boundSql, new ArrayList<ParameterMapping>(subParameterMappings)); subParameterMappings.clear(); int subRc = (Integer) invocation.getMethod().invoke(invocation.getTarget(), subStatement, parameterObject); if (rc >= 0) { rc = subRc < 0 ? subRc : rc + subRc; } } return rc; }
From source file:com.mybatisX.plugins.PaginationInterceptor.java
License:Apache License
public Object intercept(Invocation invocation) throws Throwable { Object target = invocation.getTarget(); if (target instanceof StatementHandler) { StatementHandler statementHandler = (StatementHandler) target; MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler); RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds"); /* ??? */ if (rowBounds == null || rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); }// ww w . ja va 2 s.c om /* ? */ IDialect dialect = getiDialect(); /* * <p> ? </p> <p> ??????? * </p> */ BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql"); String originalSql = (String) boundSql.getSql(); metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET); metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT); /** * <p> * * </p> * <p> * count * </p> */ if (rowBounds instanceof Pagination) { Pagination page = (Pagination) rowBounds; boolean orderBy = true; if (page.isSearchCount()) { /* * COUNT ORDER BY SQL */ CountOptimize countOptimize = SqlUtils.getCountOptimize(originalSql, page.isOptimizeCount()); orderBy = countOptimize.isOrderBy(); } /* SQL */ String buildSql = SqlUtils.concatOrderBy(originalSql, page, orderBy); originalSql = dialect.buildPaginationSql(buildSql, page.getOffsetCurrent(), page.getSize()); } /** * SQL */ metaStatementHandler.setValue("delegate.boundSql.sql", originalSql); } else { MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; Object parameterObject = null; RowBounds rowBounds = null; if (invocation.getArgs().length > 1) { parameterObject = invocation.getArgs()[1]; rowBounds = (RowBounds) invocation.getArgs()[2]; } /* ??? */ if (rowBounds == null || rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } BoundSql boundSql = mappedStatement.getBoundSql(parameterObject); /* * <p> ? </p> <p> ??????? * </p> */ String originalSql = (String) boundSql.getSql(); /** * <p> * * </p> * <p> * count * </p> */ if (rowBounds instanceof Pagination) { Connection connection = null; try { connection = mappedStatement.getConfiguration().getEnvironment().getDataSource() .getConnection(); Pagination page = (Pagination) rowBounds; if (page.isSearchCount()) { /* * COUNT ORDER BY SQL */ CountOptimize countOptimize = SqlUtils.getCountOptimize(originalSql, page.isOptimizeCount()); page = this.count(countOptimize.getCountSQL(), connection, mappedStatement, boundSql, page); /** 0 */ if (page.getTotal() <= 0) { return invocation.proceed(); } } } finally { IOUtils.closeQuietly(connection); } } } return invocation.proceed(); }
From source file:com.pansoft.common.pageHelper.PageHelper.java
License:Open Source License
/** * Mybatis//from ww w . jav a 2s. co m * * @param invocation * ? * @return * @throws Throwable * */ @Override public Object intercept(Invocation invocation) throws Throwable { final Object[] args = invocation.getArgs(); RowBounds rowBounds = (RowBounds) args[2]; if (LOCAL_PAGE.get() == null && rowBounds == RowBounds.DEFAULT) { return invocation.proceed(); } else { // ?ms MappedStatement ms = (MappedStatement) args[0]; // RowBounds-?Mybatis args[2] = RowBounds.DEFAULT; // ? Page page = getPage(rowBounds); // pageSizeZero if ((page.getPageSizeZero() != null && page.getPageSizeZero()) && page.getPageSize() == 0) { // ? Object result = invocation.proceed(); // ? page.addAll((List) result); // page.setPageNum(1); // ?pageSize=total page.setPageSize(page.size()); // ??total page.setTotal(page.size()); // ?Page - ??? return page; } SqlSource sqlSource = ((MappedStatement) args[0]).getSqlSource(); // ?total??count if (page.isCount()) { // ?MappedStatement?qs SQLUTIL.processCountMappedStatement(ms, sqlSource, args); // Object result = invocation.proceed(); // page.setTotal((Integer) ((List) result).get(0)); if (page.getTotal() == 0) { return page; } } // pageSize>0pageSize<=0???count if (page.getPageSize() > 0 && ((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0) || rowBounds != RowBounds.DEFAULT)) { // ?MappedStatement?qs SQLUTIL.processPageMappedStatement(ms, sqlSource, page, args); // Object result = invocation.proceed(); // ? page.addAll((List) result); } // return page; } }