net.sf.jsqlparser.statement.select.Select.toString()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中net.sf.jsqlparser.statement.select.Select.toString()方法的一些代码示例,展示了Select.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Select.toString()方法的具体详情如下:
包路径:net.sf.jsqlparser.statement.select.Select
类名称:Select
方法名:toString

Select.toString介绍

暂无

代码示例

代码示例来源:origin: JSQLParser/JSqlParser

@Override
public String toString() {
  return "EXPLAIN " + select.toString();
}

代码示例来源:origin: pagehelper/Mybatis-PageHelper

String pageSql = pageSelect.toString();

代码示例来源:origin: codingapi/tx-lcn

public boolean isxLock() {
  return StringUtils.endsWithIgnoreCase(StringUtils.trimAllWhitespace(this.select.toString()),
      StringUtils.trimAllWhitespace(SqlUtils.FOR_UPDATE));
}

代码示例来源:origin: codingapi/tx-lcn

public boolean issLock() {
  return StringUtils.endsWithIgnoreCase(StringUtils.trimAllWhitespace(this.select.toString()),
      StringUtils.trimAllWhitespace(SqlUtils.LOCK_IN_SHARE_MODE));
}

代码示例来源:origin: JSQLParser/JSqlParser

@Override
  public String toString() {
    String sql;
    String createOps = PlainSelect.getStringList(createOptionsStrings, false, false);

    sql = "CREATE " + (unlogged ? "UNLOGGED " : "")
        + (!"".equals(createOps) ? createOps + " " : "")
        + "TABLE " + (ifNotExists ? "IF NOT EXISTS " : "") + table;

    if (select != null) {
      sql += " AS " + (selectParenthesis ? "(" : "") + select.toString() + (selectParenthesis ? ")" : "");
    } else {
      sql += " (";

      sql += PlainSelect.getStringList(columnDefinitions, true, false);
      if (indexes != null && !indexes.isEmpty()) {
        sql += ", ";
        sql += PlainSelect.getStringList(indexes);
      }
      sql += ")";
      String options = PlainSelect.getStringList(tableOptionsStrings, false, false);
      if (options != null && options.length() > 0) {
        sql += " " + options;
      }
    }

    return sql;
  }
}

代码示例来源:origin: pagehelper/Mybatis-PageHelper

/**
 * convert to order by sql
 *
 * @param sql
 * @param orderBy
 * @return
 */
public static String converToOrderBySql(String sql, String orderBy) {
  //解析SQL
  Statement stmt = null;
  try {
    stmt = CCJSqlParserUtil.parse(sql);
    Select select = (Select) stmt;
    SelectBody selectBody = select.getSelectBody();
    //处理body-去最外层order by
    List<OrderByElement> orderByElements = extraOrderBy(selectBody);
    String defaultOrderBy = PlainSelect.orderByToString(orderByElements);
    if (defaultOrderBy.indexOf('?') != -1) {
      throw new PageException("原SQL[" + sql + "]中的order by包含参数,因此不能使用OrderBy插件进行修改!");
    }
    //新的sql
    sql = select.toString();
  } catch (Throwable e) {
    throw new PageException("处理排序失败: " + e, e);
  }
  return sql + " order by " + orderBy;
}

代码示例来源:origin: baomidou/mybatis-plus

return sqlInfo.setSql(SqlParserUtils.getOriginalCountSql(selectStatement.toString()));
    return sqlInfo.setSql(SqlParserUtils.getOriginalCountSql(selectStatement.toString()));
  return sqlInfo.setSql(selectStatement.toString());
} catch (Throwable e) {

代码示例来源:origin: pagehelper/Mybatis-PageHelper

String result = select.toString();
return result;

代码示例来源:origin: it.unibz.inf.ontop/ontop-obdalib-core

@Override
public String toString() {
  return selectQuery.toString();
}

代码示例来源:origin: com.intoverflow.booster/booster-core

public static String restructSelect(String sql, Function<Collection<Table>, String> conditionSupplier, Consumer<SelectColumn> columnFilter) throws JSQLParserException {
  Statement stmt = CCJSqlParserUtil.parse(sql);
  Select select = (Select) stmt;
  SelectBody selectBody = select.getSelectBody();
  restruct(selectBody, conditionSupplier, columnFilter);
  return select.toString();
}

代码示例来源:origin: com.github.jsqlparser/jsqlparser

@Override
  public String toString() {
    String sql;
    String createOps = PlainSelect.getStringList(createOptionsStrings, false, false);

    sql = "CREATE " + (unlogged ? "UNLOGGED " : "")
        + (!"".equals(createOps) ? createOps + " " : "")
        + "TABLE " + (ifNotExists ? "IF NOT EXISTS " : "") + table;

    if (select != null) {
      sql += " AS " + (selectParenthesis ? "(" : "") + select.toString() + (selectParenthesis ? ")" : "");
    } else {
      sql += " (";

      sql += PlainSelect.getStringList(columnDefinitions, true, false);
      if (indexes != null && !indexes.isEmpty()) {
        sql += ", ";
        sql += PlainSelect.getStringList(indexes);
      }
      sql += ")";
      String options = PlainSelect.getStringList(tableOptionsStrings, false, false);
      if (options != null && options.length() > 0) {
        sql += " " + options;
      }
    }

    return sql;
  }
}

代码示例来源:origin: tk.mybatis/orderby-helper

/**
 * convert to order by sql
 *
 * @param sql
 * @param orderBy
 * @return
 */
public static String converToOrderBySql(String sql, String orderBy) {
  //解析SQL
  Statement stmt = null;
  try {
    stmt = CCJSqlParserUtil.parse(sql);
    Select select = (Select) stmt;
    SelectBody selectBody = select.getSelectBody();
    //处理body-去最外层order by
    List<OrderByElement> orderByElements = extraOrderBy(selectBody);
    String defaultOrderBy = PlainSelect.orderByToString(orderByElements);
    if (defaultOrderBy.indexOf('?') != -1) {
      throw new RuntimeException("原SQL[" + sql + "]中的order by包含参数,因此不能使用OrderBy插件进行修改!");
    }
    //新的sql
    sql = select.toString();
  } catch (Throwable e) {
    e.printStackTrace();
  }
  return sql + " order by " + orderBy;
}

代码示例来源:origin: abel533/OrderByHelper

/**
 * convert to order by sql
 *
 * @param sql
 * @param orderBy
 * @return
 */
public static String converToOrderBySql(String sql, String orderBy) {
  //解析SQL
  Statement stmt = null;
  try {
    stmt = CCJSqlParserUtil.parse(sql);
    Select select = (Select) stmt;
    SelectBody selectBody = select.getSelectBody();
    //处理body-去最外层order by
    List<OrderByElement> orderByElements = extraOrderBy(selectBody);
    String defaultOrderBy = PlainSelect.orderByToString(orderByElements);
    if (defaultOrderBy.indexOf('?') != -1) {
      throw new RuntimeException("原SQL[" + sql + "]中的order by包含参数,因此不能使用OrderBy插件进行修改!");
    }
    //新的sql
    sql = select.toString();
  } catch (Throwable e) {
    e.printStackTrace();
  }
  return sql + " order by " + orderBy;
}

代码示例来源:origin: ontop/ontop

/**
  The query for obtaining values of parameters is almost the same with the original source query,
  except that we only need to distinct project the columns needed for the template expansion
 */
private static String getTemplateValuesQuery(String sql, List<SelectExpressionItem> templateColumns) throws JSQLParserException {
  Select select = (Select)CCJSqlParserUtil.parse(sql);
  PlainSelect plainSelect = (PlainSelect)select.getSelectBody();
  plainSelect.setDistinct(new Distinct());
  plainSelect.setSelectItems(ImmutableList.copyOf(templateColumns)); // SelectExpressionItem -> SelectItem
  return select.toString();
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-mapping-sql-core

/**
  The query for obtaining values of parameters is almost the same with the original source query,
  except that we only need to distinct project the columns needed for the template expansion
 */
private static String getTemplateValuesQuery(String sql, List<SelectExpressionItem> templateColumns) throws JSQLParserException {
  Select select = (Select)CCJSqlParserUtil.parse(sql);
  PlainSelect plainSelect = (PlainSelect)select.getSelectBody();
  plainSelect.setDistinct(new Distinct());
  plainSelect.setSelectItems(ImmutableList.copyOf(templateColumns)); // SelectExpressionItem -> SelectItem
  return select.toString();
}

代码示例来源:origin: selfly/dexcoder-assistant

public String getCountSql(String sql, Pager pager, String database) {
  //校验是否支持该sql
  this.isSupportedSql(sql);
  if (CACHE.get(sql) != null) {
    return CACHE.get(sql);
  }
  //解析SQL
  Statement stmt;
  try {
    stmt = CCJSqlParserUtil.parse(sql);
  } catch (Throwable e) {
    //无法解析的用一般方法返回count语句
    String countSql = super.getCountSql(sql, pager, database);
    CACHE.put(sql, countSql);
    return countSql;
  }
  Select select = (Select) stmt;
  SelectBody selectBody = select.getSelectBody();
  //处理body-去order by
  processSelectBody(selectBody);
  //处理with-去order by
  processWithItemsList(select.getWithItemsList());
  //处理为count查询
  sqlToCount(select);
  String result = select.toString();
  CACHE.put(sql, result);
  return result;
}

代码示例来源:origin: com.github.pagehelper/pagehelper

/**
 * convert to order by sql
 *
 * @param sql
 * @param orderBy
 * @return
 */
public static String converToOrderBySql(String sql, String orderBy) {
  //解析SQL
  Statement stmt = null;
  try {
    stmt = CCJSqlParserUtil.parse(sql);
    Select select = (Select) stmt;
    SelectBody selectBody = select.getSelectBody();
    //处理body-去最外层order by
    List<OrderByElement> orderByElements = extraOrderBy(selectBody);
    String defaultOrderBy = PlainSelect.orderByToString(orderByElements);
    if (defaultOrderBy.indexOf('?') != -1) {
      throw new PageException("原SQL[" + sql + "]中的order by包含参数,因此不能使用OrderBy插件进行修改!");
    }
    //新的sql
    sql = select.toString();
  } catch (Throwable e) {
    throw new PageException("处理排序失败: " + e, e);
  }
  return sql + " order by " + orderBy;
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-mapping-sql-core

/**
 * Create a new query with the changed projection and selection
 */
private static String getInstantiatedSQL(String sql,
                     List<SelectItem> newColumns,
                     List<SelectExpressionItem> templateColumns,
                     List<String> values) throws JSQLParserException {
  Select select = (Select) CCJSqlParserUtil.parse(sql);
  PlainSelect plainSelect = (PlainSelect)select.getSelectBody();
  Expression where = plainSelect.getWhere();
  int size = templateColumns.size(); // both lists have the same size
  for (int i = 0; i < size; i++) {
    BinaryExpression condition = new EqualsTo();
    condition.setLeftExpression(templateColumns.get(i).getExpression());
    condition.setRightExpression(new StringValue("'" + values.get(i) + "'"));
    where = (where == null) ? condition : new AndExpression(where, condition);
  }
  plainSelect.setWhere(where); // where cannot be null
  plainSelect.setSelectItems(newColumns);
  return select.toString();
}

代码示例来源:origin: ontop/ontop

/**
 * Create a new query with the changed projection and selection
 */
private static String getInstantiatedSQL(String sql,
                     List<SelectItem> newColumns,
                     List<SelectExpressionItem> templateColumns,
                     List<String> values) throws JSQLParserException {
  Select select = (Select) CCJSqlParserUtil.parse(sql);
  PlainSelect plainSelect = (PlainSelect)select.getSelectBody();
  Expression where = plainSelect.getWhere();
  int size = templateColumns.size(); // both lists have the same size
  for (int i = 0; i < size; i++) {
    BinaryExpression condition = new EqualsTo();
    condition.setLeftExpression(templateColumns.get(i).getExpression());
    condition.setRightExpression(new StringValue("'" + values.get(i) + "'"));
    where = (where == null) ? condition : new AndExpression(where, condition);
  }
  plainSelect.setWhere(where); // where cannot be null
  plainSelect.setSelectItems(newColumns);
  return select.toString();
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-obdalib-core

/**
 * Method to substitute * from the select query. It add the columns name that are used in the mapping
 * @param select the query with or without *
 * @param variables the variables used in the mapping, this are the needed columns for our select query
 * @return  the query with columns or functions in the projection part
 */
public String getMappingQuery(Select select, Set<Variable> variables) {
  VariableSet variableNames = new VariableSet(variables);
  
   if (select.getWithItemsList() != null) {
    for (WithItem withItem : select.getWithItemsList()) 
      withItem.accept(new ReplaceStarSelectVisitor(false, null, variableNames));
  }
  select.getSelectBody().accept(new ReplaceStarSelectVisitor(false, null, variableNames));
  return select.toString();
}

相关文章