Skip to content

Commit

Permalink
fix #921 spring boot mybatis 传参数报错
Browse files Browse the repository at this point in the history
  • Loading branch information
shi-yuan committed Aug 25, 2019
1 parent a57ab45 commit 2f581c2
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nlpcn</groupId>
<artifactId>elasticsearch-sql</artifactId>
<version>6.8.2.0</version>
<version>6.8.2.1</version>
<packaging>jar</packaging>
<description>Query elasticsearch using SQL</description>
<name>elasticsearch-sql</name>
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/alibaba/druid/pool/ElasticSearchConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@

import org.elasticsearch.client.Client;

import java.sql.*;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -33,7 +47,7 @@ public Statement createStatement() throws SQLException {

@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
return new ElasticSearchPreparedStatement();
return new ElasticSearchPreparedStatement(sql);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ResultSet executeQuery() throws SQLException {

conn.beforeExecute();
try {
ObjectResult extractor = getObjectResult(true, getSql(), false, false, true);
ObjectResult extractor = getObjectResult(true, false, false, true);
List<String> headers = extractor.getHeaders();
List<List<Object>> lines = extractor.getLines();

Expand Down Expand Up @@ -67,7 +67,7 @@ public boolean execute() throws SQLException {

conn.beforeExecute();
try {
ObjectResult extractor = getObjectResult(true, getSql(), false, false, true);
ObjectResult extractor = getObjectResult(true, false, false, true);
List<String> headers = extractor.getHeaders();
List<List<Object>> lines = extractor.getLines();

Expand All @@ -84,11 +84,10 @@ public boolean execute() throws SQLException {
}
}

private ObjectResult getObjectResult(boolean flat, String query, boolean includeScore, boolean includeType, boolean includeId) throws SqlParseException, SQLFeatureNotSupportedException, Exception, CsvExtractorException {
private ObjectResult getObjectResult(boolean flat, boolean includeScore, boolean includeType, boolean includeId) throws SqlParseException, SQLFeatureNotSupportedException, Exception, CsvExtractorException {
SearchDao searchDao = new org.nlpcn.es4sql.SearchDao(client);

//String rewriteSQL = searchDao.explain(getSql()).explain().explain();

String query = ((ElasticSearchPreparedStatement) getRawPreparedStatement()).getExecutableSql();
QueryAction queryAction = searchDao.explain(query);
Object execution = QueryActionElasticExecutor.executeAnyAction(searchDao.getClient(), queryAction);
return new ObjectResultsExtractor(includeScore, includeType, includeId, false, queryAction).extractResults(execution, flat);
Expand Down
Loading

0 comments on commit 2f581c2

Please sign in to comment.