spuerx vor 9 Jahren
Ursprung
Commit
f62ccd79ef
96 geänderte Dateien mit 1319 neuen und 788 gelöschten Zeilen
  1. 15 14
      README.md
  2. 0 104
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/AbstractAtomMethodQueryParser.java
  3. 5 9
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/AbstractFieldSpecificMethodQueryParser.java
  4. 13 2
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/CheckableMethodQueryParser.java
  5. 58 9
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/MethodInvocation.java
  6. 5 0
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/MethodQueryParser.java
  7. 7 4
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/ParameterizedMethodQueryParser.java
  8. 27 24
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/FullTextAtomQueryParser.java
  9. 33 48
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/MatchAtomQueryParser.java
  10. 26 48
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/MultiMatchAtomQueryParser.java
  11. 40 68
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/QueryStringAtomQueryParser.java
  12. 39 63
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/SimpleQueryStringAtomQueryParser.java
  13. 30 36
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/script/ScriptAtomQueryParser.java
  14. 27 39
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/FuzzyAtomQueryParser.java
  15. 28 40
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/PrefixAtomQueryParser.java
  16. 30 39
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/RegexpAtomQueryParser.java
  17. 29 41
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/TermAtomQueryParser.java
  18. 1 1
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/TermLevelAtomQueryParser.java
  19. 18 40
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/TermsAtomQueryParser.java
  20. 28 40
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/WildcardAtomQueryParser.java
  21. 3 2
      elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/sql/AbstractQueryConditionParser.java
  22. 1 1
      elasticsearch-query-core/src/test/java/org/elasticsearch/query/SqlParserWhereConditionTest.java
  23. 4 4
      elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserLimitTest.xml
  24. 2 2
      elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserListenerTest.xml
  25. 2 2
      elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserOrderByTest.xml
  26. 10 10
      elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserQueryTest.xml
  27. 2 2
      elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserRoutingTest.xml
  28. 5 5
      elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserSelectFieldTest.xml
  29. 7 7
      elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserWhereConditionTest.xml
  30. 1 1
      elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserLimitTest.txt
  31. 1 1
      elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserListenerTest.txt
  32. 1 1
      elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserOrderByTest.txt
  33. 1 1
      elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserQueryTest.txt
  34. 1 1
      elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserRoutingTest.txt
  35. 1 1
      elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserSelectFieldTest.txt
  36. 1 1
      elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserWhereConditionTest.txt
  37. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractConnection.java
  38. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractDataSource.java
  39. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractDriverBasedDataSource.java
  40. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedConnection.java
  41. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedPreparedStatement.java
  42. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedResultSet.java
  43. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedStatement.java
  44. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractResultSet.java
  45. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractStatement.java
  46. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ConnectionProxy.java
  47. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/DriverManagerDataSource.java
  48. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticConnection.java
  49. 2 2
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticDatabaseMetaData.java
  50. 4 4
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticDriver.java
  51. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticPreparedStatement.java
  52. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticResultSet.java
  53. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticResultSetMetaData.java
  54. 2 3
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticSingleConnectionDataSource.java
  55. 3 3
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticStatement.java
  56. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/SmartDataSource.java
  57. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/ElasticClientProvider.java
  58. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/ElasticClientProxy.java
  59. 2 2
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/ElasticClientProxyProviderImpl.java
  60. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchActionExecutor.java
  61. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchResponse.java
  62. 2 2
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchResponseExtractor.java
  63. 2 2
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchResponseResolver.java
  64. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/exception/BuildElasticClientException.java
  65. 1 1
      elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/exception/ResolveSearchResponseException.java
  66. 1 1
      elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/BaseJdbcTest.java
  67. 4 4
      elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/ElasticDriverTest.java
  68. 3 3
      elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/GroupByTest.java
  69. 3 3
      elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/MethodQueryTest.java
  70. 3 10
      elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/ScriptQueryTest.java
  71. 5 5
      elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.ElasticDriverTest.xml
  72. 2 2
      elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.GroupByTest.xml
  73. 2 2
      elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.MethodQueryTest.xml
  74. 2 2
      elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.ScriptQueryTest.xml
  75. 1 1
      elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.ElasticDriverTest.txt
  76. 1 1
      elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.GroupByTest.txt
  77. 1 1
      elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.MethodQueryTest.txt
  78. 1 1
      elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.ScriptQueryTest.txt
  79. 6 0
      elasticsearch-query-spring/pom.xml
  80. 203 1
      elasticsearch-query-spring/src/main/java/org/elasticsearch/ElasticSqlMapClientTemplate.java
  81. 81 0
      elasticsearch-query-spring/src/main/java/org/elasticsearch/ElasticSqlMapExecutor.java
  82. 23 0
      elasticsearch-query-spring/src/main/java/org/elasticsearch/bean/Buyer.java
  83. 66 0
      elasticsearch-query-spring/src/main/java/org/elasticsearch/bean/Product.java
  84. 23 0
      elasticsearch-query-spring/src/main/java/org/elasticsearch/bean/Provider.java
  85. 35 0
      elasticsearch-query-spring/src/main/java/org/elasticsearch/dao/ProductDao.java
  86. 40 0
      elasticsearch-query-spring/src/main/resources/application-context.xml
  87. 30 0
      elasticsearch-query-spring/src/main/resources/log4j.properties
  88. 17 0
      elasticsearch-query-spring/src/main/resources/sqlMapConfig.xml
  89. 19 0
      elasticsearch-query-spring/src/main/resources/sqlmap/PRODUCT.xml
  90. 31 0
      elasticsearch-query-spring/src/test/java/org/elasticsearch/ProductIndexQueryTest.java
  91. 40 0
      elasticsearch-query-spring/target/classes/application-context.xml
  92. 30 0
      elasticsearch-query-spring/target/classes/log4j.properties
  93. 17 0
      elasticsearch-query-spring/target/classes/sqlMapConfig.xml
  94. 19 0
      elasticsearch-query-spring/target/classes/sqlmap/PRODUCT.xml
  95. 65 0
      elasticsearch-query-spring/target/surefire-reports/TEST-org.elasticsearch.ProductIndexQueryTest.xml
  96. 4 0
      elasticsearch-query-spring/target/surefire-reports/org.elasticsearch.ProductIndexQueryTest.txt

+ 15 - 14
README.md

@@ -7,7 +7,7 @@ elasticsearch-query-tookit
 toolkit version | ES version
 -----------|-----------
 master | 2.4.4
-2.4.4.1 | 2.4.4
+2.4.4.2 | 2.4.4
 1.x    | 1.4.5
 
 介绍
@@ -32,6 +32,7 @@ SearchRequestBuilder searchReq = parseResult.toRequest(esClient);
 //执行查询
 SearchResponse response = searchReq.execute().actionGet();
 ```
+注:其中routing by用于指定查询路由值,也可以不指定
 生成的DSL如下:
 ```bash
 {
@@ -74,15 +75,20 @@ SearchResponse response = searchReq.execute().actionGet();
 2. 指定连接ES的连接串:jdbc:elastic:192.168.0.109:9300/product_cluster
 3. 创建一个SqlMapClient对象,并指定sqlMapConfig.xml路径
 ```bash
-<bean id="elasticDataSource" class="org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource" destroy-method="destroy">
-    <property name="driverClassName" value="org.elasticsearch.jdbc.api.ElasticDriver" />
-    <property name="url" value="jdbc:elastic:192.168.0.109:9300/product_cluster" />
+<bean id="elasticDataSource" class="org.elasticsearch.api.ElasticSingleConnectionDataSource" destroy-method="destroy">
+    <property name="driverClassName" value="org.elasticsearch.api.ElasticDriver" />
+    <property name="url" value="jdbc:elastic:192.168.0.109:9300/lu-search-cluster" />
+    <property name="suppressClose" value="true" />
 </bean>
 
 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
     <property name="dataSource" ref="elasticDataSource" />
     <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
 </bean>
+
+<bean id="sqlMapClientTemplate" class="org.elasticsearch.ElasticSqlMapClientTemplate">
+    <property name="sqlMapClient" ref="sqlMapClient"/>
+</bean>
 ```
 
 sqlMapConfig.xml文件内容如下:
@@ -123,9 +129,8 @@ PRODUCT.xml文件中声明select sql语句
 @Repository
 public class ProductDao {
     @Autowired
-    @Qualifier("sqlMapClient")
-    private SqlMapClient sqlMapClient;
-
+    @Qualifier("sqlMapClientTemplate")
+    private ElasticSqlMapExecutor sqlMapClientTemplate;
 
     public List<Product> getProductByCodeAndMatchWord(String matchWord, String productCode) throws SQLException {
         Map<String, Object> paramMap = Maps.newHashMap();
@@ -134,13 +139,8 @@ public class ProductDao {
         paramMap.put("routingVal", "A");
         paramMap.put("matchWord", matchWord);
         paramMap.put("prefixWord", matchWord);
-        String responseGson = (String) sqlMapClient.queryForObject("PRODUCT.getProductByCodeAndMatchWord", paramMap);
-        
-        //反序列化查询结果
-        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
-        JdbcSearchResponse<Product> searchResponse = responseResolver.resolveSearchResponse(Product.class);
 
-        return searchResponse.getDocList();
+        return sqlMapClientTemplate.queryForList("PRODUCT.getProductByCodeAndMatchWord", paramMap, Product.class);
 
     }
 }
@@ -150,8 +150,9 @@ public class ProductDao {
 @Test
 public void testProductQuery() throws Exception {
     BeanFactory factory = new ClassPathXmlApplicationContext("application-context.xml");
+
     ProductDao productDao = factory.getBean(ProductDao.class);
-    
+
     List<Product> productList = productDao.getProductByCodeAndMatchWord("iphone 6s", "IP_6S");
     for (Product product : productList) {
         System.out.println(product.getProductName());

+ 0 - 104
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/AbstractAtomMethodQueryParser.java

@@ -1,104 +0,0 @@
-package org.elasticsearch.dsl.parser.query.method;
-
-import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
-import com.google.common.collect.Maps;
-import org.elasticsearch.dsl.bean.AtomQuery;
-import org.elasticsearch.dsl.bean.ElasticSqlQueryField;
-import org.elasticsearch.dsl.enums.QueryFieldType;
-import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.listener.ParseActionListener;
-import org.elasticsearch.dsl.parser.sql.QueryFieldParser;
-import org.elasticsearch.index.query.QueryBuilder;
-
-import java.util.Map;
-
-public abstract class AbstractAtomMethodQueryParser implements MethodQueryParser {
-
-    protected static final String COMMA = ",";
-
-    protected static final String COLON = ":";
-
-    protected ParseActionListener parseActionListener;
-
-    public AbstractAtomMethodQueryParser(ParseActionListener parseActionListener) {
-        this.parseActionListener = parseActionListener;
-    }
-
-    protected abstract void checkQueryMethod(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs);
-
-    protected abstract AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs);
-
-    protected interface IConditionMethodQueryBuilder {
-        QueryBuilder buildQuery(String queryFieldName, Object[] parameters);
-    }
-
-
-    public final AtomQuery parseAtomMethodQuery(MethodInvocation invocation) {
-        checkQueryMethod(invocation.getMatchQueryExpr(), invocation.getQueryAs(), invocation.getSqlArgs());
-
-        return parseMethodQueryExpr(invocation.getMatchQueryExpr(), invocation.getQueryAs(), invocation.getSqlArgs());
-    }
-
-    protected AtomQuery parseCondition(SQLExpr queryFieldExpr, Object[] parameters, String queryAs, IConditionMethodQueryBuilder queryBuilder) {
-        QueryFieldParser queryFieldParser = new QueryFieldParser();
-        ElasticSqlQueryField queryField = queryFieldParser.parseConditionQueryField(queryFieldExpr, queryAs);
-
-        AtomQuery atomQuery = null;
-        if (queryField.getQueryFieldType() == QueryFieldType.RootDocField || queryField.getQueryFieldType() == QueryFieldType.InnerDocField) {
-            QueryBuilder originalQuery = queryBuilder.buildQuery(queryField.getQueryFieldFullName(), parameters);
-            atomQuery = new AtomQuery(originalQuery);
-        }
-
-        if (queryField.getQueryFieldType() == QueryFieldType.NestedDocField) {
-            QueryBuilder originalQuery = queryBuilder.buildQuery(queryField.getQueryFieldFullName(), parameters);
-            atomQuery = new AtomQuery(originalQuery, queryField.getNestedDocContextPath());
-        }
-
-        if (atomQuery == null) {
-            throw new ElasticSql2DslException(String.format("[syntax error] query condition field can not support type[%s]", queryField.getQueryFieldType()));
-        }
-
-        onAtomMethodQueryConditionParse(queryField, parameters);
-
-        return atomQuery;
-    }
-
-    private void onAtomMethodQueryConditionParse(ElasticSqlQueryField paramName, Object[] parameters) {
-        try {
-            parseActionListener.onAtomMethodQueryConditionParse(paramName, parameters);
-        }
-        catch (Exception ex) {
-            try {
-                parseActionListener.onFailure(ex);
-            }
-            catch (Exception exp) {
-                //ignore;
-            }
-        }
-    }
-
-    protected Map<String, String> buildExtraMethodQueryParamsMap(String strMatchQueryParams) {
-        Map<String, String> extraParamMap = Maps.newHashMap();
-        for (String paramPair : strMatchQueryParams.split(COMMA)) {
-            String[] paramPairArr = paramPair.split(COLON);
-            if (paramPairArr.length == 2) {
-                extraParamMap.put(paramPairArr[0].trim(), paramPairArr[1].trim());
-            }
-            else {
-                throw new ElasticSql2DslException("Failed to parse query method params!");
-            }
-        }
-        return extraParamMap;
-    }
-
-    protected Boolean isExtraParamsString(String extraParams) {
-        for (String paramPair : extraParams.split(COMMA)) {
-            String[] paramPairArr = paramPair.split(COLON);
-            if (paramPairArr.length != 2) {
-                return Boolean.FALSE;
-            }
-        }
-        return Boolean.TRUE;
-    }
-}

+ 5 - 9
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/AbstractFieldSpecificMethodQueryParser.java

@@ -21,22 +21,18 @@ public abstract class AbstractFieldSpecificMethodQueryParser extends Parameteriz
 
     protected abstract QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams);
 
-    protected abstract SQLExpr getFieldExpr(MethodInvocation invocation);
+    protected abstract SQLExpr defineFieldExpr(MethodInvocation invocation);
 
     @Override
-    protected String getExtraParamString(MethodInvocation invocation) {
+    protected String defineExtraParamString(MethodInvocation invocation) {
         //ignore extra params, subclass can override if necessary
         return null;
     }
 
     @Override
     protected AtomQuery parseMethodQueryWithExtraParams(MethodInvocation invocation, Map<String, String> extraParamMap) throws ElasticSql2DslException {
-        return parseCondition(invocation, extraParamMap);
-    }
-
-    private AtomQuery parseCondition(MethodInvocation invocation, Map<String, String> extraParamMap) {
         QueryFieldParser queryFieldParser = new QueryFieldParser();
-        ElasticSqlQueryField queryField = queryFieldParser.parseConditionQueryField(getFieldExpr(invocation), invocation.getQueryAs());
+        ElasticSqlQueryField queryField = queryFieldParser.parseConditionQueryField(defineFieldExpr(invocation), invocation.getQueryAs());
 
         AtomQuery atomQuery = null;
         if (queryField.getQueryFieldType() == QueryFieldType.RootDocField || queryField.getQueryFieldType() == QueryFieldType.InnerDocField) {
@@ -50,7 +46,8 @@ public abstract class AbstractFieldSpecificMethodQueryParser extends Parameteriz
         }
 
         if (atomQuery == null) {
-            throw new ElasticSql2DslException(String.format("[syntax error] query condition field can not support type[%s]", queryField.getQueryFieldType()));
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] query field can not support type[%s]", queryField.getQueryFieldType()));
         }
 
         onAtomMethodQueryConditionParse(queryField, invocation.getSqlArgs());
@@ -58,7 +55,6 @@ public abstract class AbstractFieldSpecificMethodQueryParser extends Parameteriz
         return atomQuery;
     }
 
-
     private void onAtomMethodQueryConditionParse(ElasticSqlQueryField paramName, Object[] parameters) {
         try {
             parseActionListener.onAtomMethodQueryConditionParse(paramName, parameters);

+ 13 - 2
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/CheckableMethodQueryParser.java

@@ -2,16 +2,27 @@ package org.elasticsearch.dsl.parser.query.method;
 
 import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
+import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 
 public abstract class CheckableMethodQueryParser implements MethodQueryParser {
 
-    protected abstract void checkQueryMethod(MethodInvocation invocation) throws ElasticSql2DslException;
+    protected abstract void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException;
 
     protected abstract AtomQuery parseMethodQueryWithCheck(MethodInvocation invocation) throws ElasticSql2DslException;
 
     @Override
+    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
+        return ElasticSqlMethodInvokeHelper.isMethodOf(defineMethodNames(), invocation.getMethodName());
+    }
+
+    @Override
     public AtomQuery parseAtomMethodQuery(MethodInvocation invocation) throws ElasticSql2DslException {
-        checkQueryMethod(invocation);
+        if (!isMatchMethodInvocation(invocation)) {
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] Expected method name is one of [%s],but get [%s]",
+                            defineMethodNames(), invocation.getMethodName()));
+        }
+        checkMethodInvokeArgs(invocation);
         return parseMethodQueryWithCheck(invocation);
     }
 }

+ 58 - 9
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/MethodInvocation.java

@@ -1,22 +1,25 @@
 package org.elasticsearch.dsl.parser.query.method;
 
+import com.alibaba.druid.sql.ast.SQLExpr;
 import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
+import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
+
+import java.util.List;
 
 public class MethodInvocation {
-    private SQLMethodInvokeExpr matchQueryExpr;
-    private String queryAs;
-    private Object[] sqlArgs;
+    private final SQLMethodInvokeExpr methodInvokeExpr;
+    private final String queryAs;
+    private final Object[] sqlArgs;
 
-    public MethodInvocation(SQLMethodInvokeExpr matchQueryExpr, String queryAs, Object[] sqlArgs) {
-        this.matchQueryExpr = matchQueryExpr;
+    public MethodInvocation(SQLMethodInvokeExpr methodInvokeExpr, String queryAs, Object[] sqlArgs) {
+        if (methodInvokeExpr == null) {
+            throw new IllegalArgumentException("method invoke expression can not be null");
+        }
+        this.methodInvokeExpr = methodInvokeExpr;
         this.queryAs = queryAs;
         this.sqlArgs = sqlArgs;
     }
 
-    public SQLMethodInvokeExpr getMatchQueryExpr() {
-        return matchQueryExpr;
-    }
-
     public String getQueryAs() {
         return queryAs;
     }
@@ -24,4 +27,50 @@ public class MethodInvocation {
     public Object[] getSqlArgs() {
         return sqlArgs;
     }
+
+    public String getMethodName() {
+        return methodInvokeExpr.getMethodName();
+    }
+
+    public List<SQLExpr> getParameters() {
+        return methodInvokeExpr.getParameters();
+    }
+
+    public int getParameterCount() {
+        return methodInvokeExpr.getParameters().size();
+    }
+
+    public SQLExpr getFirstParameter(int index) {
+        return getParameter(0);
+    }
+
+    public SQLExpr getParameter(int index) {
+        return methodInvokeExpr.getParameters().get(index);
+    }
+
+    public Object getParameterAsObject(int index) {
+        SQLExpr paramExpr = methodInvokeExpr.getParameters().get(index);
+        return ElasticSqlArgTransferHelper.transferSqlArg(paramExpr, sqlArgs, false);
+    }
+
+    public String getParameterAsFormatDate(int index) {
+        SQLExpr paramExpr = methodInvokeExpr.getParameters().get(index);
+        return ElasticSqlArgTransferHelper.transferSqlArg(paramExpr, sqlArgs, true).toString();
+    }
+
+    public String getParameterAsString(int index) {
+        return getParameterAsObject(index).toString();
+    }
+
+    public String getLastParameterAsString() {
+        return getParameterAsObject(getParameterCount() - 1).toString();
+    }
+
+    public Double getParameterAsDouble(int index) {
+        return (Double) getParameterAsObject(index);
+    }
+
+    public Long getParameterAsLong(int index) {
+        return (Long) getParameterAsObject(index);
+    }
 }

+ 5 - 0
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/MethodQueryParser.java

@@ -3,7 +3,12 @@ package org.elasticsearch.dsl.parser.query.method;
 import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
 
+import java.util.List;
+
 public interface MethodQueryParser {
+
+    List<String> defineMethodNames();
+
     boolean isMatchMethodInvocation(MethodInvocation invocation);
 
     AtomQuery parseAtomMethodQuery(MethodInvocation invocation) throws ElasticSql2DslException;

+ 7 - 4
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/ParameterizedMethodQueryParser.java

@@ -10,11 +10,11 @@ import java.util.Map;
 
 public abstract class ParameterizedMethodQueryParser extends CheckableMethodQueryParser {
 
-    private static final String COMMA = ",";
+    protected static final String COMMA = ",";
 
-    private static final String COLON = ":";
+    protected static final String COLON = ":";
 
-    protected abstract String getExtraParamString(MethodInvocation invocation);
+    protected abstract String defineExtraParamString(MethodInvocation invocation);
 
     protected abstract AtomQuery parseMethodQueryWithExtraParams(
             MethodInvocation invocation, Map<String, String> extraParamMap) throws ElasticSql2DslException;
@@ -26,7 +26,7 @@ public abstract class ParameterizedMethodQueryParser extends CheckableMethodQuer
     }
 
     private Map<String, String> buildExtraParamMap(MethodInvocation invocation) {
-        String extraParamString = getExtraParamString(invocation);
+        String extraParamString = defineExtraParamString(invocation);
 
         if (StringUtils.isBlank(extraParamString)) {
             return Collections.emptyMap();
@@ -46,6 +46,9 @@ public abstract class ParameterizedMethodQueryParser extends CheckableMethodQuer
     }
 
     protected Boolean isExtraParamsString(String extraParams) {
+        if (StringUtils.isBlank(extraParams)) {
+            return Boolean.FALSE;
+        }
         for (String paramPair : extraParams.split(COMMA)) {
             String[] paramPairArr = paramPair.split(COLON);
             if (paramPairArr.length != 2) {

+ 27 - 24
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/FullTextAtomQueryParser.java

@@ -1,48 +1,51 @@
 package org.elasticsearch.dsl.parser.query.method.fulltext;
 
 import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
+import com.google.common.collect.ImmutableList;
 import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
 import org.elasticsearch.dsl.listener.ParseActionListener;
-import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
+import org.elasticsearch.dsl.parser.query.method.MethodQueryParser;
+
+import java.util.List;
+import java.util.function.Predicate;
 
 public class FullTextAtomQueryParser {
 
-    protected ParseActionListener parseActionListener;
+    private final List<MethodQueryParser> methodQueryParsers;
 
     public FullTextAtomQueryParser(ParseActionListener parseActionListener) {
-        this.parseActionListener = parseActionListener;
+        methodQueryParsers = ImmutableList.of(
+                new MatchAtomQueryParser(parseActionListener),
+                new MultiMatchAtomQueryParser(),
+                new QueryStringAtomQueryParser(),
+                new SimpleQueryStringAtomQueryParser()
+        );
     }
 
-    public Boolean isFulltextAtomQuery(SQLMethodInvokeExpr methodQueryExpr) {
-        return MatchAtomQueryParser.isMatchQuery(methodQueryExpr) || MultiMatchAtomQueryParser.isMultiMatch(methodQueryExpr) ||
-                QueryStringAtomQueryParser.isQueryStringQuery(methodQueryExpr) || SimpleQueryStringAtomQueryParser.isSimpleQueryStringQuery(methodQueryExpr);
+    public Boolean isFulltextAtomQuery(MethodInvocation invocation) {
+        return methodQueryParsers.stream().anyMatch(new Predicate<MethodQueryParser>() {
+            @Override
+            public boolean test(MethodQueryParser methodQueryParser) {
+                return methodQueryParser.isMatchMethodInvocation(invocation);
+            }
+        });
     }
 
     public AtomQuery parseFullTextAtomQuery(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        AbstractAtomMethodQueryParser matchAtomQueryParser = getQueryParser(methodQueryExpr);
         MethodInvocation methodInvocation = new MethodInvocation(methodQueryExpr, queryAs, sqlArgs);
+        MethodQueryParser matchAtomQueryParser = getQueryParser(methodInvocation);
         return matchAtomQueryParser.parseAtomMethodQuery(methodInvocation);
     }
 
-    private AbstractAtomMethodQueryParser getQueryParser(SQLMethodInvokeExpr methodQueryExpr) {
-        if (Boolean.TRUE == MatchAtomQueryParser.isMatchQuery(methodQueryExpr)) {
-            return new MatchAtomQueryParser(parseActionListener);
-        }
-
-        if (Boolean.TRUE == MultiMatchAtomQueryParser.isMultiMatch(methodQueryExpr)) {
-            return new MultiMatchAtomQueryParser(parseActionListener);
-        }
-
-        if (Boolean.TRUE == QueryStringAtomQueryParser.isQueryStringQuery(methodQueryExpr)) {
-            return new QueryStringAtomQueryParser(parseActionListener);
-        }
-
-        if (Boolean.TRUE == SimpleQueryStringAtomQueryParser.isSimpleQueryStringQuery(methodQueryExpr)) {
-            return new SimpleQueryStringAtomQueryParser(parseActionListener);
+    private MethodQueryParser getQueryParser(MethodInvocation invocation) {
+        for (MethodQueryParser methodQueryParser : methodQueryParsers) {
+            if (methodQueryParser.isMatchMethodInvocation(invocation)) {
+                return methodQueryParser;
+            }
         }
-
-        throw new ElasticSql2DslException(String.format("[syntax error] Can not support method query expr[%s] condition", methodQueryExpr.getMethodName()));
+        throw new ElasticSql2DslException(
+                String.format("[syntax error] Can not support method query expr[%s] condition", invocation.getMethodName()));
     }
 }

+ 33 - 48
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/MatchAtomQueryParser.java

@@ -1,17 +1,13 @@
 package org.elasticsearch.dsl.parser.query.method.fulltext;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.common.unit.Fuzziness;
-import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 import org.elasticsearch.dsl.listener.ParseActionListener;
-import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
+import org.elasticsearch.dsl.parser.query.method.AbstractFieldSpecificMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
 import org.elasticsearch.index.query.MatchQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
@@ -20,7 +16,7 @@ import org.elasticsearch.index.query.QueryBuilders;
 import java.util.List;
 import java.util.Map;
 
-public class MatchAtomQueryParser extends AbstractAtomMethodQueryParser {
+public class MatchAtomQueryParser extends AbstractFieldSpecificMethodQueryParser {
 
     private static final List<String> MATCH_METHOD = ImmutableList.of("match", "match_query", "matchQuery");
 
@@ -28,63 +24,52 @@ public class MatchAtomQueryParser extends AbstractAtomMethodQueryParser {
         super(parseActionListener);
     }
 
-    public static Boolean isMatchQuery(SQLMethodInvokeExpr methodQueryExpr) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(MATCH_METHOD, methodQueryExpr.getMethodName());
-    }
-
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return false;
+    public List<String> defineMethodNames() {
+        return MATCH_METHOD;
     }
 
     @Override
-    protected void checkQueryMethod(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        if (Boolean.FALSE == isMatchQuery(methodQueryExpr)) {
-            throw new ElasticSql2DslException(String.format("[syntax error] Expected match query method name is [match],but get [%s]", methodQueryExpr.getMethodName()));
-        }
+    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
+        String text = invocation.getParameterAsString(1);
+        MatchQueryBuilder matchQuery = QueryBuilders.matchQuery(fieldName, text);
 
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: match", paramCount));
-        }
+        setExtraMatchQueryParam(matchQuery, extraParams);
+        return matchQuery;
+    }
 
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
+    @Override
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 2;
 
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false).toString();
-        if (StringUtils.isEmpty(text)) {
-            throw new ElasticSql2DslException("[syntax error] Search text can not be blank!");
-        }
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
     }
 
     @Override
-    @SuppressWarnings("unchecked")
-    protected AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        SQLExpr queryField = methodQueryExpr.getParameters().get(0);
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
-
-        Map<String, String> extraParamMap = null;
-        if (methodQueryExpr.getParameters().size() == 3) {
-            SQLExpr extraParamExpr = methodQueryExpr.getParameters().get(2);
-            String extraParam = ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
+    protected SQLExpr defineFieldExpr(MethodInvocation invocation) {
+        return invocation.getParameter(0);
+    }
 
-            extraParamMap = buildExtraMethodQueryParamsMap(extraParam);
+    @Override
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        if (invocation.getParameterCount() != 2 && invocation.getParameterCount() != 3) {
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        Object text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false);
-
-        return parseCondition(queryField, new Object[]{text, extraParamMap}, queryAs, new IConditionMethodQueryBuilder() {
-            @Override
-            public QueryBuilder buildQuery(String queryFieldName, Object[] parameters) {
-                MatchQueryBuilder matchQuery = QueryBuilders.matchQuery(queryFieldName, parameters[0]);
-
-                if (parameters.length == 2 && parameters[1] != null) {
-                    Map<String, String> tExtraParamMap = (Map<String, String>) parameters[1];
-                    setExtraMatchQueryParam(matchQuery, tExtraParamMap);
-                }
+        String text = invocation.getParameterAsString(1);
+        if (StringUtils.isEmpty(text)) {
+            throw new ElasticSql2DslException("[syntax error] Match search text can not be blank!");
+        }
 
-                return matchQuery;
+        if (invocation.getParameterCount() == 3) {
+            String extraParamString = defineExtraParamString(invocation);
+            if (StringUtils.isEmpty(extraParamString)) {
+                throw new ElasticSql2DslException("[syntax error] The extra param of match method can not be blank");
             }
-        });
+        }
     }
 
     private void setExtraMatchQueryParam(MatchQueryBuilder matchQuery, Map<String, String> extraParamMap) {

+ 26 - 48
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/MultiMatchAtomQueryParser.java

@@ -1,18 +1,13 @@
 package org.elasticsearch.dsl.parser.query.method.fulltext;
 
-import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.common.unit.Fuzziness;
 import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
-import org.elasticsearch.dsl.listener.ParseActionListener;
-import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
+import org.elasticsearch.dsl.parser.query.method.ParameterizedMethodQueryParser;
 import org.elasticsearch.index.query.MatchQueryBuilder;
 import org.elasticsearch.index.query.MultiMatchQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -20,39 +15,44 @@ import org.elasticsearch.index.query.QueryBuilders;
 import java.util.List;
 import java.util.Map;
 
-public class MultiMatchAtomQueryParser extends AbstractAtomMethodQueryParser {
+public class MultiMatchAtomQueryParser extends ParameterizedMethodQueryParser {
 
     private static final List<String> MULTI_MATCH_METHOD = ImmutableList.of("multiMatch", "multi_match", "multi_match_query", "multiMatchQuery");
 
-    public MultiMatchAtomQueryParser(ParseActionListener parseActionListener) {
-        super(parseActionListener);
+    @Override
+    public List<String> defineMethodNames() {
+        return MULTI_MATCH_METHOD;
     }
 
-    public static Boolean isMultiMatch(SQLMethodInvokeExpr methodQueryExpr) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(MULTI_MATCH_METHOD, methodQueryExpr.getMethodName());
+    @Override
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 2;
+
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return false;
+    protected AtomQuery parseMethodQueryWithExtraParams(MethodInvocation invocation, Map<String, String> extraParamMap) throws ElasticSql2DslException {
+        String[] fields = invocation.getParameterAsString(0).split(COMMA);
+        String text = invocation.getParameterAsString(1);
+
+        MultiMatchQueryBuilder multiMatchQuery = QueryBuilders.multiMatchQuery(text, fields);
+        setExtraMatchQueryParam(multiMatchQuery, extraParamMap);
+
+        return new AtomQuery(multiMatchQuery);
     }
 
     @Override
-    protected void checkQueryMethod(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        if (Boolean.FALSE == isMultiMatch(methodQueryExpr)) {
-            throw new ElasticSql2DslException(String.format("[syntax error] Expected multiMatch query method name is [multiMatch],but get [%s]", methodQueryExpr.getMethodName()));
-        }
-
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: multiMatch", paramCount));
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        if (invocation.getParameterCount() != 2 && invocation.getParameterCount() != 3) {
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLExpr fieldsExpr = methodQueryExpr.getParameters().get(0);
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
-
-        String strFields = ElasticSqlArgTransferHelper.transferSqlArg(fieldsExpr, sqlArgs, false).toString();
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false).toString();
+        String strFields = invocation.getParameterAsString(0);
+        String text = invocation.getParameterAsString(1);
 
         if (StringUtils.isEmpty(strFields)) {
             throw new ElasticSql2DslException("[syntax error] Search fields can not be empty!");
@@ -62,28 +62,6 @@ public class MultiMatchAtomQueryParser extends AbstractAtomMethodQueryParser {
         }
     }
 
-    @Override
-    protected AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        SQLExpr queryFields = methodQueryExpr.getParameters().get(0);
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
-
-        Map<String, String> extraParamMap = null;
-        if (methodQueryExpr.getParameters().size() == 3) {
-            SQLExpr extraParamExpr = methodQueryExpr.getParameters().get(2);
-            String extraParam = ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
-
-            extraParamMap = buildExtraMethodQueryParamsMap(extraParam);
-        }
-
-        String[] fields = ElasticSqlArgTransferHelper.transferSqlArg(queryFields, sqlArgs, false).toString().split(COMMA);
-        Object text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false);
-
-        MultiMatchQueryBuilder multiMatchQuery = QueryBuilders.multiMatchQuery(text, fields);
-        setExtraMatchQueryParam(multiMatchQuery, extraParamMap);
-
-        return new AtomQuery(multiMatchQuery);
-    }
-
     private void setExtraMatchQueryParam(MultiMatchQueryBuilder multiMatchQuery, Map<String, String> extraParamMap) {
         if (MapUtils.isEmpty(extraParamMap)) {
             return;

+ 40 - 68
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/QueryStringAtomQueryParser.java

@@ -1,18 +1,13 @@
 package org.elasticsearch.dsl.parser.query.method.fulltext;
 
-import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.common.unit.Fuzziness;
 import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
-import org.elasticsearch.dsl.listener.ParseActionListener;
-import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
+import org.elasticsearch.dsl.parser.query.method.ParameterizedMethodQueryParser;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.index.query.QueryStringQueryBuilder;
 
@@ -20,44 +15,65 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
-public class QueryStringAtomQueryParser extends AbstractAtomMethodQueryParser {
+public class QueryStringAtomQueryParser extends ParameterizedMethodQueryParser {
 
     private static List<String> QUERY_STRING_METHOD = ImmutableList.of("queryString", "query_string");
 
-    public QueryStringAtomQueryParser(ParseActionListener parseActionListener) {
-        super(parseActionListener);
-    }
-
-    public static Boolean isQueryStringQuery(SQLMethodInvokeExpr methodQueryExpr) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(QUERY_STRING_METHOD, methodQueryExpr.getMethodName());
+    @Override
+    public List<String> defineMethodNames() {
+        return QUERY_STRING_METHOD;
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return false;
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        return isExtraParamsString(invocation.getLastParameterAsString())
+                ? invocation.getLastParameterAsString() : StringUtils.EMPTY;
     }
 
     @Override
-    protected void checkQueryMethod(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        if (Boolean.FALSE == isQueryStringQuery(methodQueryExpr)) {
-            throw new ElasticSql2DslException(String.format("[syntax error] Expected queryString query method name is [queryString],but get [%s]", methodQueryExpr.getMethodName()));
+    protected AtomQuery parseMethodQueryWithExtraParams(MethodInvocation invocation, Map<String, String> extraParamMap) throws ElasticSql2DslException {
+        String text = invocation.getParameterAsString(0);
+        QueryStringQueryBuilder queryStringQuery = QueryBuilders.queryStringQuery(text);
+
+        String queryFields = null;
+        if (invocation.getParameterCount() == 3) {
+            queryFields = invocation.getParameterAsString(1);
         }
 
-        int paramCount = methodQueryExpr.getParameters().size();
+        if (StringUtils.isNotBlank(queryFields)) {
+            String[] tArr = queryFields.split(COLON);
+            if ("fields".equalsIgnoreCase(tArr[0])) {
+                for (String fieldItem : tArr[1].split(COMMA)) {
+                    queryStringQuery.field(fieldItem);
+                }
+            }
+
+            if ("default_field".equalsIgnoreCase(tArr[0])) {
+                queryStringQuery.defaultField(tArr[1]);
+            }
+        }
+
+        setExtraMatchQueryParam(queryStringQuery, extraParamMap);
+        return new AtomQuery(queryStringQuery);
+    }
+
+    @Override
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        int paramCount = invocation.getParameterCount();
         if (paramCount != 1 && paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: queryString", paramCount));
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(0);
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false).toString();
+        String text = invocation.getParameterAsString(0);
 
         if (StringUtils.isEmpty(text)) {
             throw new ElasticSql2DslException("[syntax error] Search text can not be blank!");
         }
 
         if (paramCount == 3) {
-            SQLExpr fieldsExpr = methodQueryExpr.getParameters().get(1);
-            String strFields = ElasticSqlArgTransferHelper.transferSqlArg(fieldsExpr, sqlArgs, false).toString();
+            String strFields = invocation.getParameterAsString(1);
 
             if (StringUtils.isEmpty(text)) {
                 throw new ElasticSql2DslException("[syntax error] Search fields can not be empty!");
@@ -74,50 +90,6 @@ public class QueryStringAtomQueryParser extends AbstractAtomMethodQueryParser {
         }
     }
 
-    @Override
-    protected AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(0);
-
-        SQLExpr queryFields = null;
-        SQLExpr extraParamExpr = null;
-
-        if (methodQueryExpr.getParameters().size() == 2) {
-            extraParamExpr = methodQueryExpr.getParameters().get(1);
-        }
-        else if (methodQueryExpr.getParameters().size() == 3) {
-            queryFields = methodQueryExpr.getParameters().get(1);
-            extraParamExpr = methodQueryExpr.getParameters().get(2);
-        }
-
-
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false).toString();
-        QueryStringQueryBuilder queryStringQuery = QueryBuilders.queryStringQuery(text);
-
-        if (queryFields != null) {
-            String[] tArr = ElasticSqlArgTransferHelper.transferSqlArg(queryFields, sqlArgs, false).toString().split(COLON);
-            if ("fields".equalsIgnoreCase(tArr[0])) {
-                for (String fieldItem : tArr[1].split(COMMA)) {
-                    queryStringQuery.field(fieldItem);
-                }
-            }
-
-            if ("default_field".equalsIgnoreCase(tArr[0])) {
-                queryStringQuery.defaultField(tArr[1]);
-            }
-        }
-
-        Map<String, String> extraParamMap = null;
-        if (extraParamExpr != null) {
-            String extraParam = ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
-            extraParamMap = buildExtraMethodQueryParamsMap(extraParam);
-        }
-
-
-        setExtraMatchQueryParam(queryStringQuery, extraParamMap);
-
-        return new AtomQuery(queryStringQuery);
-    }
-
     private void setExtraMatchQueryParam(QueryStringQueryBuilder queryStringQuery, Map<String, String> extraParamMap) {
         if (MapUtils.isEmpty(extraParamMap)) {
             return;

+ 39 - 63
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/fulltext/SimpleQueryStringAtomQueryParser.java

@@ -1,18 +1,13 @@
 package org.elasticsearch.dsl.parser.query.method.fulltext;
 
-import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
-import org.elasticsearch.dsl.listener.ParseActionListener;
-import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
+import org.elasticsearch.dsl.parser.query.method.ParameterizedMethodQueryParser;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.index.query.SimpleQueryStringBuilder;
 import org.elasticsearch.index.query.SimpleQueryStringFlag;
@@ -21,44 +16,64 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
-public class SimpleQueryStringAtomQueryParser extends AbstractAtomMethodQueryParser {
+public class SimpleQueryStringAtomQueryParser extends ParameterizedMethodQueryParser {
 
     private static List<String> SIMPLE_QUERY_STRING_METHOD = ImmutableList.of("simpleQueryString", "simple_query_string");
 
-    public SimpleQueryStringAtomQueryParser(ParseActionListener parseActionListener) {
-        super(parseActionListener);
-    }
-
-    public static Boolean isSimpleQueryStringQuery(SQLMethodInvokeExpr methodQueryExpr) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(SIMPLE_QUERY_STRING_METHOD, methodQueryExpr.getMethodName());
+    @Override
+    public List<String> defineMethodNames() {
+        return SIMPLE_QUERY_STRING_METHOD;
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return false;
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        return isExtraParamsString(invocation.getLastParameterAsString())
+                ? invocation.getLastParameterAsString() : StringUtils.EMPTY;
     }
 
     @Override
-    protected void checkQueryMethod(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        if (Boolean.FALSE == isSimpleQueryStringQuery(methodQueryExpr)) {
-            throw new ElasticSql2DslException(String.format("[syntax error] Expected simpleQueryString query method name is [simpleQueryString],but get [%s]", methodQueryExpr.getMethodName()));
+    protected AtomQuery parseMethodQueryWithExtraParams(MethodInvocation invocation, Map<String, String> extraParamMap) throws ElasticSql2DslException {
+        String queryFields = null;
+        if (invocation.getParameterCount() == 3) {
+            queryFields = invocation.getParameterAsString(1);
+        }
+
+        String text = invocation.getParameterAsString(0);
+        SimpleQueryStringBuilder simpleQueryString = QueryBuilders.simpleQueryStringQuery(text);
+
+        if (StringUtils.isNotBlank(queryFields)) {
+            String[] tArr = queryFields.split(COLON);
+            if ("fields".equalsIgnoreCase(tArr[0])) {
+                for (String fieldItem : tArr[1].split(COMMA)) {
+                    simpleQueryString.field(fieldItem);
+                }
+            }
         }
 
-        int paramCount = methodQueryExpr.getParameters().size();
+        if(MapUtils.isNotEmpty(extraParamMap)) {
+            setExtraMatchQueryParam(simpleQueryString, extraParamMap);
+        }
+
+        return new AtomQuery(simpleQueryString);
+    }
+
+    @Override
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        int paramCount = invocation.getParameterCount();
         if (paramCount != 1 && paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: queryString", paramCount));
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(0);
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false).toString();
+        String text = invocation.getParameterAsString(0);
 
         if (StringUtils.isEmpty(text)) {
             throw new ElasticSql2DslException("[syntax error] Search text can not be blank!");
         }
 
         if (paramCount == 3) {
-            SQLExpr fieldsExpr = methodQueryExpr.getParameters().get(1);
-            String strFields = ElasticSqlArgTransferHelper.transferSqlArg(fieldsExpr, sqlArgs, false).toString();
+            String strFields = invocation.getParameterAsString(1);
 
             if (StringUtils.isEmpty(text)) {
                 throw new ElasticSql2DslException("[syntax error] Search fields can not be empty!");
@@ -75,45 +90,6 @@ public class SimpleQueryStringAtomQueryParser extends AbstractAtomMethodQueryPar
         }
     }
 
-    @Override
-    protected AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(0);
-
-        SQLExpr queryFields = null;
-        SQLExpr extraParamExpr = null;
-
-        if (methodQueryExpr.getParameters().size() == 2) {
-            extraParamExpr = methodQueryExpr.getParameters().get(1);
-        }
-        else if (methodQueryExpr.getParameters().size() == 3) {
-            queryFields = methodQueryExpr.getParameters().get(1);
-            extraParamExpr = methodQueryExpr.getParameters().get(2);
-        }
-
-
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false).toString();
-        SimpleQueryStringBuilder simpleQueryString = QueryBuilders.simpleQueryStringQuery(text);
-
-        if (queryFields != null) {
-            String[] tArr = ElasticSqlArgTransferHelper.transferSqlArg(queryFields, sqlArgs, false).toString().split(COLON);
-            if ("fields".equalsIgnoreCase(tArr[0])) {
-                for (String fieldItem : tArr[1].split(COMMA)) {
-                    simpleQueryString.field(fieldItem);
-                }
-            }
-        }
-
-        Map<String, String> extraParamMap = null;
-        if (extraParamExpr != null) {
-            String extraParam = ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
-            extraParamMap = buildExtraMethodQueryParamsMap(extraParam);
-        }
-
-        setExtraMatchQueryParam(simpleQueryString, extraParamMap);
-
-        return new AtomQuery(simpleQueryString);
-    }
-
     private void setExtraMatchQueryParam(SimpleQueryStringBuilder simpleStringQuery, Map<String, String> extraParamMap) {
         if (MapUtils.isEmpty(extraParamMap)) {
             return;

+ 30 - 36
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/script/ScriptAtomQueryParser.java

@@ -1,18 +1,16 @@
 package org.elasticsearch.dsl.parser.query.method.script;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Maps;
+import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 import org.elasticsearch.dsl.bean.AtomQuery;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
 import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
-import org.elasticsearch.dsl.listener.ParseActionListener;
-import org.elasticsearch.dsl.parser.query.method.AbstractAtomMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
+import org.elasticsearch.dsl.parser.query.method.ParameterizedMethodQueryParser;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.script.Script;
 import org.elasticsearch.script.ScriptService;
@@ -20,56 +18,52 @@ import org.elasticsearch.script.ScriptService;
 import java.util.List;
 import java.util.Map;
 
-public class ScriptAtomQueryParser extends AbstractAtomMethodQueryParser {
+public class ScriptAtomQueryParser extends ParameterizedMethodQueryParser {
 
     private static List<String> SCRIPT_METHOD = ImmutableList.of("script_query", "scriptQuery");
 
-    public ScriptAtomQueryParser(ParseActionListener parseActionListener) {
-        super(parseActionListener);
+    @Override
+    public List<String> defineMethodNames() {
+        return SCRIPT_METHOD;
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(SCRIPT_METHOD, invocation.getMatchQueryExpr().getMethodName());
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 1;
+
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
     }
 
     @Override
-    protected void checkQueryMethod(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        if (Boolean.FALSE == isMatchMethodInvocation(new MethodInvocation(methodQueryExpr, queryAs, sqlArgs))) {
-            throw new ElasticSql2DslException(String.format("[syntax error] Expected script query method name is [script],but get [%s]", methodQueryExpr.getMethodName()));
-        }
-
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount != 1 && paramCount != 2) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: fuzzy", paramCount));
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        if (invocation.getParameterCount() != 1 && invocation.getParameterCount() != 2) {
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLExpr scriptExpr = methodQueryExpr.getParameters().get(0);
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(scriptExpr, sqlArgs, false).toString();
-        if (StringUtils.isEmpty(text)) {
-            throw new ElasticSql2DslException("[syntax error] script can not be blank!");
+        String script = invocation.getParameterAsString(0);
+        if (StringUtils.isEmpty(script)) {
+            throw new ElasticSql2DslException("[syntax error] Script can not be blank!");
         }
     }
 
     @Override
-    protected AtomQuery parseMethodQueryExpr(SQLMethodInvokeExpr methodQueryExpr, String queryAs, Object[] sqlArgs) {
-        String script = (String) ElasticSqlArgTransferHelper.transferSqlArg(methodQueryExpr.getParameters().get(0), sqlArgs, false);
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount == 2) {
-            String scriptParams = (String) ElasticSqlArgTransferHelper.transferSqlArg(methodQueryExpr.getParameters().get(1), sqlArgs, false);
-            Map<String, Object> scriptParamMap = buildScriptParamMap(scriptParams);
+    protected AtomQuery parseMethodQueryWithExtraParams(MethodInvocation invocation, Map<String, String> extraParamMap) throws ElasticSql2DslException {
+        String script = invocation.getParameterAsString(0);
+
+        if (MapUtils.isNotEmpty(extraParamMap)) {
+            Map<String, Object> scriptParamMap = Maps.transformEntries(extraParamMap, new Maps.EntryTransformer<String, String, Object>() {
+                @Override
+                public Object transformEntry(String key, String value) {
+                    return NumberUtils.isNumber(value) ? NumberUtils.createNumber(value) : value;
+                }
+            });
             return new AtomQuery(QueryBuilders.scriptQuery(new Script(script, ScriptService.ScriptType.INLINE, null, scriptParamMap)));
         }
         return new AtomQuery(QueryBuilders.scriptQuery(new Script(script)));
     }
 
-    private Map<String, Object> buildScriptParamMap(String scriptStrParams) {
-        Map<String, String> scriptStrParamMap = buildExtraMethodQueryParamsMap(scriptStrParams);
-        return Maps.transformEntries(scriptStrParamMap, new Maps.EntryTransformer<String, String, Object>() {
-            @Override
-            public Object transformEntry(String key, String value) {
-                return NumberUtils.isNumber(value) ? NumberUtils.createNumber(value) : value;
-            }
-        });
-    }
+
 }

+ 27 - 39
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/FuzzyAtomQueryParser.java

@@ -1,14 +1,11 @@
 package org.elasticsearch.dsl.parser.query.method.term;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.common.unit.Fuzziness;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 import org.elasticsearch.dsl.listener.ParseActionListener;
 import org.elasticsearch.dsl.parser.query.method.AbstractFieldSpecificMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
@@ -21,69 +18,60 @@ import java.util.Map;
 
 public class FuzzyAtomQueryParser extends AbstractFieldSpecificMethodQueryParser {
 
-    private static List<String> FUZZY_QUERY_METHOD = ImmutableList.of("fuzzy", "fuzzy_query", "fuzzyQuery");
+    private static final List<String> FUZZY_QUERY_METHOD = ImmutableList.of("fuzzy", "fuzzy_query", "fuzzyQuery");
 
     public FuzzyAtomQueryParser(ParseActionListener parseActionListener) {
         super(parseActionListener);
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(FUZZY_QUERY_METHOD, invocation.getMatchQueryExpr().getMethodName());
+    public List<String> defineMethodNames() {
+        return FUZZY_QUERY_METHOD;
     }
 
     @Override
-    protected void checkQueryMethod(MethodInvocation invocation) {
+    protected SQLExpr defineFieldExpr(MethodInvocation invocation) {
+        return invocation.getParameter(0);
+    }
 
-        if (Boolean.FALSE == isMatchMethodInvocation(invocation)) {
-            throw new ElasticSql2DslException(
-                    String.format("[syntax error] Expected fuzzy query method name is [fuzzy],but get [%s]",
-                            invocation.getMatchQueryExpr().getMethodName()));
-        }
+    @Override
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 2;
 
-        SQLMethodInvokeExpr methodQueryExpr = invocation.getMatchQueryExpr();
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
+    }
 
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: fuzzy", paramCount));
+    @Override
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) {
+        if (invocation.getParameterCount() != 2 && invocation.getParameterCount() != 3) {
+            throw new ElasticSql2DslException(
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
-
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false).toString();
+        String text = invocation.getParameterAsString(1);
         if (StringUtils.isEmpty(text)) {
-            throw new ElasticSql2DslException("[syntax error] Fuzzy text can not be blank!");
+            throw new ElasticSql2DslException("[syntax error] Fuzzy search text can not be blank!");
         }
-    }
 
-    @Override
-    protected String getExtraParamString(MethodInvocation invocation) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-        if (methodInvokeExpr.getParameters().size() == 3) {
-            SQLExpr extraParamExpr = methodInvokeExpr.getParameters().get(2);
-            Object[] sqlArgs = invocation.getSqlArgs();
-            return ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
+        if (invocation.getParameterCount() == 3) {
+            String extraParamString = defineExtraParamString(invocation);
+            if (StringUtils.isEmpty(extraParamString)) {
+                throw new ElasticSql2DslException("[syntax error] The extra param of fuzzy method can not be blank");
+            }
         }
-        return StringUtils.EMPTY;
     }
 
     @Override
     protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-
-        SQLExpr textExpr = methodInvokeExpr.getParameters().get(1);
-        Object text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false);
-
+        String text = invocation.getParameterAsString(1);
         FuzzyQueryBuilder fuzzyQuery = QueryBuilders.fuzzyQuery(fieldName, text);
+
         setExtraMatchQueryParam(fuzzyQuery, extraParams);
         return fuzzyQuery;
     }
 
-    @Override
-    protected SQLExpr getFieldExpr(MethodInvocation invocation) {
-        return invocation.getMatchQueryExpr().getParameters().get(0);
-    }
-
     private void setExtraMatchQueryParam(FuzzyQueryBuilder fuzzyQuery, Map<String, String> extraParamMap) {
         if (MapUtils.isEmpty(extraParamMap)) {
             return;

+ 28 - 40
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/PrefixAtomQueryParser.java

@@ -1,13 +1,10 @@
 package org.elasticsearch.dsl.parser.query.method.term;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 import org.elasticsearch.dsl.listener.ParseActionListener;
 import org.elasticsearch.dsl.parser.query.method.AbstractFieldSpecificMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
@@ -27,60 +24,51 @@ public class PrefixAtomQueryParser extends AbstractFieldSpecificMethodQueryParse
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(PREFIX_QUERY_METHOD, invocation.getMatchQueryExpr().getMethodName());
+    public List<String> defineMethodNames() {
+        return PREFIX_QUERY_METHOD;
     }
 
     @Override
-    protected String getExtraParamString(MethodInvocation invocation) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-        if (methodInvokeExpr.getParameters().size() == 3) {
-            SQLExpr extraParamExpr = methodInvokeExpr.getParameters().get(2);
-            Object[] sqlArgs = invocation.getSqlArgs();
-            return ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
-        }
-        return StringUtils.EMPTY;
+    protected SQLExpr defineFieldExpr(MethodInvocation invocation) {
+        return invocation.getParameter(0);
     }
 
     @Override
-    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-
-        SQLExpr textExpr = methodInvokeExpr.getParameters().get(1);
-        Object text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false);
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 2;
 
-        PrefixQueryBuilder prefixQuery = QueryBuilders.prefixQuery(fieldName, text.toString());
-
-        setExtraMatchQueryParam(prefixQuery, extraParams);
-        return prefixQuery;
-    }
-
-    @Override
-    protected SQLExpr getFieldExpr(MethodInvocation invocation) {
-        return invocation.getMatchQueryExpr().getParameters().get(0);
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
     }
 
     @Override
-    protected void checkQueryMethod(MethodInvocation invocation) {
-        if (Boolean.FALSE == isMatchMethodInvocation(invocation)) {
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) {
+        if (invocation.getParameterCount() != 2 && invocation.getParameterCount() != 3) {
             throw new ElasticSql2DslException(
-                    String.format("[syntax error] Expected prefix query method name is [prefix],but get [%s]",
-                            invocation.getMatchQueryExpr().getMethodName()));
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLMethodInvokeExpr methodQueryExpr = invocation.getMatchQueryExpr();
+        String text = invocation.getParameterAsString(1);
+        if (StringUtils.isEmpty(text)) {
+            throw new ElasticSql2DslException("[syntax error] Prefix search text can not be blank!");
+        }
 
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: match", paramCount));
+        if (invocation.getParameterCount() == 3) {
+            String extraParamString = defineExtraParamString(invocation);
+            if (StringUtils.isEmpty(extraParamString)) {
+                throw new ElasticSql2DslException("[syntax error] The extra param of prefix method can not be blank");
+            }
         }
+    }
 
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
+    @Override
+    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
+        String text = invocation.getParameterAsString(1);
+        PrefixQueryBuilder prefixQuery = QueryBuilders.prefixQuery(fieldName, text);
 
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false).toString();
-        if (StringUtils.isEmpty(text)) {
-            throw new ElasticSql2DslException("[syntax error] Prefix text can not be blank!");
-        }
+        setExtraMatchQueryParam(prefixQuery, extraParams);
+        return prefixQuery;
     }
 
     private void setExtraMatchQueryParam(PrefixQueryBuilder prefixQuery, Map<String, String> extraParamMap) {

+ 30 - 39
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/RegexpAtomQueryParser.java

@@ -1,14 +1,11 @@
 package org.elasticsearch.dsl.parser.query.method.term;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 import org.elasticsearch.dsl.listener.ParseActionListener;
 import org.elasticsearch.dsl.parser.query.method.AbstractFieldSpecificMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
@@ -29,61 +26,55 @@ public class RegexpAtomQueryParser extends AbstractFieldSpecificMethodQueryParse
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(REGEXP_QUERY_METHOD, invocation.getMatchQueryExpr().getMethodName());
+    public List<String> defineMethodNames() {
+        return REGEXP_QUERY_METHOD;
     }
 
     @Override
-    protected String getExtraParamString(MethodInvocation invocation) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-        if (methodInvokeExpr.getParameters().size() == 3) {
-            SQLExpr extraParamExpr = methodInvokeExpr.getParameters().get(2);
-            Object[] sqlArgs = invocation.getSqlArgs();
-            return ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
-        }
-        return StringUtils.EMPTY;
+    protected SQLExpr defineFieldExpr(MethodInvocation invocation) {
+        return invocation.getParameter(0);
     }
 
     @Override
-    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-
-        SQLExpr textExpr = methodInvokeExpr.getParameters().get(1);
-        Object text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false);
-
-        RegexpQueryBuilder regexpQuery = QueryBuilders.regexpQuery(fieldName, text.toString());
-        setExtraMatchQueryParam(regexpQuery, extraParams);
-        return regexpQuery;
-    }
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 2;
 
-    @Override
-    protected SQLExpr getFieldExpr(MethodInvocation invocation) {
-        return invocation.getMatchQueryExpr().getParameters().get(0);
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
     }
 
     @Override
-    protected void checkQueryMethod(MethodInvocation invocation) throws ElasticSql2DslException {
-        if (Boolean.FALSE == isMatchMethodInvocation(invocation)) {
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        if (invocation.getParameterCount() != 2 && invocation.getParameterCount() != 3) {
             throw new ElasticSql2DslException(
-                    String.format("[syntax error] Expected regexp query method name is [regexp],but get [%s]",
-                            invocation.getMatchQueryExpr().getMethodName()));
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLMethodInvokeExpr methodQueryExpr = invocation.getMatchQueryExpr();
+        String text = invocation.getParameterAsString(1);
+        if (StringUtils.isEmpty(text)) {
+            throw new ElasticSql2DslException("[syntax error] Regexp search text can not be blank!");
+        }
 
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: regexp", paramCount));
+        if (invocation.getParameterCount() == 3) {
+            String extraParamString = defineExtraParamString(invocation);
+            if (StringUtils.isEmpty(extraParamString)) {
+                throw new ElasticSql2DslException("[syntax error] The extra param of regexp method can not be blank");
+            }
         }
+    }
 
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
+    @Override
+    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
+        String text = invocation.getParameterAsString(1);
+        RegexpQueryBuilder regexpQuery = QueryBuilders.regexpQuery(fieldName, text);
 
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false).toString();
-        if (StringUtils.isEmpty(text)) {
-            throw new ElasticSql2DslException("[syntax error] Regexp text can not be blank!");
-        }
+        setExtraMatchQueryParam(regexpQuery, extraParams);
+        return regexpQuery;
     }
 
+
+
     private void setExtraMatchQueryParam(RegexpQueryBuilder regexpQuery, Map<String, String> extraParamMap) {
         if (MapUtils.isEmpty(extraParamMap)) {
             return;

+ 29 - 41
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/TermAtomQueryParser.java

@@ -1,13 +1,10 @@
 package org.elasticsearch.dsl.parser.query.method.term;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 import org.elasticsearch.dsl.listener.ParseActionListener;
 import org.elasticsearch.dsl.parser.query.method.AbstractFieldSpecificMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
@@ -27,62 +24,53 @@ public class TermAtomQueryParser extends AbstractFieldSpecificMethodQueryParser
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(TERM_QUERY_METHOD, invocation.getMatchQueryExpr().getMethodName());
+    public List<String> defineMethodNames() {
+        return TERM_QUERY_METHOD;
     }
 
     @Override
-    protected String getExtraParamString(MethodInvocation invocation) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-        if (methodInvokeExpr.getParameters().size() == 3) {
-            SQLExpr extraParamExpr = methodInvokeExpr.getParameters().get(2);
-            Object[] sqlArgs = invocation.getSqlArgs();
-            return ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
-        }
-        return StringUtils.EMPTY;
+    protected SQLExpr defineFieldExpr(MethodInvocation invocation) {
+        return invocation.getParameter(0);
     }
 
     @Override
-    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-
-        SQLExpr textExpr = methodInvokeExpr.getParameters().get(1);
-        Object text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false);
-
-        TermQueryBuilder termQuery = QueryBuilders.termQuery(fieldName, text);
-        setExtraMatchQueryParam(termQuery, extraParams);
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 2;
 
-        return termQuery;
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
     }
 
     @Override
-    protected SQLExpr getFieldExpr(MethodInvocation invocation) {
-        return invocation.getMatchQueryExpr().getParameters().get(0);
-    }
-
-    @Override
-    protected void checkQueryMethod(MethodInvocation invocation) throws ElasticSql2DslException {
-        if (!isMatchMethodInvocation(invocation)) {
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        if (invocation.getParameterCount() != 2 && invocation.getParameterCount() != 3) {
             throw new ElasticSql2DslException(
-                    String.format("[syntax error] Expected term query method name is [term],but get [%s]",
-                            invocation.getMatchQueryExpr().getMethodName()));
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLMethodInvokeExpr methodCallExpr = invocation.getMatchQueryExpr();
-
-        int paramCount = methodCallExpr.getParameters().size();
-        if (paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: term", paramCount));
+        String text = invocation.getParameterAsString(1);
+        if (StringUtils.isEmpty(text)) {
+            throw new ElasticSql2DslException("[syntax error] Term search text can not be blank!");
         }
 
-        SQLExpr textExpr = methodCallExpr.getParameters().get(1);
-
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false).toString();
-        if (StringUtils.isEmpty(text)) {
-            throw new ElasticSql2DslException("[syntax error] Term text can not be blank!");
+        if (invocation.getParameterCount() == 3) {
+            String extraParamString = defineExtraParamString(invocation);
+            if (StringUtils.isEmpty(extraParamString)) {
+                throw new ElasticSql2DslException("[syntax error] The extra param of term method can not be blank");
+            }
         }
     }
 
+    @Override
+    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
+        String text = invocation.getParameterAsString(1);
+
+        TermQueryBuilder termQuery = QueryBuilders.termQuery(fieldName, text);
+        setExtraMatchQueryParam(termQuery, extraParams);
+
+        return termQuery;
+    }
 
     private void setExtraMatchQueryParam(TermQueryBuilder termQuery, Map<String, String> extraParamMap) {
         if (MapUtils.isEmpty(extraParamMap)) {

+ 1 - 1
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/TermLevelAtomQueryParser.java

@@ -48,6 +48,6 @@ public class TermLevelAtomQueryParser {
         }
         throw new ElasticSql2DslException(
                 String.format("[syntax error] Can not support method query expr[%s] condition",
-                        methodInvocation.getMatchQueryExpr().getMethodName()));
+                        methodInvocation.getMethodName()));
     }
 }

+ 18 - 40
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/TermsAtomQueryParser.java

@@ -1,14 +1,11 @@
 package org.elasticsearch.dsl.parser.query.method.term;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 import org.elasticsearch.dsl.listener.ParseActionListener;
 import org.elasticsearch.dsl.parser.query.method.AbstractFieldSpecificMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
@@ -28,17 +25,18 @@ public class TermsAtomQueryParser extends AbstractFieldSpecificMethodQueryParser
     }
 
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(TERMS_QUERY_METHOD, invocation.getMatchQueryExpr().getMethodName());
+    public List<String> defineMethodNames() {
+        return TERMS_QUERY_METHOD;
     }
 
     @Override
-    protected String getExtraParamString(MethodInvocation invocation) {
-        int paramCount = invocation.getMatchQueryExpr().getParameters().size();
-        SQLExpr lastParam = invocation.getMatchQueryExpr().getParameters().get(paramCount - 1);
-
-        String extraParamString = ElasticSqlArgTransferHelper.transferSqlArg(lastParam, invocation.getSqlArgs(), false).toString();
+    protected SQLExpr defineFieldExpr(MethodInvocation invocation) {
+        return invocation.getParameter(0);
+    }
 
+    @Override
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        String extraParamString = invocation.getLastParameterAsString();
         if (isExtraParamsString(extraParamString)) {
             return extraParamString;
         }
@@ -46,24 +44,17 @@ public class TermsAtomQueryParser extends AbstractFieldSpecificMethodQueryParser
     }
 
     @Override
-    protected void checkQueryMethod(MethodInvocation invocation) {
-        if (Boolean.FALSE == isMatchMethodInvocation(invocation)) {
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) {
+        if (invocation.getParameterCount() <= 1) {
             throw new ElasticSql2DslException(
-                    String.format("[syntax error] Expected terms query method name is [terms],but get [%s]",
-                            invocation.getMatchQueryExpr().getMethodName()));
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLMethodInvokeExpr methodQueryExpr = invocation.getMatchQueryExpr();
-
-        int paramCount = invocation.getMatchQueryExpr().getParameters().size();
-        if (paramCount <= 1) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: term", paramCount));
-        }
+        int paramCount = invocation.getParameterCount();
 
         for (int idx = 1; idx < paramCount - 1; idx++) {
-            SQLExpr textExpr = methodQueryExpr.getParameters().get(idx);
-
-            String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false).toString();
+            String text = invocation.getParameterAsString(idx);
             if (StringUtils.isEmpty(text)) {
                 throw new ElasticSql2DslException("[syntax error] Terms text can not be blank!");
             }
@@ -72,24 +63,16 @@ public class TermsAtomQueryParser extends AbstractFieldSpecificMethodQueryParser
 
     @Override
     protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
-
-        SQLMethodInvokeExpr methodQueryExpr = invocation.getMatchQueryExpr();
-        Object[] sqlArgs = invocation.getSqlArgs();
-
-        int paramCount = methodQueryExpr.getParameters().size();
+        int paramCount = invocation.getParameterCount();
 
         List<String> termTextList = Lists.newArrayList();
         for (int idx = 1; idx < paramCount - 1; idx++) {
-            SQLExpr textExpr = methodQueryExpr.getParameters().get(idx);
-            String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, sqlArgs, false).toString();
+            String text = invocation.getParameterAsString(idx);
             termTextList.add(text);
         }
 
-
-        SQLExpr lastParam = methodQueryExpr.getParameters().get(paramCount - 1);
-        String lastParamText = ElasticSqlArgTransferHelper.transferSqlArg(lastParam, sqlArgs, false).toString();
-
-        if (Boolean.FALSE == isExtraParamsString(lastParamText)) {
+        String lastParamText = invocation.getLastParameterAsString();
+        if (!isExtraParamsString(lastParamText)) {
             termTextList.add(lastParamText);
         }
 
@@ -98,11 +81,6 @@ public class TermsAtomQueryParser extends AbstractFieldSpecificMethodQueryParser
         return termsQuery;
     }
 
-    @Override
-    protected SQLExpr getFieldExpr(MethodInvocation invocation) {
-        return invocation.getMatchQueryExpr().getParameters().get(0);
-    }
-
     private void setExtraMatchQueryParam(TermsQueryBuilder termsQuery, Map<String, String> extraParamMap) {
         if (MapUtils.isEmpty(extraParamMap)) {
             return;

+ 28 - 40
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/query/method/term/WildcardAtomQueryParser.java

@@ -1,13 +1,10 @@
 package org.elasticsearch.dsl.parser.query.method.term;
 
 import com.alibaba.druid.sql.ast.SQLExpr;
-import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 import org.elasticsearch.dsl.exception.ElasticSql2DslException;
-import org.elasticsearch.dsl.helper.ElasticSqlArgTransferHelper;
-import org.elasticsearch.dsl.helper.ElasticSqlMethodInvokeHelper;
 import org.elasticsearch.dsl.listener.ParseActionListener;
 import org.elasticsearch.dsl.parser.query.method.AbstractFieldSpecificMethodQueryParser;
 import org.elasticsearch.dsl.parser.query.method.MethodInvocation;
@@ -26,61 +23,52 @@ public class WildcardAtomQueryParser extends AbstractFieldSpecificMethodQueryPar
         super(parseActionListener);
     }
 
-
     @Override
-    public boolean isMatchMethodInvocation(MethodInvocation invocation) {
-        return ElasticSqlMethodInvokeHelper.isMethodOf(WILDCARD_QUERY_METHOD, invocation.getMatchQueryExpr().getMethodName());
+    public List<String> defineMethodNames() {
+        return WILDCARD_QUERY_METHOD;
     }
 
     @Override
-    protected String getExtraParamString(MethodInvocation invocation) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-        if (methodInvokeExpr.getParameters().size() == 3) {
-            SQLExpr extraParamExpr = methodInvokeExpr.getParameters().get(2);
-            Object[] sqlArgs = invocation.getSqlArgs();
-            return ElasticSqlArgTransferHelper.transferSqlArg(extraParamExpr, sqlArgs, false).toString();
-        }
-        return StringUtils.EMPTY;
-    }
+    protected String defineExtraParamString(MethodInvocation invocation) {
+        int extraParamIdx = 2;
 
-    @Override
-    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
-        SQLMethodInvokeExpr methodInvokeExpr = invocation.getMatchQueryExpr();
-
-        SQLExpr textExpr = methodInvokeExpr.getParameters().get(1);
-        Object text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false);
-
-        WildcardQueryBuilder wildcardQuery = QueryBuilders.wildcardQuery(fieldName, text.toString());
-        setExtraMatchQueryParam(wildcardQuery, extraParams);
-        return wildcardQuery;
+        return (invocation.getParameterCount() == extraParamIdx + 1)
+                ? invocation.getParameterAsString(extraParamIdx) : StringUtils.EMPTY;
     }
 
     @Override
-    protected SQLExpr getFieldExpr(MethodInvocation invocation) {
-        return invocation.getMatchQueryExpr().getParameters().get(0);
+    protected SQLExpr defineFieldExpr(MethodInvocation invocation) {
+        return invocation.getParameter(0);
     }
 
     @Override
-    protected void checkQueryMethod(MethodInvocation invocation) throws ElasticSql2DslException {
-        if (Boolean.FALSE == isMatchMethodInvocation(invocation)) {
+    protected void checkMethodInvokeArgs(MethodInvocation invocation) throws ElasticSql2DslException {
+        if (invocation.getParameterCount() != 2 && invocation.getParameterCount() != 3) {
             throw new ElasticSql2DslException(
-                    String.format("[syntax error] Expected wildcard query method name is [wildcard],but get [%s]",
-                            invocation.getMatchQueryExpr().getMethodName()));
+                    String.format("[syntax error] There's no %s args method named [%s].",
+                            invocation.getParameterCount(), invocation.getMethodName()));
         }
 
-        SQLMethodInvokeExpr methodQueryExpr = invocation.getMatchQueryExpr();
+        String text = invocation.getParameterAsString(1);
+        if (StringUtils.isEmpty(text)) {
+            throw new ElasticSql2DslException("[syntax error] Wildcard search text can not be blank!");
+        }
 
-        int paramCount = methodQueryExpr.getParameters().size();
-        if (paramCount != 2 && paramCount != 3) {
-            throw new ElasticSql2DslException(String.format("[syntax error] There's no %s args method: wildcard", paramCount));
+        if (invocation.getParameterCount() == 3) {
+            String extraParamString = defineExtraParamString(invocation);
+            if (StringUtils.isEmpty(extraParamString)) {
+                throw new ElasticSql2DslException("[syntax error] The extra param of wildcard method can not be blank");
+            }
         }
+    }
 
-        SQLExpr textExpr = methodQueryExpr.getParameters().get(1);
+    @Override
+    protected QueryBuilder buildQuery(MethodInvocation invocation, String fieldName, Map<String, String> extraParams) {
+        String text = invocation.getParameterAsString(1);
+        WildcardQueryBuilder wildcardQuery = QueryBuilders.wildcardQuery(fieldName, text);
 
-        String text = ElasticSqlArgTransferHelper.transferSqlArg(textExpr, invocation.getSqlArgs(), false).toString();
-        if (StringUtils.isEmpty(text)) {
-            throw new ElasticSql2DslException("[syntax error] Wildcard text can not be blank!");
-        }
+        setExtraMatchQueryParam(wildcardQuery, extraParams);
+        return wildcardQuery;
     }
 
     private void setExtraMatchQueryParam(WildcardQueryBuilder wildcardQuery, Map<String, String> extraParamMap) {

+ 3 - 2
elasticsearch-query-core/src/main/java/org/elasticsearch/dsl/parser/sql/AbstractQueryConditionParser.java

@@ -35,11 +35,12 @@ public abstract class AbstractQueryConditionParser implements QueryParser {
 
     public AbstractQueryConditionParser(ParseActionListener parseActionListener) {
         termLevelAtomQueryParser = new TermLevelAtomQueryParser(parseActionListener);
-        scriptAtomQueryParser = new ScriptAtomQueryParser(parseActionListener);
         fullTextAtomQueryParser = new FullTextAtomQueryParser(parseActionListener);
         binaryQueryParser = new BinaryAtomQueryParser(parseActionListener);
         inListQueryParser = new InListAtomQueryParser(parseActionListener);
         betweenAndQueryParser = new BetweenAndAtomQueryParser(parseActionListener);
+
+        scriptAtomQueryParser = new ScriptAtomQueryParser();
     }
 
     protected BoolQueryBuilder parseQueryConditionExpr(SQLExpr conditionExpr, String queryAs, Object[] sqlArgs) {
@@ -97,7 +98,7 @@ public abstract class AbstractQueryConditionParser implements QueryParser {
                 return scriptAtomQueryParser.parseAtomMethodQuery(methodInvocation);
             }
 
-            if (fullTextAtomQueryParser.isFulltextAtomQuery(methodQueryExpr)) {
+            if (fullTextAtomQueryParser.isFulltextAtomQuery(methodInvocation)) {
                 return fullTextAtomQueryParser.parseFullTextAtomQuery(methodQueryExpr, queryAs, sqlArgs);
             }
 

+ 1 - 1
elasticsearch-query-core/src/test/java/org/elasticsearch/query/SqlParserWhereConditionTest.java

@@ -264,7 +264,7 @@ public class SqlParserWhereConditionTest {
 
     @Test
     public void testMatchQuery() throws Exception {
-        String sql = "select * from index query term(name, 'abc', 'boost:2.0f') and term(code, '123')";
+        String sql = "select * from index where term(name, 'abc', 'boost:2.0f') and term(code, '123')";
         ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser();
         ElasticSqlParseResult parseResult = sql2DslParser.parse(sql);
         System.out.println(parseResult.toDsl());

+ 4 - 4
elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserLimitTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="3" failures="0" name="org.elasticsearch.query.SqlParserLimitTest" time="1.181" errors="0" skipped="0">
+<testsuite tests="3" failures="0" name="org.elasticsearch.query.SqlParserLimitTest" time="0.98" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,7 +61,7 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testParseLimitExprWithArgs" time="1.015"/>
-  <testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testX" time="0.009"/>
-  <testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testParseLimitExpr" time="0.002"/>
+  <testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testParseLimitExprWithArgs" time="0.806"/>
+  <testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testX" time="0.082"/>
+  <testcase classname="org.elasticsearch.query.SqlParserLimitTest" name="testParseLimitExpr" time="0.001"/>
 </testsuite>

+ 2 - 2
elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserListenerTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="1" failures="0" name="org.elasticsearch.query.SqlParserListenerTest" time="0.067" errors="0" skipped="0">
+<testsuite tests="1" failures="0" name="org.elasticsearch.query.SqlParserListenerTest" time="0.015" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,5 +61,5 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.query.SqlParserListenerTest" name="testParseActionListener" time="0.065"/>
+  <testcase classname="org.elasticsearch.query.SqlParserListenerTest" name="testParseActionListener" time="0.014"/>
 </testsuite>

+ 2 - 2
elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserOrderByTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="1" failures="0" name="org.elasticsearch.query.SqlParserOrderByTest" time="0.006" errors="0" skipped="0">
+<testsuite tests="1" failures="0" name="org.elasticsearch.query.SqlParserOrderByTest" time="0.009" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,5 +61,5 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.query.SqlParserOrderByTest" name="testParseEqExpr" time="0.006"/>
+  <testcase classname="org.elasticsearch.query.SqlParserOrderByTest" name="testParseEqExpr" time="0.008"/>
 </testsuite>

+ 10 - 10
elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserQueryTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="10" failures="0" name="org.elasticsearch.query.SqlParserQueryTest" time="0.046" errors="0" skipped="0">
+<testsuite tests="10" failures="0" name="org.elasticsearch.query.SqlParserQueryTest" time="0.035" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,14 +61,14 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseTermsQueryExpr" time="0.005"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseFuzzyQueryExpr" time="0.008"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseWildcardQueryExpr" time="0.001"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseMultiMatchQueryExpr" time="0.002"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseTermQueryExpr" time="0.001"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseSimpleQueryStringQueryExpr" time="0.009"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseQueryStringQueryExpr" time="0.002"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParsePrefixQueryExpr" time="0.001"/>
-  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseRegexpQueryExpr" time="0.007"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseTermsQueryExpr" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseFuzzyQueryExpr" time="0.006"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseWildcardQueryExpr" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseMultiMatchQueryExpr" time="0.004"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseTermQueryExpr" time="0.007"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseSimpleQueryStringQueryExpr" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseQueryStringQueryExpr" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParsePrefixQueryExpr" time="0.003"/>
+  <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseRegexpQueryExpr" time="0.003"/>
   <testcase classname="org.elasticsearch.query.SqlParserQueryTest" name="testParseMatchQueryExpr" time="0.004"/>
 </testsuite>

+ 2 - 2
elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserRoutingTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="2" failures="0" name="org.elasticsearch.query.SqlParserRoutingTest" time="0.002" errors="0" skipped="0">
+<testsuite tests="2" failures="0" name="org.elasticsearch.query.SqlParserRoutingTest" time="0.01" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -62,5 +62,5 @@
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
   <testcase classname="org.elasticsearch.query.SqlParserRoutingTest" name="testParseRoutingExprWithArgs" time="0"/>
-  <testcase classname="org.elasticsearch.query.SqlParserRoutingTest" name="testParseRoutingExpr" time="0.001"/>
+  <testcase classname="org.elasticsearch.query.SqlParserRoutingTest" name="testParseRoutingExpr" time="0.01"/>
 </testsuite>

+ 5 - 5
elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserSelectFieldTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="6" failures="0" name="org.elasticsearch.query.SqlParserSelectFieldTest" time="0.024" errors="0" skipped="0">
+<testsuite tests="6" failures="0" name="org.elasticsearch.query.SqlParserSelectFieldTest" time="0.015" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,10 +61,10 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testParseDefaultLimit" time="0.013"/>
-  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testInnerDocField" time="0.001"/>
+  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testParseDefaultLimit" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testInnerDocField" time="0.014"/>
   <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testParseFromSource" time="0"/>
   <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testParseOriSelectField" time="0"/>
-  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testNestedDocField" time="0.004"/>
-  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testSelectAllField" time="0.002"/>
+  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testNestedDocField" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserSelectFieldTest" name="testSelectAllField" time="0"/>
 </testsuite>

+ 7 - 7
elasticsearch-query-core/target/surefire-reports/TEST-org.elasticsearch.query.SqlParserWhereConditionTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="8" failures="0" name="org.elasticsearch.query.SqlParserWhereConditionTest" time="0.056" errors="0" skipped="1">
+<testsuite tests="8" failures="0" name="org.elasticsearch.query.SqlParserWhereConditionTest" time="0.044" errors="0" skipped="1">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,13 +61,13 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testParseEqExpr" time="0.012"/>
-  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testParseGtExpr" time="0.015"/>
-  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testParseDateExpr" time="0.021"/>
-  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="test$Expr" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testParseEqExpr" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testParseGtExpr" time="0.016"/>
+  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testParseDateExpr" time="0.012"/>
+  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="test$Expr" time="0.01"/>
   <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testCreateSearchDsl" time="0"/>
-  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testMatchQuery" time="0.001"/>
-  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testNotExpr" time="0.004"/>
+  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testMatchQuery" time="0"/>
+  <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testNotExpr" time="0.003"/>
   <testcase classname="org.elasticsearch.query.SqlParserWhereConditionTest" name="testCreateAggDsl" time="0.004">
     <skipped/>
   </testcase>

+ 1 - 1
elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserLimitTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.query.SqlParserLimitTest
 -------------------------------------------------------------------------------
-Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.182 sec
+Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.981 sec

+ 1 - 1
elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserListenerTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.query.SqlParserListenerTest
 -------------------------------------------------------------------------------
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.067 sec
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec

+ 1 - 1
elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserOrderByTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.query.SqlParserOrderByTest
 -------------------------------------------------------------------------------
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.007 sec
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.009 sec

+ 1 - 1
elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserQueryTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.query.SqlParserQueryTest
 -------------------------------------------------------------------------------
-Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec
+Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.035 sec

+ 1 - 1
elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserRoutingTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.query.SqlParserRoutingTest
 -------------------------------------------------------------------------------
-Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
+Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 sec

+ 1 - 1
elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserSelectFieldTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.query.SqlParserSelectFieldTest
 -------------------------------------------------------------------------------
-Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.024 sec
+Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.014 sec

+ 1 - 1
elasticsearch-query-core/target/surefire-reports/org.elasticsearch.query.SqlParserWhereConditionTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.query.SqlParserWhereConditionTest
 -------------------------------------------------------------------------------
-Tests run: 8, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.056 sec
+Tests run: 8, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.043 sec

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractConnection.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.*;
 import java.util.Properties;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractDataSource.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import javax.sql.DataSource;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractDriverBasedDataSource.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.Connection;
 import java.sql.SQLException;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedConnection.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import java.sql.*;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedPreparedStatement.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import java.io.InputStream;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedResultSet.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import java.io.InputStream;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractFeatureNotSupportedStatement.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import java.sql.*;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractResultSet.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.SQLException;
 import java.sql.SQLWarning;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/AbstractStatement.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ConnectionProxy.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.Connection;
 

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/DriverManagerDataSource.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import java.sql.Connection;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticConnection.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import org.elasticsearch.client.Client;
 

+ 2 - 2
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticDatabaseMetaData.java

@@ -1,10 +1,10 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.*;
 
 public class ElasticDatabaseMetaData implements DatabaseMetaData {
 
-    private static final String ELASTIC_DRIVER_NAME = "org.elasticsearch.jdbc.api.ElasticDriver";
+    private static final String ELASTIC_DRIVER_NAME = "ElasticDriver";
     private static final String ELASTIC_DRIVER_PRODUCT_VERSION = "2.4.4";
     private static final Integer ELASTIC_DRIVER_PRODUCT_MAJOR_VERSION = 2;
     private static final Integer ELASTIC_DRIVER_PRODUCT_MINOR_VERSION = 4;

+ 4 - 4
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticDriver.java

@@ -1,8 +1,8 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
-import org.elasticsearch.jdbc.es.ElasticClientProvider;
-import org.elasticsearch.jdbc.es.ElasticClientProxy;
-import org.elasticsearch.jdbc.es.ElasticClientProxyProviderImpl;
+import org.elasticsearch.es.ElasticClientProvider;
+import org.elasticsearch.es.ElasticClientProxy;
+import org.elasticsearch.es.ElasticClientProxyProviderImpl;
 
 import java.sql.*;
 import java.util.Properties;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticPreparedStatement.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Lists;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticResultSet.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticResultSetMetaData.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;

+ 2 - 3
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticSingleConnectionDataSource.java

@@ -1,8 +1,8 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import org.elasticsearch.client.Client;
-import org.elasticsearch.jdbc.es.ElasticClientProvider;
+import org.elasticsearch.es.ElasticClientProvider;
 import org.elasticsearch.utils.Logger;
 
 import java.lang.reflect.InvocationHandler;
@@ -212,5 +212,4 @@ public class ElasticSingleConnectionDataSource extends DriverManagerDataSource i
     public void setAutoCommit(boolean autoCommit) {
         // ignore
     }
-
 }

+ 3 - 3
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/ElasticStatement.java

@@ -1,11 +1,11 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.dsl.bean.ElasticSqlParseResult;
 import org.elasticsearch.dsl.parser.ElasticSql2DslParser;
-import org.elasticsearch.jdbc.es.JdbcSearchActionExecutor;
-import org.elasticsearch.jdbc.es.JdbcSearchResponseExtractor;
+import org.elasticsearch.es.JdbcSearchActionExecutor;
+import org.elasticsearch.es.JdbcSearchResponseExtractor;
 
 import java.sql.Connection;
 import java.sql.ResultSet;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/api/SmartDataSource.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.api;
+package org.elasticsearch.api;
 
 
 import javax.sql.DataSource;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/ElasticClientProvider.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.es;
+package org.elasticsearch.es;
 
 import org.elasticsearch.client.Client;
 

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/ElasticClientProxy.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.es;
+package org.elasticsearch.es;
 
 import org.elasticsearch.client.Client;
 

+ 2 - 2
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/ElasticClientProxyProviderImpl.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.es;
+package org.elasticsearch.es;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -6,7 +6,7 @@ import org.elasticsearch.client.Client;
 import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.transport.InetSocketTransportAddress;
-import org.elasticsearch.jdbc.exception.BuildElasticClientException;
+import org.elasticsearch.exception.BuildElasticClientException;
 import org.elasticsearch.utils.Constants;
 
 import java.lang.reflect.InvocationHandler;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchActionExecutor.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.es;
+package org.elasticsearch.es;
 
 import org.elasticsearch.action.*;
 import org.elasticsearch.utils.Logger;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchResponse.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.es;
+package org.elasticsearch.es;
 
 import com.google.gson.Gson;
 

+ 2 - 2
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchResponseExtractor.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.es;
+package org.elasticsearch.es;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -25,7 +25,7 @@ public class JdbcSearchResponseExtractor {
     public String extractSearchResponse(SearchResponse searchResponse) {
         JdbcSearchResponse<String> jdbcSearchResponse = null;
 
-        if (Boolean.TRUE == isAggregationResponse(searchResponse)) {
+        if (isAggregationResponse(searchResponse)) {
             jdbcSearchResponse = extractAggregationResult(searchResponse);
         }
         else {

+ 2 - 2
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/es/JdbcSearchResponseResolver.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.es;
+package org.elasticsearch.es;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Lists;
@@ -7,7 +7,7 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.jdbc.exception.ResolveSearchResponseException;
+import org.elasticsearch.exception.ResolveSearchResponseException;
 import org.elasticsearch.utils.Constants;
 
 import java.util.Collections;

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/exception/BuildElasticClientException.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.exception;
+package org.elasticsearch.exception;
 
 
 public class BuildElasticClientException extends RuntimeException {

+ 1 - 1
elasticsearch-query-jdbc/src/main/java/org/elasticsearch/jdbc/exception/ResolveSearchResponseException.java

@@ -1,4 +1,4 @@
-package org.elasticsearch.jdbc.exception;
+package org.elasticsearch.exception;
 
 
 public class ResolveSearchResponseException extends RuntimeException {

+ 1 - 1
elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/BaseJdbcTest.java

@@ -1,6 +1,6 @@
 package org.elasticsearch.jdbc;
 
 public class BaseJdbcTest {
-    protected static final String driver = "org.elasticsearch.jdbc.api.ElasticDriver";
+    protected static final String driver = "org.elasticsearch.api.ElasticDriver";
     protected static final String url = "jdbc:elastic:192.168.0.109:9300/lu-search-cluster";
 }

+ 4 - 4
elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/ElasticDriverTest.java

@@ -1,11 +1,11 @@
 package org.elasticsearch.jdbc;
 
 
-import org.elasticsearch.jdbc.api.ElasticConnection;
-import org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource;
+import org.elasticsearch.api.ElasticConnection;
+import org.elasticsearch.api.ElasticSingleConnectionDataSource;
 import org.elasticsearch.jdbc.bean.Product;
-import org.elasticsearch.jdbc.es.JdbcSearchResponse;
-import org.elasticsearch.jdbc.es.JdbcSearchResponseResolver;
+import org.elasticsearch.es.JdbcSearchResponse;
+import org.elasticsearch.es.JdbcSearchResponseResolver;
 import org.junit.Test;
 
 import java.sql.*;

+ 3 - 3
elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/GroupByTest.java

@@ -1,10 +1,10 @@
 package org.elasticsearch.jdbc;
 
 
-import org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource;
+import org.elasticsearch.api.ElasticSingleConnectionDataSource;
+import org.elasticsearch.es.JdbcSearchResponse;
 import org.elasticsearch.jdbc.bean.ProductAggResult;
-import org.elasticsearch.jdbc.es.JdbcSearchResponse;
-import org.elasticsearch.jdbc.es.JdbcSearchResponseResolver;
+import org.elasticsearch.es.JdbcSearchResponseResolver;
 import org.junit.Test;
 
 import java.sql.Connection;

+ 3 - 3
elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/MethodQueryTest.java

@@ -1,10 +1,10 @@
 package org.elasticsearch.jdbc;
 
 
-import org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource;
+import org.elasticsearch.es.JdbcSearchResponse;
+import org.elasticsearch.api.ElasticSingleConnectionDataSource;
 import org.elasticsearch.jdbc.bean.Product;
-import org.elasticsearch.jdbc.es.JdbcSearchResponse;
-import org.elasticsearch.jdbc.es.JdbcSearchResponseResolver;
+import org.elasticsearch.es.JdbcSearchResponseResolver;
 import org.junit.Test;
 
 import java.sql.Connection;

+ 3 - 10
elasticsearch-query-jdbc/src/test/java/org/elasticsearch/jdbc/ScriptQueryTest.java

@@ -1,10 +1,10 @@
 package org.elasticsearch.jdbc;
 
 
-import org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource;
+import org.elasticsearch.api.ElasticSingleConnectionDataSource;
 import org.elasticsearch.jdbc.bean.Product;
-import org.elasticsearch.jdbc.es.JdbcSearchResponse;
-import org.elasticsearch.jdbc.es.JdbcSearchResponseResolver;
+import org.elasticsearch.es.JdbcSearchResponse;
+import org.elasticsearch.es.JdbcSearchResponseResolver;
 import org.junit.Test;
 
 import java.sql.Connection;
@@ -32,12 +32,5 @@ public class ScriptQueryTest extends BaseJdbcTest {
         for (Product product : jdbcSearchResponse.getResultList()) {
             System.out.println(String.format("productName:%s, minPrice:%s, advicePrice:%s", product.getProductName(), product.getMinPrice(), product.getAdvicePrice()));
         }
-
-
-//        sql = "";
-//        ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser();
-//        ElasticSqlParseResult parseResult = sql2DslParser.parse(sql);
-//        String dsl = parseResult.toDsl();
-//        System.out.println(dsl);
     }
 }

+ 5 - 5
elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.ElasticDriverTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="5" failures="0" name="org.elasticsearch.jdbc.ElasticDriverTest" time="5.601" errors="0" skipped="0">
+<testsuite tests="5" failures="0" name="org.elasticsearch.jdbc.ElasticDriverTest" time="2.979" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,9 +61,9 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testLoadDriver" time="0.133"/>
-  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testQuery" time="5.243"/>
-  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testDataSource" time="0.004"/>
+  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testLoadDriver" time="0.106"/>
+  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testQuery" time="2.751"/>
+  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testDataSource" time="0"/>
   <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testGetConnection" time="0"/>
-  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testQuery2" time="0.043"/>
+  <testcase classname="org.elasticsearch.jdbc.ElasticDriverTest" name="testQuery2" time="0.017"/>
 </testsuite>

+ 2 - 2
elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.GroupByTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="1" failures="0" name="org.elasticsearch.jdbc.GroupByTest" time="0.05" errors="0" skipped="0">
+<testsuite tests="1" failures="0" name="org.elasticsearch.jdbc.GroupByTest" time="0.226" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,5 +61,5 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.jdbc.GroupByTest" name="testGroupBy" time="0.049"/>
+  <testcase classname="org.elasticsearch.jdbc.GroupByTest" name="testGroupBy" time="0.226"/>
 </testsuite>

+ 2 - 2
elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.MethodQueryTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="1" failures="0" name="org.elasticsearch.jdbc.MethodQueryTest" time="0.034" errors="0" skipped="0">
+<testsuite tests="1" failures="0" name="org.elasticsearch.jdbc.MethodQueryTest" time="0.05" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,5 +61,5 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.jdbc.MethodQueryTest" name="testPrefixAndNestedQuery" time="0.033"/>
+  <testcase classname="org.elasticsearch.jdbc.MethodQueryTest" name="testPrefixAndNestedQuery" time="0.048"/>
 </testsuite>

+ 2 - 2
elasticsearch-query-jdbc/target/surefire-reports/TEST-org.elasticsearch.jdbc.ScriptQueryTest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<testsuite tests="1" failures="0" name="org.elasticsearch.jdbc.ScriptQueryTest" time="0.032" errors="0" skipped="0">
+<testsuite tests="1" failures="0" name="org.elasticsearch.jdbc.ScriptQueryTest" time="2.103" errors="0" skipped="0">
   <properties>
     <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
     <property name="sun.boot.library.path" value="E:\dev\Java\jdk1.8.0_66\jre\bin"/>
@@ -61,5 +61,5 @@
     <property name="sun.desktop" value="windows"/>
     <property name="sun.cpu.isalist" value="amd64"/>
   </properties>
-  <testcase classname="org.elasticsearch.jdbc.ScriptQueryTest" name="testScriptQuery" time="0.031"/>
+  <testcase classname="org.elasticsearch.jdbc.ScriptQueryTest" name="testScriptQuery" time="2.102"/>
 </testsuite>

+ 1 - 1
elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.ElasticDriverTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.jdbc.ElasticDriverTest
 -------------------------------------------------------------------------------
-Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.602 sec
+Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.98 sec

+ 1 - 1
elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.GroupByTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.jdbc.GroupByTest
 -------------------------------------------------------------------------------
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.053 sec
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.226 sec

+ 1 - 1
elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.MethodQueryTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.jdbc.MethodQueryTest
 -------------------------------------------------------------------------------
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 sec
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.049 sec

+ 1 - 1
elasticsearch-query-jdbc/target/surefire-reports/org.elasticsearch.jdbc.ScriptQueryTest.txt

@@ -1,4 +1,4 @@
 -------------------------------------------------------------------------------
 Test set: org.elasticsearch.jdbc.ScriptQueryTest
 -------------------------------------------------------------------------------
-Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.103 sec

+ 6 - 0
elasticsearch-query-spring/pom.xml

@@ -36,6 +36,12 @@
 		</dependency>
 
 		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.16</version>
+		</dependency>
+
+		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
 			<version>4.12</version>

+ 203 - 1
elasticsearch-query-spring/src/main/java/org/elasticsearch/ElasticSqlMapClientTemplate.java

@@ -1,7 +1,209 @@
 package org.elasticsearch;
 
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
+import org.apache.commons.collections.CollectionUtils;
+import org.elasticsearch.es.JdbcSearchResponse;
+import org.elasticsearch.es.JdbcSearchResponseResolver;
+import org.springframework.dao.DataAccessException;
 import org.springframework.orm.ibatis.SqlMapClientTemplate;
 
-public class ElasticSqlMapClientTemplate extends SqlMapClientTemplate {
+import java.util.List;
 
+public class ElasticSqlMapClientTemplate extends SqlMapClientTemplate implements ElasticSqlMapExecutor {
+    @Override
+    public <T> List<T> queryForList(String statementName, Class<T> clazz) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(clazz);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Class<T> clazz, String datePattern) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(clazz, datePattern);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, TypeToken<T> typeToken) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(typeToken);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, TypeToken<T> typeToken, String datePattern) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(typeToken, datePattern);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Class<T> clazz, Gson gson) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(clazz, gson);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, TypeToken<T> typeToken, Gson gson) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(typeToken, gson);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(resolveStrategy);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Object parameterObject, Class<T> clazz) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName, parameterObject);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(clazz);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Object parameterObject, Class<T> clazz, String datePattern) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName, parameterObject);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(clazz, datePattern);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Object parameterObject, TypeToken<T> typeToken) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName, parameterObject);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(typeToken);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Object parameterObject, TypeToken<T> typeToken, String datePattern) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName, parameterObject);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(typeToken, datePattern);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Object parameterObject, Class<T> clazz, Gson gson) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName, parameterObject);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(clazz, gson);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Object parameterObject, TypeToken<T> typeToken, Gson gson) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName, parameterObject);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(typeToken, gson);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> List<T> queryForList(String statementName, Object parameterObject, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException {
+        String responseGson = (String) super.queryForObject(statementName, parameterObject);
+        JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
+        JdbcSearchResponse<T> searchResponse = responseResolver.resolveSearchResponse(resolveStrategy);
+        return searchResponse.getResultList();
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Class<T> clazz) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, clazz);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Class<T> clazz, String datePattern) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, clazz, datePattern);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, TypeToken<T> typeToken) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, typeToken);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, TypeToken<T> typeToken, String datePattern) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, typeToken, datePattern);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Class<T> clazz, Gson gson) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, clazz, gson);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, TypeToken<T> typeToken, Gson gson) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, typeToken, gson);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, resolveStrategy);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Object parameterObject, Class<T> clazz) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, parameterObject, clazz);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Object parameterObject, Class<T> clazz, String datePattern) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, parameterObject, clazz, datePattern);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Object parameterObject, TypeToken<T> typeToken) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, parameterObject, typeToken);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Object parameterObject, TypeToken<T> typeToken, String datePattern) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, parameterObject, typeToken, datePattern);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Object parameterObject, Class<T> clazz, Gson gson) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, parameterObject, clazz, gson);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Object parameterObject, TypeToken<T> typeToken, Gson gson) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, parameterObject, typeToken, gson);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
+
+    @Override
+    public <T> T queryForObject(String statementName, Object parameterObject, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException {
+        List<T> resultList = queryForList(statementName, parameterObject, resolveStrategy);
+        return CollectionUtils.isEmpty(resultList) ? null : resultList.get(0);
+    }
 }

+ 81 - 0
elasticsearch-query-spring/src/main/java/org/elasticsearch/ElasticSqlMapExecutor.java

@@ -0,0 +1,81 @@
+package org.elasticsearch;
+
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
+import org.elasticsearch.es.JdbcSearchResponseResolver;
+import org.springframework.dao.DataAccessException;
+
+import java.util.List;
+
+public interface ElasticSqlMapExecutor {
+
+    // statementName
+
+    <T> List<T> queryForList(String statementName, Class<T> clazz) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Class<T> clazz, String datePattern) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, TypeToken<T> typeToken) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, TypeToken<T> typeToken, String datePattern) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Class<T> clazz, Gson gson) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, TypeToken<T> typeToken, Gson gson) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException;
+
+
+    // String statementName, Object parameterObject
+
+
+    <T> List<T> queryForList(String statementName, Object parameterObject, Class<T> clazz) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Object parameterObject, Class<T> clazz, String datePattern) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Object parameterObject, TypeToken<T> typeToken) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Object parameterObject, TypeToken<T> typeToken, String datePattern) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Object parameterObject, Class<T> clazz, Gson gson) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Object parameterObject, TypeToken<T> typeToken, Gson gson) throws DataAccessException;
+
+    <T> List<T> queryForList(String statementName, Object parameterObject, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException;
+
+
+    // statementName
+
+    <T> T queryForObject(String statementName, Class<T> clazz) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Class<T> clazz, String datePattern) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, TypeToken<T> typeToken) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, TypeToken<T> typeToken, String datePattern) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Class<T> clazz, Gson gson) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, TypeToken<T> typeToken, Gson gson) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException;
+
+
+    // String statementName, Object parameterObject
+
+
+    <T> T queryForObject(String statementName, Object parameterObject, Class<T> clazz) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Object parameterObject, Class<T> clazz, String datePattern) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Object parameterObject, TypeToken<T> typeToken) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Object parameterObject, TypeToken<T> typeToken, String datePattern) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Object parameterObject, Class<T> clazz, Gson gson) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Object parameterObject, TypeToken<T> typeToken, Gson gson) throws DataAccessException;
+
+    <T> T queryForObject(String statementName, Object parameterObject, JdbcSearchResponseResolver.ResolveStrategy<T> resolveStrategy) throws DataAccessException;
+
+}

+ 23 - 0
elasticsearch-query-spring/src/main/java/org/elasticsearch/bean/Buyer.java

@@ -0,0 +1,23 @@
+package org.elasticsearch.bean;
+
+public class Buyer {
+    private String buyerName;
+
+    private Integer productPrice;
+
+    public String getBuyerName() {
+        return buyerName;
+    }
+
+    public void setBuyerName(String buyerName) {
+        this.buyerName = buyerName;
+    }
+
+    public Integer getProductPrice() {
+        return productPrice;
+    }
+
+    public void setProductPrice(Integer productPrice) {
+        this.productPrice = productPrice;
+    }
+}

+ 66 - 0
elasticsearch-query-spring/src/main/java/org/elasticsearch/bean/Product.java

@@ -0,0 +1,66 @@
+package org.elasticsearch.bean;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+public class Product {
+    private String productName;
+
+    private String productCode;
+
+    private BigDecimal minPrice;
+
+    private BigDecimal advicePrice;
+
+    private Provider provider;
+
+    private List<Buyer> buyers;
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public void setProductName(String productName) {
+        this.productName = productName;
+    }
+
+    public String getProductCode() {
+        return productCode;
+    }
+
+    public void setProductCode(String productCode) {
+        this.productCode = productCode;
+    }
+
+    public BigDecimal getMinPrice() {
+        return minPrice;
+    }
+
+    public void setMinPrice(BigDecimal minPrice) {
+        this.minPrice = minPrice;
+    }
+
+    public BigDecimal getAdvicePrice() {
+        return advicePrice;
+    }
+
+    public void setAdvicePrice(BigDecimal advicePrice) {
+        this.advicePrice = advicePrice;
+    }
+
+    public Provider getProvider() {
+        return provider;
+    }
+
+    public void setProvider(Provider provider) {
+        this.provider = provider;
+    }
+
+    public List<Buyer> getBuyers() {
+        return buyers;
+    }
+
+    public void setBuyers(List<Buyer> buyers) {
+        this.buyers = buyers;
+    }
+}

+ 23 - 0
elasticsearch-query-spring/src/main/java/org/elasticsearch/bean/Provider.java

@@ -0,0 +1,23 @@
+package org.elasticsearch.bean;
+
+public class Provider {
+    private String providerName;
+
+    private Integer providerLevel;
+
+    public String getProviderName() {
+        return providerName;
+    }
+
+    public void setProviderName(String providerName) {
+        this.providerName = providerName;
+    }
+
+    public Integer getProviderLevel() {
+        return providerLevel;
+    }
+
+    public void setProviderLevel(Integer providerLevel) {
+        this.providerLevel = providerLevel;
+    }
+}

+ 35 - 0
elasticsearch-query-spring/src/main/java/org/elasticsearch/dao/ProductDao.java

@@ -0,0 +1,35 @@
+package org.elasticsearch.dao;
+
+import com.google.common.collect.Maps;
+import org.elasticsearch.ElasticSqlMapExecutor;
+import org.elasticsearch.bean.Product;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Repository;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+
+@Repository
+public class ProductDao {
+    @Autowired
+    @Qualifier("sqlMapClientTemplate")
+    private ElasticSqlMapExecutor sqlMapClientTemplate;
+
+    public List<Product> getProductByCodeAndMatchWord(String matchWord, String productCode) throws SQLException {
+        Map<String, Object> paramMap = Maps.newHashMap();
+        paramMap.put("productCode", productCode);
+        paramMap.put("advicePrice", 1000);
+        paramMap.put("routingVal", "A");
+        paramMap.put("matchWord", matchWord);
+        paramMap.put("prefixWord", matchWord);
+
+        return sqlMapClientTemplate.queryForList("PRODUCT.getProductByCodeAndMatchWord", paramMap, Product.class);
+
+    }
+
+    public List<Product> getAllProduct() {
+        return sqlMapClientTemplate.queryForList("PRODUCT.getAllProduct", Product.class);
+    }
+}

+ 40 - 0
elasticsearch-query-spring/src/main/resources/application-context.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:tx="http://www.springframework.org/schema/tx"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+     http://www.springframework.org/schema/tx
+     http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+
+
+     http://www.springframework.org/schema/context
+     http://www.springframework.org/schema/context/spring-context-2.5.xsd">
+
+
+    <context:component-scan base-package="org.elasticsearch" />
+    <tx:annotation-driven transaction-manager="transactionManager" />
+
+    <bean id="elasticDataSource" class="org.elasticsearch.api.ElasticSingleConnectionDataSource" destroy-method="destroy">
+        <property name="driverClassName" value="org.elasticsearch.api.ElasticDriver" />
+        <property name="url" value="jdbc:elastic:192.168.0.109:9300/lu-search-cluster" />
+        <property name="suppressClose" value="true" />
+    </bean>
+
+
+    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
+        <property name="dataSource" ref="elasticDataSource" />
+        <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
+    </bean>
+
+    <bean id="sqlMapClientTemplate" class="org.elasticsearch.ElasticSqlMapClientTemplate">
+        <property name="sqlMapClient" ref="sqlMapClient"/>
+    </bean>
+
+    <bean id="transactionManager"
+          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="elasticDataSource" />
+    </bean>
+
+</beans>

+ 30 - 0
elasticsearch-query-spring/src/main/resources/log4j.properties

@@ -0,0 +1,30 @@
+LOG_HOME=/tmp/logs/elasticsearch-query-spring
+
+log4j.appender.reporterAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.reporterAppender.Threshold=DEBUG
+log4j.appender.reporterAppender.File=${LOG_HOME}/elasticsearch-query-spring.log
+log4j.appender.reporterAppender.DatePattern='.'yyyy-MM-dd'.log'
+log4j.appender.reporterAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.reporterAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss SSS} [%-3p] [%t] %c{3} - %m%n
+
+log4j.appender.warnAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.warnAppender.Threshold=WARN
+log4j.appender.warnAppender.File=${LOG_HOME}/warn.log
+log4j.appender.warnAppender.DatePattern='.'yyyy-MM-dd'.log'
+log4j.appender.warnAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.warnAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss SSS} [%-3p] [%t] %c{3} - %m%n
+
+log4j.appender.3rdPartyAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.3rdPartyAppender.Threshold=INFO
+log4j.appender.3rdPartyAppender.File=${LOG_HOME}/3rd-party.log
+log4j.appender.3rdPartyAppender.DatePattern='.'yyyy-MM-dd'.log'
+log4j.appender.3rdPartyAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.3rdPartyAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss SSS} [%-3p] [%t] %c{3} - %m%n
+
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.Target=System.out
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss}[%c]-[%p]%m%n
+
+log4j.rootLogger=INFO,reporterAppender,console
+#log4j.logger.org.elasticsearch.jdbc.search=DEBUG,remoteAppender

+ 17 - 0
elasticsearch-query-spring/src/main/resources/sqlMapConfig.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
+        "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
+
+<sqlMapConfig>
+    <settings
+            cacheModelsEnabled="true"
+            lazyLoadingEnabled="true"
+            enhancementEnabled="true"
+            maxSessions="64"
+            maxTransactions="20"
+            maxRequests="128"
+            useStatementNamespaces="true"/>
+
+    <sqlMap resource="sqlmap/PRODUCT.xml"/>
+
+</sqlMapConfig>

+ 19 - 0
elasticsearch-query-spring/src/main/resources/sqlmap/PRODUCT.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE sqlMap
+        PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
+        "http://ibatis.apache.org/dtd/sql-map-2.dtd">
+<sqlMap namespace="PRODUCT">
+    <select id="getProductByCodeAndMatchWord" parameterClass="java.util.Map" resultClass="java.lang.String">
+        SELECT *
+        FROM index.product
+        QUERY match(productName, #matchWord#) or prefix(productName, #prefixWord#, 'boost:2.0f')
+        WHERE productCode = #productCode#
+        AND advicePrice > #advicePrice#
+        AND $$buyers.buyerName IN ('china', 'usa')
+        ROUTING BY #routingVal#
+    </select>
+
+    <select id="getAllProduct" resultClass="java.lang.String">
+        SELECT * FROM index.product
+    </select>
+</sqlMap>

+ 31 - 0
elasticsearch-query-spring/src/test/java/org/elasticsearch/ProductIndexQueryTest.java

@@ -0,0 +1,31 @@
+package org.elasticsearch;
+
+import org.elasticsearch.bean.Product;
+import org.elasticsearch.dao.ProductDao;
+import org.junit.Test;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.List;
+
+public class ProductIndexQueryTest {
+
+    @Test
+    public void testProductQuery() throws Exception {
+        BeanFactory factory = new ClassPathXmlApplicationContext("application-context.xml");
+
+        ProductDao productDao = factory.getBean(ProductDao.class);
+
+        List<Product> productList = productDao.getProductByCodeAndMatchWord("iphone 6s", "IP_6S");
+        for (Product product : productList) {
+            System.out.println(product.getProductName());
+        }
+
+        System.out.println("============================>");
+
+        productList = productDao.getAllProduct();
+        for (Product product : productList) {
+            System.out.println(product.getProductName());
+        }
+    }
+}

+ 40 - 0
elasticsearch-query-spring/target/classes/application-context.xml

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:tx="http://www.springframework.org/schema/tx"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+     http://www.springframework.org/schema/tx
+     http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+
+
+     http://www.springframework.org/schema/context
+     http://www.springframework.org/schema/context/spring-context-2.5.xsd">
+
+
+    <context:component-scan base-package="org.elasticsearch" />
+    <tx:annotation-driven transaction-manager="transactionManager" />
+
+    <bean id="elasticDataSource" class="org.elasticsearch.api.ElasticSingleConnectionDataSource" destroy-method="destroy">
+        <property name="driverClassName" value="org.elasticsearch.api.ElasticDriver" />
+        <property name="url" value="jdbc:elastic:192.168.0.109:9300/lu-search-cluster" />
+        <property name="suppressClose" value="true" />
+    </bean>
+
+
+    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
+        <property name="dataSource" ref="elasticDataSource" />
+        <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
+    </bean>
+
+    <bean id="sqlMapClientTemplate" class="org.elasticsearch.ElasticSqlMapClientTemplate">
+        <property name="sqlMapClient" ref="sqlMapClient"/>
+    </bean>
+
+    <bean id="transactionManager"
+          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <property name="dataSource" ref="elasticDataSource" />
+    </bean>
+
+</beans>

+ 30 - 0
elasticsearch-query-spring/target/classes/log4j.properties

@@ -0,0 +1,30 @@
+LOG_HOME=/tmp/logs/elasticsearch-query-spring
+
+log4j.appender.reporterAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.reporterAppender.Threshold=DEBUG
+log4j.appender.reporterAppender.File=${LOG_HOME}/elasticsearch-query-spring.log
+log4j.appender.reporterAppender.DatePattern='.'yyyy-MM-dd'.log'
+log4j.appender.reporterAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.reporterAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss SSS} [%-3p] [%t] %c{3} - %m%n
+
+log4j.appender.warnAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.warnAppender.Threshold=WARN
+log4j.appender.warnAppender.File=${LOG_HOME}/warn.log
+log4j.appender.warnAppender.DatePattern='.'yyyy-MM-dd'.log'
+log4j.appender.warnAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.warnAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss SSS} [%-3p] [%t] %c{3} - %m%n
+
+log4j.appender.3rdPartyAppender=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.3rdPartyAppender.Threshold=INFO
+log4j.appender.3rdPartyAppender.File=${LOG_HOME}/3rd-party.log
+log4j.appender.3rdPartyAppender.DatePattern='.'yyyy-MM-dd'.log'
+log4j.appender.3rdPartyAppender.layout=org.apache.log4j.PatternLayout
+log4j.appender.3rdPartyAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss SSS} [%-3p] [%t] %c{3} - %m%n
+
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.Target=System.out
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss}[%c]-[%p]%m%n
+
+log4j.rootLogger=INFO,reporterAppender,console
+#log4j.logger.org.elasticsearch.jdbc.search=DEBUG,remoteAppender

+ 17 - 0
elasticsearch-query-spring/target/classes/sqlMapConfig.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
+        "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
+
+<sqlMapConfig>
+    <settings
+            cacheModelsEnabled="true"
+            lazyLoadingEnabled="true"
+            enhancementEnabled="true"
+            maxSessions="64"
+            maxTransactions="20"
+            maxRequests="128"
+            useStatementNamespaces="true"/>
+
+    <sqlMap resource="sqlmap/PRODUCT.xml"/>
+
+</sqlMapConfig>

+ 19 - 0
elasticsearch-query-spring/target/classes/sqlmap/PRODUCT.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE sqlMap
+        PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
+        "http://ibatis.apache.org/dtd/sql-map-2.dtd">
+<sqlMap namespace="PRODUCT">
+    <select id="getProductByCodeAndMatchWord" parameterClass="java.util.Map" resultClass="java.lang.String">
+        SELECT *
+        FROM index.product
+        QUERY match(productName, #matchWord#) or prefix(productName, #prefixWord#, 'boost:2.0f')
+        WHERE productCode = #productCode#
+        AND advicePrice > #advicePrice#
+        AND $$buyers.buyerName IN ('china', 'usa')
+        ROUTING BY #routingVal#
+    </select>
+
+    <select id="getAllProduct" resultClass="java.lang.String">
+        SELECT * FROM index.product
+    </select>
+</sqlMap>

Datei-Diff unterdrückt, da er zu groß ist
+ 65 - 0
elasticsearch-query-spring/target/surefire-reports/TEST-org.elasticsearch.ProductIndexQueryTest.xml


+ 4 - 0
elasticsearch-query-spring/target/surefire-reports/org.elasticsearch.ProductIndexQueryTest.txt

@@ -0,0 +1,4 @@
+-------------------------------------------------------------------------------
+Test set: org.elasticsearch.ProductIndexQueryTest
+-------------------------------------------------------------------------------
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.702 sec