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


Java PlainSelect.getDistinct方法代码示例

本文整理汇总了Java中net.sf.jsqlparser.statement.select.PlainSelect.getDistinct方法的典型用法代码示例。如果您正苦于以下问题:Java PlainSelect.getDistinct方法的具体用法?Java PlainSelect.getDistinct怎么用?Java PlainSelect.getDistinct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.jsqlparser.statement.select.PlainSelect的用法示例。


在下文中一共展示了PlainSelect.getDistinct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sqlCountOptimize

import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
/**
 * 获取select的count语句
 *
 * @param originalSql
 *            selectSQL
 * @return
 */
public static String sqlCountOptimize(String originalSql) {
    Assert.hasLength(originalSql);
    String sqlCount;
    try {
        Select selectStatement = (Select) CCJSqlParserUtil.parse(originalSql);
        PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
        Distinct distinct = plainSelect.getDistinct();
        List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
        // 优化Order by
        List<OrderByElement> orderBy = plainSelect.getOrderByElements();
        // 添加包含groupby 不去除orderby
        if (CollectionUtils.isEmpty(groupBy) && CollectionUtils.isNotEmpty(orderBy)) {
            plainSelect.setOrderByElements(null);
        }
        if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
            return String.format(SQL_BASE_COUNT, selectStatement.toString());
        }
        List<SelectItem> selectCount = countSelectItem();
        plainSelect.setSelectItems(selectCount);
        sqlCount = selectStatement.toString();
    } catch (Exception e) {
        sqlCount = String.format(SQL_BASE_COUNT, originalSql);
    }
    return sqlCount;
}
 
开发者ID:baomidou,项目名称:hibernate-plus,代码行数:33,代码来源:SqlUtils.java

示例2: jsqlparserCount

import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
/**
 * jsqlparser方式获取select的count语句
 *
 * @param originalSql selectSQL
 * @return
 */
public static String jsqlparserCount(String originalSql) {
    String sqlCount;
    try {
        Select selectStatement = (Select) CCJSqlParserUtil.parse(originalSql);
        PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
        Distinct distinct = plainSelect.getDistinct();
        List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
        // 优化Order by
        List<OrderByElement> orderBy = plainSelect.getOrderByElements();
        // 添加包含groupby 不去除orderby
        if (CollectionUtils.isEmpty(groupBy) && CollectionUtils.isNotEmpty(orderBy)) {
            plainSelect.setOrderByElements(null);
        }
        // 包含 distinct、groupBy不优化
        if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
            sqlCount = String.format(SqlUtils.SQL_BASE_COUNT, selectStatement.toString());
            return sqlCount;
        }
        List<SelectItem> selectCount = countSelectItem();
        plainSelect.setSelectItems(selectCount);
        sqlCount = selectStatement.toString();
    } catch (Exception e) {
        sqlCount = String.format(SqlUtils.SQL_BASE_COUNT, originalSql);
    }
    return sqlCount;
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:33,代码来源:JsqlParserUtils.java

示例3: visit

import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
@Override
public void visit(PlainSelect plainSelect) {
    if (plainSelect.getDistinct() != null && plainSelect.getDistinct().getOnSelectItems() != null) {
        plainSelect.getDistinct().getOnSelectItems().forEach(s -> s.accept(this));
    }
    if (plainSelect.getFromItem() != null) {
        plainSelect.getFromItem().accept(this);
    }
    if (plainSelect.getGroupByColumnReferences() != null) {
        plainSelect.getGroupByColumnReferences().forEach(s -> s.accept(this));
    }
    if (plainSelect.getHaving() != null) {
        plainSelect.getHaving().accept(this);
    }
    if (plainSelect.getJoins() != null) {
        plainSelect.getJoins().forEach(
            j -> {
                visitJoin(j);
            }
        );
    }
    if (plainSelect.getOrderByElements() != null) {
        plainSelect.getOrderByElements().forEach(s -> s.accept(this));
    }
    if (plainSelect.getSelectItems() != null) {
        plainSelect.getSelectItems().forEach(s -> s.accept(this));
    }
    if (plainSelect.getTop() != null) {
        plainSelect.getTop().getExpression().accept(this);
    }
    if (plainSelect.getWhere() != null) {
        plainSelect.getWhere().accept(this);
    }
    if (plainSelect.getLimit() != null) {
        visitLimit(plainSelect.getLimit());
    }

}
 
开发者ID:diennea,项目名称:herddb,代码行数:39,代码来源:JdbcQueryRewriter.java

示例4: optimizeSql

import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
@Override
public SqlInfo optimizeSql(MetaObject metaObject, String sql) {
    if (logger.isDebugEnabled()) {
        logger.debug(" JsqlParserCountOptimize sql=" + sql);
    }
    SqlInfo sqlInfo = SqlInfo.newInstance();
    try {
        Select selectStatement = (Select) CCJSqlParserUtil.parse(sql);
        PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
        Distinct distinct = plainSelect.getDistinct();
        List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
        List<OrderByElement> orderBy = plainSelect.getOrderByElements();

        // 添加包含groupBy 不去除orderBy
        if (CollectionUtils.isEmpty(groupBy) && CollectionUtils.isNotEmpty(orderBy)) {
            plainSelect.setOrderByElements(null);
            sqlInfo.setOrderBy(false);
        }
        //#95 Github, selectItems contains #{} ${}, which will be translated to ?, and it may be in a function: power(#{myInt},2)
        for (SelectItem item : plainSelect.getSelectItems()) {
            if (item.toString().contains("?")) {
                sqlInfo.setSql(String.format(SqlUtils.SQL_BASE_COUNT, selectStatement.toString()));
                return sqlInfo;
            }
        }
        // 包含 distinct、groupBy不优化
        if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
            sqlInfo.setSql(String.format(SqlUtils.SQL_BASE_COUNT, selectStatement.toString()));
            return sqlInfo;
        }
        // 优化 SQL
        plainSelect.setSelectItems(countSelectItem);
        sqlInfo.setSql(selectStatement.toString());
        return sqlInfo;
    } catch (Throwable e) {
        // 无法优化使用原 SQL
        sqlInfo.setSql(String.format(SqlUtils.SQL_BASE_COUNT, sql));
        return sqlInfo;
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:41,代码来源:JsqlParserCountOptimize.java

示例5: plainSelectToStringAppendWithNoLock

import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
private static String plainSelectToStringAppendWithNoLock(PlainSelect plain) {
    StringBuilder sql = new StringBuilder("SELECT ");
    if (plain.getDistinct() != null)
        sql.append(plain.getDistinct()).append(" ");

    if (plain.getTop() != null)
        sql.append(plain.getTop()).append(" ");

    sql.append(PlainSelect.getStringList(plain.getSelectItems()));
    if (plain.getFromItem() != null) {
        sql.append(" FROM ").append(plain.getFromItem()).append(" WITH (NOLOCK) ");
        if (plain.getJoins() != null) {
            Iterator<Join> it = plain.getJoins().iterator();
            while (it.hasNext()) {
                Join join = it.next();
                if (join.isSimple()) {
                    sql.append(", ").append(join).append(" WITH (NOLOCK) ");
                } else {
                    String temp = join.toString().replace(join.getRightItem().toString(),
                            join.getRightItem().toString() + " WITH (NOLOCK) ");
                    sql.append(" ").append(temp);
                }
            }
        }

        if (plain.getWhere() != null)
            sql.append(" WHERE ").append(plain.getWhere());

        if (plain.getOracleHierarchical() != null)
            sql.append(plain.getOracleHierarchical().toString());

        sql.append(PlainSelect.getFormatedList(plain.getGroupByColumnReferences(), "GROUP BY"));
        if (plain.getHaving() != null)
            sql.append(" HAVING ").append(plain.getHaving());

        sql.append(PlainSelect.orderByToString(plain.isOracleSiblings(), plain.getOrderByElements()));
        if (plain.getLimit() != null)
            sql.append(plain.getLimit());

    }
    return sql.toString();
}
 
开发者ID:ctripcorp,项目名称:dal,代码行数:43,代码来源:SqlBuilder.java

示例6: checkContainDistinct

import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
private void checkContainDistinct(PlainSelect plainSelect)
{
   mHasDistinct = (plainSelect.getDistinct() == null) ? false : true;
}
 
开发者ID:obidea,项目名称:semantika,代码行数:5,代码来源:SelectStatementHandler.java


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