当前位置: 首页>>代码示例>>Java>>正文


Java RowBounds.DEFAULT属性代码示例

本文整理汇总了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();
  }
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:42,代码来源:PaginationInterceptor.java

示例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(); 
}
 
开发者ID:penggle,项目名称:xproject,代码行数:38,代码来源:PaginationInterceptor.java


注:本文中的org.apache.ibatis.session.RowBounds.DEFAULT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。