本文整理汇总了Java中net.sf.jsqlparser.statement.Statement.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Statement.toString方法的具体用法?Java Statement.toString怎么用?Java Statement.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.jsqlparser.statement.Statement
的用法示例。
在下文中一共展示了Statement.toString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modifyTableNames
import net.sf.jsqlparser.statement.Statement; //导入方法依赖的package包/类
public static String modifyTableNames(String sql,TableRenamer tableRenamer)
{
if(sql == null)
{
throw new IllegalArgumentException("sql is null");
}
Statement statement = null;
try
{
statement = CCJSqlParserUtil.parse(sql);
}
catch (JSQLParserException e)
{
throw new IllegalArgumentException("Error when parsing sql:[" + sql+"]",e);
}
TableRenameVisitor tableRenameVisitor=new TableRenameVisitor(tableRenamer);
statement.accept(tableRenameVisitor);
return statement.toString();
}
示例2: parse
import net.sf.jsqlparser.statement.Statement; //导入方法依赖的package包/类
private String parse(String query, QueryType queryType) {
Statement statement = null;
try {
// Read and parse the query
Reader reader = new StringReader(query);
statement = parserManager.parse(reader);
// Find the appropriate method to call based on the query and statement types
if (statement instanceof Select) {
statement = queryType.parseQuery((Select) statement, this);
} else if (statement instanceof Insert) {
statement = queryType.parseQuery((Insert) statement, this);
} else if (statement instanceof Delete) {
statement = queryType.parseQuery((Delete) statement, this);
} else if (statement instanceof Update) {
requiresUpdate = true;
statement = queryType.parseQuery((Update) statement, this);
} else {
logger.error("SQL statement type not supported.");
}
} catch (JSQLParserException e) {
logger.error("Failed to parse query");
e.printStackTrace();
}
return statement == null ? "" : statement.toString();
}
示例3: parseSql
import net.sf.jsqlparser.statement.Statement; //导入方法依赖的package包/类
private static CassandraCqlStatement parseSql(CassandraConfiguration config, String sql, Map<String, String> hints) {
CassandraStatementType stmtType = CassandraStatementType.UNKNOWN;
if (Strings.isNullOrEmpty(sql)) {
return new CassandraCqlStatement(Strings.nullToEmpty(sql),
new CassandraCqlStmtConfiguration(config, stmtType, hints));
}
CassandraCqlStatement sqlStmt = null;
CassandraCqlStmtConfiguration stmtConfig = null;
try {
// workaround for limitation of JSqlParser - escaping keyword-like columns
Matcher m = SQL_KEYWORDS_PATTERN.matcher(sql);
sql = m.replaceAll(SQL_KEYWORD_ESCAPING);
// go ahead to parse the SQL
Statement s = CCJSqlParserUtil.parse(sql);
// now translate the SQL query to CQL
sql = s.toString();
if (s instanceof Select) {
stmtType = CassandraStatementType.SELECT;
} else if (sql.startsWith(CassandraStatementType.INSERT.getType())) {
stmtType = CassandraStatementType.INSERT;
} else if (sql.startsWith(CassandraStatementType.UPDATE.getType())) {
stmtType = CassandraStatementType.UPDATE;
} else if (sql.startsWith(CassandraStatementType.DELETE.getType())) {
stmtType = CassandraStatementType.DELETE;
} else if (sql.startsWith(CassandraStatementType.TRUNCATE.getType())) {
stmtType = CassandraStatementType.TRUNCATE;
} else if (sql.startsWith(CassandraStatementType.CREATE.getType())) {
stmtType = CassandraStatementType.CREATE;
} else if (sql.startsWith(CassandraStatementType.ALTER.getType())) {
stmtType = CassandraStatementType.ALTER;
} else if (sql.startsWith(CassandraStatementType.DROP.getType())) {
stmtType = CassandraStatementType.DROP;
}
stmtConfig = new CassandraCqlStmtConfiguration(config, stmtType, hints);
if (stmtType.isQuery()) {
Select select = (Select) s;
SqlToCqlTranslator trans = new SqlToCqlTranslator(stmtConfig);
select.getSelectBody().accept(trans);
sql = select.toString();
}
} catch (Throwable t) {
Logger.debug("Failed to parse the given SQL, fall back to CQL parser");
sqlStmt = parseCql(config, sql, hints);
sql = sqlStmt.getCql();
}
if (sqlStmt == null) {
sqlStmt = new CassandraCqlStatement(sql, stmtConfig == null
? new CassandraCqlStmtConfiguration(config, stmtType, hints) : stmtConfig);
}
return sqlStmt;
}