本文整理汇总了Java中org.apache.ibatis.session.RowBounds.DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java RowBounds.DEFAULT属性的具体用法?Java RowBounds.DEFAULT怎么用?Java RowBounds.DEFAULT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.ibatis.session.RowBounds
的用法示例。
在下文中一共展示了RowBounds.DEFAULT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
/**
* Physical Pagination Interceptor for all the queries with parameter {@link org.apache.ibatis.session.RowBounds}
*/
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget());
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
// 先判断是不是SELECT操作
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
return invocation.proceed();
}
RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
/* 不需要分页的场合 */
if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
return invocation.proceed();
}
BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
String originalSql = boundSql.getSql();
Connection connection = (Connection) invocation.getArgs()[0];
DBType dbType = JdbcUtils.getDbType(connection.getMetaData().getURL());
if (rowBounds instanceof Pagination) {
Pagination page = (Pagination) rowBounds;
if (page.isSearchCount()) {
this.queryTotal(JsqlParserUtils.jsqlparserCount(originalSql), mappedStatement, boundSql, page, connection);
if (page.getTotal() <= 0) {
return invocation.proceed();
}
}
originalSql = DialectFactory.buildPaginationSql(page, originalSql, dbType, null);
} else {
// support physical Pagination for RowBounds
originalSql = DialectFactory.buildPaginationSql(rowBounds, originalSql, dbType, null);
}
/*
* <p> 禁用内存分页 </p> <p> 内存分页会查询所有结果出来处理(这个很吓人的),如果结果变化频繁这个数据还会不准。</p>
*/
metaStatementHandler.setValue("delegate.boundSql.sql", originalSql);
metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
return invocation.proceed();
}
示例2: intercept
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler)invocation.getTarget();
MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(), new DefaultReflectorFactory());
RowBounds rowBounds = (RowBounds)metaStatementHandler.getValue("delegate.rowBounds");
if(rowBounds == null || rowBounds == RowBounds.DEFAULT){
return invocation.proceed();
}
if(dialect == null){
Configuration configuration = (Configuration) metaStatementHandler.getValue("delegate.configuration");
Dialect.Type databaseType = null;
String d = configuration.getVariables().getProperty("dialect");
if(d == null || d.trim().equals("")){
throw new IllegalStateException("No property named with 'dialect' defined in mybatis configuration xml file.");
}
try {
databaseType = Dialect.Type.valueOf(d);
} catch (Exception e) {
throw new IllegalStateException(String.format("No such dialect enum defined in class %s.", Dialect.Type.class));
}
switch (databaseType) {
case MYSQL: // MySQL分页
dialect = new MySQLDialect();
break;
case ORACLE: // Oracle分页
dialect = new OracleDialect();
break;
}
if(dialect == null){
throw new IllegalStateException(String.format("No %s dialect found!", databaseType));
}
}
String originalSql = metaStatementHandler.getValue("delegate.boundSql.sql").toString();
metaStatementHandler.setValue("delegate.boundSql.sql", dialect.getLimitSql(originalSql, rowBounds.getOffset(), rowBounds.getLimit()));
metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
return invocation.proceed();
}