You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2023/06/03 16:13:43 UTC
[shardingsphere] branch master updated: Remove unused constructor and revise code style for #25988 (#26034)
This is an automated email from the ASF dual-hosted git repository.
yx9o 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 219c27e98da Remove unused constructor and revise code style for #25988 (#26034)
219c27e98da is described below
commit 219c27e98da5067ca2f7d543c001f33ac6ea1a24
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Sun Jun 4 00:13:26 2023 +0800
Remove unused constructor and revise code style for #25988 (#26034)
* Revise code style in #25988
* Remove constructor only used in test code
* Complete OpenGaussComBatchBindExecutorTest
---
.../bind/OpenGaussComBatchBindExecutorTest.java | 3 ++-
.../PostgreSQLServerPreparedStatement.java | 29 ++++++----------------
.../extended/parse/PostgreSQLComParseExecutor.java | 5 ++--
.../command/query/extended/PortalTest.java | 20 +++++++++------
...egatedBatchedStatementsCommandExecutorTest.java | 4 +--
.../PostgreSQLBatchedStatementsExecutorTest.java | 4 +--
.../bind/PostgreSQLComBindExecutorTest.java | 2 +-
.../PostgreSQLComDescribeExecutorTest.java | 20 ++++++++++-----
8 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
index af64cfb40dd..e3deb3d01cb 100644
--- a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
+++ b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
@@ -84,7 +84,8 @@ class OpenGaussComBatchBindExecutorTest {
SQLStatementContext sqlStatementContext = mock(InsertStatementContext.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
ConnectionSession connectionSession = mockConnectionSession();
- connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statement, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, Collections.emptyList()));
+ PostgreSQLServerPreparedStatement serverPreparedStatement = new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, Collections.emptyList(), Collections.emptyList());
+ connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statement, serverPreparedStatement);
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
Iterator<DatabasePacket> actualPacketsIterator = new OpenGaussComBatchBindExecutor(mockComBatchBindPacket(), connectionSession).execute().iterator();
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLServerPreparedStatement.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLServerPreparedStatement.java
index 38396559ee6..8a9bdf3f601 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLServerPreparedStatement.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLServerPreparedStatement.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extend
import lombok.AccessLevel;
import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLParameterDescriptionPacket;
@@ -27,13 +28,13 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.proxy.backend.session.ServerPreparedStatement;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
* Prepared statement for PostgreSQL.
*/
+@RequiredArgsConstructor
@Getter
@Setter
public final class PostgreSQLServerPreparedStatement implements ServerPreparedStatement {
@@ -49,20 +50,6 @@ public final class PostgreSQLServerPreparedStatement implements ServerPreparedSt
@Getter(AccessLevel.NONE)
private PostgreSQLPacket rowDescription;
- public PostgreSQLServerPreparedStatement(final String sql, final SQLStatementContext sqlStatementContext, final List<PostgreSQLColumnType> parameterTypes) {
- this(sql, sqlStatementContext, parameterTypes, Collections.emptyList());
- }
-
- public PostgreSQLServerPreparedStatement(final String sql,
- final SQLStatementContext sqlStatementContext,
- final List<PostgreSQLColumnType> parameterTypes,
- final List<Integer> actualParameterMarkerIndexes) {
- this.sql = sql;
- this.sqlStatementContext = sqlStatementContext;
- this.parameterTypes = parameterTypes;
- this.actualParameterMarkerIndexes = actualParameterMarkerIndexes;
- }
-
/**
* Describe parameters of the prepared statement.
*
@@ -82,18 +69,18 @@ public final class PostgreSQLServerPreparedStatement implements ServerPreparedSt
}
/**
- * Adjust Parameters order.
+ * Adjust parameters order.
* @param parameters parameters in pg marker index order
* @return parameters in jdbc style marker index order
*/
public List<Object> adjustParametersOrder(final List<Object> parameters) {
- if (parameters == null || parameters.size() == 0) {
+ if (parameters.isEmpty()) {
return parameters;
}
- List<Object> reOrdered = new ArrayList<>(parameters.size());
- for (Integer parameterMarkerIndex : actualParameterMarkerIndexes) {
- reOrdered.add(parameters.get(parameterMarkerIndex));
+ List<Object> result = new ArrayList<>(parameters.size());
+ for (int each : actualParameterMarkerIndexes) {
+ result.add(parameters.get(each));
}
- return reOrdered;
+ return result;
}
}
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
index cb6d5b1f7aa..a83e860542b 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
@@ -45,7 +45,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import java.util.stream.Collectors;
/**
* PostgreSQL command parse executor.
@@ -65,7 +64,9 @@ public final class PostgreSQLComParseExecutor implements CommandExecutor {
List<Integer> actualParameterMarkerIndexes = new ArrayList<>();
if (sqlStatement.getParameterCount() > 0) {
List<ParameterMarkerSegment> parameterMarkerSegments = new ArrayList<>(((AbstractSQLStatement) sqlStatement).getParameterMarkerSegments());
- actualParameterMarkerIndexes.addAll(parameterMarkerSegments.stream().map(ParameterMarkerSegment::getParameterIndex).collect(Collectors.toList()));
+ for (ParameterMarkerSegment each : parameterMarkerSegments) {
+ actualParameterMarkerIndexes.add(each.getParameterIndex());
+ }
sql = convertSQLToJDBCStyle(parameterMarkerSegments, sql);
sqlStatement = sqlParserEngine.parse(sql, true);
}
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
index 4c0038900f6..fa62f54fa0f 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
@@ -130,8 +130,9 @@ class PortalTest {
@Test
void assertGetName() throws SQLException {
- Portal portal = new Portal("", new PostgreSQLServerPreparedStatement("",
- new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList()), Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
+ PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("",
+ new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList(), Collections.emptyList());
+ Portal portal = new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
assertThat(portal.getName(), is(""));
}
@@ -148,7 +149,7 @@ class PortalTest {
SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getSqlStatement()).thenReturn(new PostgreSQLSelectStatement());
PostgreSQLServerPreparedStatement preparedStatement =
- new PostgreSQLServerPreparedStatement("", sqlStatementContext, Collections.emptyList());
+ new PostgreSQLServerPreparedStatement("", sqlStatementContext, Collections.emptyList(), Collections.emptyList());
List<PostgreSQLValueFormat> resultFormats = new ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT, PostgreSQLValueFormat.BINARY));
Portal portal = new Portal("", preparedStatement, Collections.emptyList(), resultFormats, databaseConnectionManager);
portal.bind();
@@ -181,7 +182,7 @@ class PortalTest {
new QueryResponseRow(Collections.singletonList(new QueryResponseCell(Types.INTEGER, 1))));
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(selectStatementContext.getSqlStatement()).thenReturn(new PostgreSQLSelectStatement());
- PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", selectStatementContext, Collections.emptyList());
+ PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", selectStatementContext, Collections.emptyList(), Collections.emptyList());
List<PostgreSQLValueFormat> resultFormats = new ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT, PostgreSQLValueFormat.BINARY));
Portal portal = new Portal("", preparedStatement, Collections.emptyList(), resultFormats, databaseConnectionManager);
portal.bind();
@@ -200,7 +201,7 @@ class PortalTest {
when(proxyBackendHandler.next()).thenReturn(false);
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(insertStatementContext.getSqlStatement()).thenReturn(new PostgreSQLInsertStatement());
- PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", insertStatementContext, Collections.emptyList());
+ PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", insertStatementContext, Collections.emptyList(), Collections.emptyList());
Portal portal = new Portal("insert into t values (1)", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
portal.bind();
assertThat(portal.describe(), is(PostgreSQLNoDataPacket.getInstance()));
@@ -212,7 +213,8 @@ class PortalTest {
void assertExecuteEmptyStatement() throws SQLException {
when(proxyBackendHandler.execute()).thenReturn(mock(UpdateResponseHeader.class));
when(proxyBackendHandler.next()).thenReturn(false);
- PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList());
+ PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("",
+ new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList(), Collections.emptyList());
Portal portal = new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
portal.bind();
assertThat(portal.describe(), is(PostgreSQLNoDataPacket.getInstance()));
@@ -229,7 +231,8 @@ class PortalTest {
VariableAssignSegment variableAssignSegment = new VariableAssignSegment();
variableAssignSegment.setVariable(new VariableSegment(0, 0, "client_encoding"));
setStatement.getVariableAssigns().add(variableAssignSegment);
- PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement(sql, new UnknownSQLStatementContext(setStatement), Collections.emptyList());
+ PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement(sql,
+ new UnknownSQLStatementContext(setStatement), Collections.emptyList(), Collections.emptyList());
Portal portal = new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
portal.bind();
List<DatabasePacket> actualPackets = portal.execute(0);
@@ -247,7 +250,8 @@ class PortalTest {
@Test
void assertClose() throws SQLException {
- PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList());
+ PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("",
+ new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList(), Collections.emptyList());
new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager).close();
verify(databaseConnectionManager).unmarkResourceInUse(proxyBackendHandler);
verify(proxyBackendHandler).close();
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
index e85466f8750..24d66b59c6a 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
@@ -29,7 +29,6 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQ
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
@@ -38,6 +37,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.Statemen
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -112,7 +112,7 @@ class PostgreSQLAggregatedBatchedStatementsCommandExecutorTest {
when(result.getConnectionContext()).thenReturn(new ConnectionContext());
when(result.getServerPreparedStatementRegistry()).thenReturn(new ServerPreparedStatementRegistry());
result.getServerPreparedStatementRegistry().addPreparedStatement(STATEMENT_ID,
- new PostgreSQLServerPreparedStatement(SQL, sqlStatementContext, Collections.singletonList(PostgreSQLColumnType.INT4)));
+ new PostgreSQLServerPreparedStatement(SQL, sqlStatementContext, Collections.singletonList(PostgreSQLColumnType.INT4), Collections.singletonList(0)));
when(result.getConnectionId()).thenReturn(CONNECTION_ID);
ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java
index d9c67ec5b8a..3e47ab2c863 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.PostgreSQLTypeUnspecifiedSQLParameter;
import org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
@@ -30,6 +29,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMod
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -93,7 +93,7 @@ class PostgreSQLBatchedStatementsExecutorTest {
ContextManager contextManager = mockContextManager();
ConnectionSession connectionSession = mockConnectionSession();
PostgreSQLServerPreparedStatement postgreSQLPreparedStatement = new PostgreSQLServerPreparedStatement("insert into t (id, col) values (?, ?)", mockInsertStatementContext(),
- Arrays.asList(PostgreSQLColumnType.INT4, PostgreSQLColumnType.VARCHAR));
+ Arrays.asList(PostgreSQLColumnType.INT4, PostgreSQLColumnType.VARCHAR), Arrays.asList(0, 1));
List<List<Object>> parameterSets = Arrays.asList(Arrays.asList(1, new PostgreSQLTypeUnspecifiedSQLParameter("foo")),
Arrays.asList(2, new PostgreSQLTypeUnspecifiedSQLParameter("bar")), Arrays.asList(3, new PostgreSQLTypeUnspecifiedSQLParameter("baz")));
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
index 1e746c51120..61bf0b6128e 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
@@ -84,7 +84,7 @@ class PostgreSQLComBindExecutorTest {
when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
String statementId = "S_1";
connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId,
- new PostgreSQLServerPreparedStatement("", new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList()));
+ new PostgreSQLServerPreparedStatement("", new UnknownSQLStatementContext(new PostgreSQLEmptyStatement()), Collections.emptyList(), Collections.emptyList()));
when(bindPacket.getStatementId()).thenReturn(statementId);
when(bindPacket.getPortal()).thenReturn("C_1");
when(bindPacket.readParameters(anyList())).thenReturn(Collections.emptyList());
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
index 88c41f45d20..74962d784d0 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
@@ -75,6 +75,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
@@ -142,7 +144,8 @@ class PostgreSQLComDescribeExecutorTest {
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME);
when(ProxyContext.getInstance().getDatabase(DATABASE_NAME)).thenReturn(database);
- connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes));
+ List<Integer> parameterIndexes = IntStream.range(0, sqlStatement.getParameterCount()).boxed().collect(Collectors.toList());
+ connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes, parameterIndexes));
Collection<DatabasePacket> actualPackets = executor.execute();
assertThat(actualPackets.size(), is(2));
Iterator<DatabasePacket> actualPacketsIterator = actualPackets.iterator();
@@ -172,7 +175,8 @@ class PostgreSQLComDescribeExecutorTest {
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME);
when(ProxyContext.getInstance().getDatabase(DATABASE_NAME)).thenReturn(database);
- connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes));
+ List<Integer> parameterIndexes = IntStream.range(0, sqlStatement.getParameterCount()).boxed().collect(Collectors.toList());
+ connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes, parameterIndexes));
Collection<DatabasePacket> actualPackets = executor.execute();
assertThat(actualPackets.size(), is(2));
Iterator<DatabasePacket> actualPacketsIterator = actualPackets.iterator();
@@ -202,7 +206,8 @@ class PostgreSQLComDescribeExecutorTest {
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME);
when(ProxyContext.getInstance().getDatabase(DATABASE_NAME)).thenReturn(database);
- connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes));
+ List<Integer> parameterIndexes = IntStream.range(0, sqlStatement.getParameterCount()).boxed().collect(Collectors.toList());
+ connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes, parameterIndexes));
Collection<DatabasePacket> actualPackets = executor.execute();
assertThat(actualPackets.size(), is(2));
Iterator<DatabasePacket> actualPacketsIterator = actualPackets.iterator();
@@ -232,7 +237,8 @@ class PostgreSQLComDescribeExecutorTest {
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME);
when(ProxyContext.getInstance().getDatabase(DATABASE_NAME)).thenReturn(database);
- connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes));
+ List<Integer> parameterIndexes = IntStream.range(0, sqlStatement.getParameterCount()).boxed().collect(Collectors.toList());
+ connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes, parameterIndexes));
assertThrows(ColumnNotFoundException.class, () -> executor.execute());
}
@@ -254,7 +260,8 @@ class PostgreSQLComDescribeExecutorTest {
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME);
when(ProxyContext.getInstance().getDatabase(DATABASE_NAME)).thenReturn(database);
- connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes));
+ List<Integer> parameterIndexes = IntStream.range(0, sqlStatement.getParameterCount()).boxed().collect(Collectors.toList());
+ connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes, parameterIndexes));
Collection<DatabasePacket> actualPackets = executor.execute();
assertThat(actualPackets.size(), is(2));
Iterator<DatabasePacket> actualPacketsIterator = actualPackets.iterator();
@@ -334,7 +341,8 @@ class PostgreSQLComDescribeExecutorTest {
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME);
when(ProxyContext.getInstance().getDatabase(DATABASE_NAME)).thenReturn(database);
- connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes));
+ List<Integer> parameterIndexes = IntStream.range(0, sqlStatement.getParameterCount()).boxed().collect(Collectors.toList());
+ connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, new PostgreSQLServerPreparedStatement(sql, sqlStatementContext, parameterTypes, parameterIndexes));
Collection<DatabasePacket> actual = executor.execute();
assertThat(actual.size(), is(2));
Iterator<DatabasePacket> actualPacketsIterator = actual.iterator();