This is an automated email from the ASF dual-hosted git repository.
menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 13574e1 Use UpdateResult instead of ExecuteResult in
UpdateResponseHeader (#8442)
13574e1 is described below
commit 13574e14dbc3a51e7473d490189fbb424c509adf
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Dec 1 15:28:27 2020 +0800
Use UpdateResult instead of ExecuteResult in UpdateResponseHeader (#8442)
---
.../communication/DatabaseCommunicationEngine.java | 27 +++++++++++-----------
.../header/update/UpdateResponseHeader.java | 17 +++++++-------
2 files changed, 22 insertions(+), 22 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 52b0562..9d52c60 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
+import
org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult;
import org.apache.shardingsphere.infra.executor.sql.log.SQLLogger;
import org.apache.shardingsphere.infra.merge.MergeEngine;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -98,30 +99,30 @@ public final class DatabaseCommunicationEngine {
Collection<ExecuteResult> executeResults =
proxySQLExecutor.execute(executionContext);
ExecuteResult executeResultSample = executeResults.iterator().next();
return executeResultSample instanceof QueryResult
- ? processExecuteQuery(executionContext, executeResults,
(QueryResult) executeResultSample) : processExecuteUpdate(executionContext,
executeResults);
+ ? processExecuteQuery(executionContext,
executeResults.stream().map(each -> (QueryResult)
each).collect(Collectors.toList()), (QueryResult) executeResultSample)
+ : processExecuteUpdate(executionContext,
executeResults.stream().map(each -> (UpdateResult)
each).collect(Collectors.toList()));
}
- private QueryResponseHeader processExecuteQuery(final ExecutionContext
executionContext,
- final
Collection<ExecuteResult> executeResults, final QueryResult
executeResultSample) throws SQLException {
- queryHeaders = createQueryHeaders(executionContext,
executeResultSample);
- mergedResult = mergeQuery(executionContext.getSqlStatementContext(),
executeResults.stream().map(each -> (QueryResult)
each).collect(Collectors.toList()));
+ private QueryResponseHeader processExecuteQuery(final ExecutionContext
executionContext, final List<QueryResult> queryResults, final QueryResult
queryResultSample) throws SQLException {
+ queryHeaders = createQueryHeaders(executionContext, queryResultSample);
+ mergedResult = mergeQuery(executionContext.getSqlStatementContext(),
queryResults);
return new QueryResponseHeader(queryHeaders);
}
- private List<QueryHeader> createQueryHeaders(final ExecutionContext
executionContext, final QueryResult executeResultSample) throws SQLException {
- int columnCount = executeResultSample.getMetaData().getColumnCount();
+ private List<QueryHeader> createQueryHeaders(final ExecutionContext
executionContext, final QueryResult queryResultSample) throws SQLException {
+ int columnCount = queryResultSample.getMetaData().getColumnCount();
List<QueryHeader> result = new ArrayList<>(columnCount);
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
- result.add(createQueryHeader(executionContext,
executeResultSample, metaData, columnIndex));
+ result.add(createQueryHeader(executionContext, queryResultSample,
metaData, columnIndex));
}
return result;
}
private QueryHeader createQueryHeader(final ExecutionContext
executionContext,
- final QueryResult
executeResultSample, final ShardingSphereMetaData metaData, final int
columnIndex) throws SQLException {
+ final QueryResult queryResultSample,
final ShardingSphereMetaData metaData, final int columnIndex) throws
SQLException {
return
hasSelectExpandProjections(executionContext.getSqlStatementContext())
- ? QueryHeaderBuilder.build(((SelectStatementContext)
executionContext.getSqlStatementContext()).getProjectionsContext(),
executeResultSample, metaData, columnIndex)
- : QueryHeaderBuilder.build(executeResultSample, metaData,
columnIndex);
+ ? QueryHeaderBuilder.build(((SelectStatementContext)
executionContext.getSqlStatementContext()).getProjectionsContext(),
queryResultSample, metaData, columnIndex)
+ : QueryHeaderBuilder.build(queryResultSample, metaData,
columnIndex);
}
private boolean hasSelectExpandProjections(final SQLStatementContext<?>
sqlStatementContext) {
@@ -134,8 +135,8 @@ public final class DatabaseCommunicationEngine {
return mergeEngine.merge(queryResults, sqlStatementContext);
}
- private UpdateResponseHeader processExecuteUpdate(final ExecutionContext
executionContext, final Collection<ExecuteResult> executeResults) throws
SQLException {
- UpdateResponseHeader result = new
UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement(),
executeResults);
+ private UpdateResponseHeader processExecuteUpdate(final ExecutionContext
executionContext, final Collection<UpdateResult> updateResults) throws
SQLException {
+ UpdateResponseHeader result = new
UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement(),
updateResults);
refreshSchema(executionContext);
mergeUpdateCount(executionContext.getSqlStatementContext(), result);
return result;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
index 76bd64e..cc7584b 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/update/UpdateResponseHeader.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.proxy.backend.response.header.update;
import lombok.AccessLevel;
import lombok.Getter;
-import
org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -47,19 +46,19 @@ public final class UpdateResponseHeader implements
ResponseHeader {
this(sqlStatement, Collections.emptyList());
}
- public UpdateResponseHeader(final SQLStatement sqlStatement, final
Collection<ExecuteResult> executeResults) {
+ public UpdateResponseHeader(final SQLStatement sqlStatement, final
Collection<UpdateResult> updateResults) {
this.sqlStatement = sqlStatement;
- lastInsertId = getLastInsertId(executeResults);
- updateCount = executeResults.iterator().hasNext() ? ((UpdateResult)
executeResults.iterator().next()).getUpdateCount() : 0;
- for (ExecuteResult each : executeResults) {
- updateCounts.add(((UpdateResult) each).getUpdateCount());
+ lastInsertId = getLastInsertId(updateResults);
+ updateCount = updateResults.iterator().hasNext() ?
updateResults.iterator().next().getUpdateCount() : 0;
+ for (UpdateResult each : updateResults) {
+ updateCounts.add(each.getUpdateCount());
}
}
- private long getLastInsertId(final Collection<ExecuteResult>
executeResults) {
+ private long getLastInsertId(final Collection<UpdateResult> updateResults)
{
long result = 0;
- for (ExecuteResult each : executeResults) {
- result = Math.max(result, ((UpdateResult) each).getLastInsertId());
+ for (UpdateResult each : updateResults) {
+ result = Math.max(result, each.getLastInsertId());
}
return result;
}