當前位置: 首頁>>代碼示例>>Java>>正文


Java SqlParser類代碼示例

本文整理匯總了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));
	}
}
 
開發者ID:lane-cn,項目名稱:elasticsql,代碼行數:30,代碼來源:ESActionFactory.java

示例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));
	}
}
 
開發者ID:mazhou,項目名稱:es-sql,代碼行數:42,代碼來源:ESActionFactory.java

示例3: init

import org.nlpcn.es4sql.parse.SqlParser; //導入依賴的package包/類
@BeforeClass
public static void init() {
    parser = new SqlParser();
}
 
開發者ID:mazhou,項目名稱:es-sql,代碼行數:5,代碼來源:SQLFunctionsTest.java


注:本文中的org.nlpcn.es4sql.parse.SqlParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。