Java Code Examples for net.sf.jsqlparser.statement.select.PlainSelect#getFromItem()

The following examples show how to use net.sf.jsqlparser.statement.select.PlainSelect#getFromItem() . 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: SqlBuilder.java    From das with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 2
Source File: SelectVisitorImpl.java    From DataPermissionHelper with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(PlainSelect plainSelect) {

    // 访问 select
    if (plainSelect.getSelectItems() != null) {
        for (SelectItem item : plainSelect.getSelectItems()) {
            item.accept(new SelectItemVisitorImpl());
        }
    }

    // 访问from
    FromItem fromItem = plainSelect.getFromItem();
    FromItemVisitorImpl fromItemVisitorImpl = new FromItemVisitorImpl();
    fromItem.accept(fromItemVisitorImpl);

    if (fromItemVisitorImpl.getSubSelect() != null) {
        plainSelect.setFromItem(fromItemVisitorImpl.getSubSelect());
        if (!DPHelper.getChangeTable()) {
            DPHelper.setChangeTable(true);
        }
    }

    // 访问where
    if (plainSelect.getWhere() != null) {
        plainSelect.getWhere().accept(new ExpressionVisitorImpl());
    }

    // 访问join
    if (plainSelect.getJoins() != null) {
        for (Join join : plainSelect.getJoins()) {
            FromItemVisitorImpl fromItemVisitorImplTemp = new FromItemVisitorImpl();
            join.getRightItem().accept(fromItemVisitorImplTemp);
            if (fromItemVisitorImplTemp.getSubSelect() != null) {
                join.setRightItem(fromItemVisitorImplTemp.getSubSelect());
                if (!DPHelper.getChangeTable()) {
                    DPHelper.setChangeTable(true);
                }
            }
        }
    }

    // 访问 order by
    if (plainSelect.getOrderByElements() != null) {
        for (OrderByElement orderByElement : plainSelect
                .getOrderByElements()) {
            orderByElement.getExpression().accept(
                    new ExpressionVisitorImpl());
        }
    }

    // 访问group by having
    if (plainSelect.getHaving() != null) {
        plainSelect.getHaving().accept(new ExpressionVisitorImpl());
    }

}
 
Example 3
Source File: SqlBuilder.java    From dal with Apache License 2.0 4 votes vote down vote up
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();
}