本文整理汇总了Java中org.nlpcn.es4sql.parse.SqlParser类的典型用法代码示例。如果您正苦于以下问题:Java SqlParser类的具体用法?Java SqlParser怎么用?Java SqlParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlParser类属于org.nlpcn.es4sql.parse包,在下文中一共展示了SqlParser类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.nlpcn.es4sql.parse.SqlParser; //导入依赖的package包/类
/**
* Create the compatible Query object
* based on the SQL query.
*
* @param sql The SQL query.
* @return Query object.
*/
public static QueryAction create(Client client, String sql) throws SqlParseException, SQLFeatureNotSupportedException {
String firstWord = sql.substring(0, sql.indexOf(' '));
switch (firstWord.toUpperCase()) {
case "SELECT":
SQLQueryExpr sqlExpr = (SQLQueryExpr) SQLUtils.toMySqlExpr(sql);
Select select = new SqlParser().parseSelect(sqlExpr);
if (select.isAgg) {
return new AggregationQueryAction(client, select);
} else {
return new DefaultQueryAction(client, select);
}
case "DELETE":
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcUtils.MYSQL);
SQLDeleteStatement deleteStatement = parser.parseDeleteStatement();
Delete delete = new SqlParser().parseDelete(deleteStatement);
return new DeleteQueryAction(client, delete);
default:
throw new SQLFeatureNotSupportedException(String.format("Unsupported query: %s", sql));
}
}
示例2: create
import org.nlpcn.es4sql.parse.SqlParser; //导入依赖的package包/类
/**
* Create the compatible Query object
* based on the SQL query.
*
* @param sql The SQL query.
* @return Query object.
*/
public static QueryAction create(Client client, String sql) throws SqlParseException, SQLFeatureNotSupportedException {
sql = sql.replaceAll("\n"," ");
String firstWord = sql.substring(0, sql.indexOf(' '));
switch (firstWord.toUpperCase()) {
case "SELECT":
SQLQueryExpr sqlExpr = (SQLQueryExpr) toSqlExpr(sql);
if(isMulti(sqlExpr)){
MultiQuerySelect multiSelect = new SqlParser().parseMultiSelect((SQLUnionQuery) sqlExpr.getSubQuery().getQuery());
handleSubQueries(client,multiSelect.getFirstSelect());
handleSubQueries(client,multiSelect.getSecondSelect());
return new MultiQueryAction(client, multiSelect);
}
else if(isJoin(sqlExpr,sql)){
JoinSelect joinSelect = new SqlParser().parseJoinSelect(sqlExpr);
handleSubQueries(client, joinSelect.getFirstTable());
handleSubQueries(client, joinSelect.getSecondTable());
return ESJoinQueryActionFactory.createJoinAction(client, joinSelect);
}
else {
Select select = new SqlParser().parseSelect(sqlExpr);
handleSubQueries(client, select);
return handleSelect(client, select);
}
case "DELETE":
SQLStatementParser parser = createSqlStatementParser(sql);
SQLDeleteStatement deleteStatement = parser.parseDeleteStatement();
Delete delete = new SqlParser().parseDelete(deleteStatement);
return new DeleteQueryAction(client, delete);
case "SHOW":
return new ShowQueryAction(client,sql);
default:
throw new SQLFeatureNotSupportedException(String.format("Unsupported query: %s", sql));
}
}
示例3: init
import org.nlpcn.es4sql.parse.SqlParser; //导入依赖的package包/类
@BeforeClass
public static void init() {
parser = new SqlParser();
}