This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 3001dbef53d Refactor QueryHeaderBuilder protocol attribute population
(#39248)
3001dbef53d is described below
commit 3001dbef53dd5ac4b9afbad96709468e863052e9
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jul 28 11:02:45 2026 +0800
Refactor QueryHeaderBuilder protocol attribute population (#39248)
* Strengthen AI implementation boundaries and review loop
* Strengthen AI implementation boundaries and review loop
* Refactor QueryHeaderBuilder protocol attribute population
* Refactor QueryHeaderBuilder protocol attribute population
* Refactor QueryHeaderBuilder protocol attribute population
---
.../backend/response/header/query/QueryHeader.java | 9 ++-----
.../response/header/query/QueryHeaderBuilder.java | 13 +++-------
.../header/query/QueryHeaderBuilderEngine.java | 9 ++++---
.../StandardDatabaseProxyConnectorTest.java | 5 ++--
.../header/query/QueryHeaderBuilderEngineTest.java | 4 ++-
.../header/query/PostgreSQLQueryHeaderBuilder.java | 30 ++++++----------------
.../query/PostgreSQLQueryHeaderBuilderTest.java | 12 ++++++---
.../command/query/extended/PortalTest.java | 4 +--
.../simple/PostgreSQLComQueryExecutorTest.java | 14 +++++-----
9 files changed, 41 insertions(+), 59 deletions(-)
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeader.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeader.java
index d8d756b5ef3..8045818a908 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeader.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeader.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.proxy.backend.response.header.query;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -54,10 +54,5 @@ public final class QueryHeader {
private final boolean autoIncrement;
- private final Map<String, Object> protocolAttributes;
-
- public QueryHeader(final String schema, final String table, final String
columnLabel, final String columnName, final int columnType, final String
columnTypeName,
- final int columnLength, final int decimals, final
boolean signed, final boolean primaryKey, final boolean notNull, final boolean
autoIncrement) {
- this(schema, table, columnLabel, columnName, columnType,
columnTypeName, columnLength, decimals, signed, primaryKey, notNull,
autoIncrement, Collections.emptyMap());
- }
+ private final Map<String, Object> protocolAttributes = new HashMap<>();
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java
index 26a7a92099b..45f82d2e543 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilder.java
@@ -45,19 +45,12 @@ public interface QueryHeaderBuilder extends
DatabaseTypedSPI {
QueryHeader build(ShardingSphereResultSetMetaData resultSetMetaData,
ShardingSphereDatabase database, String columnName, String columnLabel, int
columnIndex) throws SQLException;
/**
- * Build query header.
+ * Append protocol attributes to a query header built by this builder
before it is published.
*
- * @param resultSetMetaData result set meta data
+ * @param queryHeader query header
* @param resultSet JDBC result set
- * @param database database
- * @param columnName column name
- * @param columnLabel column label
- * @param columnIndex column index
- * @return query header
* @throws SQLException SQL exception
*/
- default QueryHeader build(final ShardingSphereResultSetMetaData
resultSetMetaData, final ResultSet resultSet, final ShardingSphereDatabase
database,
- final String columnName, final String
columnLabel, final int columnIndex) throws SQLException {
- return build(resultSetMetaData, database, columnName, columnLabel,
columnIndex);
+ default void appendProtocolAttributes(final QueryHeader queryHeader, final
ResultSet resultSet) throws SQLException {
}
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java
index 24a3546bdcc..aa5a7b481ff 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngine.java
@@ -88,10 +88,11 @@ public final class QueryHeaderBuilderEngine {
public QueryHeader build(final SQLStatementContext sqlStatementContext,
final ShardingSphereResultSetMetaData resultSetMetaData, final ResultSet
resultSet,
final ShardingSphereDatabase database, final int
columnIndex) throws SQLException {
Projection projection = findProjection(sqlStatementContext,
columnIndex);
- if (null == projection) {
- return queryHeaderBuilder.build(resultSetMetaData, resultSet,
database, resultSetMetaData.getColumnName(columnIndex),
resultSetMetaData.getColumnLabel(columnIndex), columnIndex);
- }
- return queryHeaderBuilder.build(resultSetMetaData, resultSet,
database, projection.getColumnName(), projection.getColumnLabel(), columnIndex);
+ QueryHeader result = null == projection
+ ? queryHeaderBuilder.build(resultSetMetaData, database,
resultSetMetaData.getColumnName(columnIndex),
resultSetMetaData.getColumnLabel(columnIndex), columnIndex)
+ : queryHeaderBuilder.build(resultSetMetaData, database,
projection.getColumnName(), projection.getColumnLabel(), columnIndex);
+ queryHeaderBuilder.appendProtocolAttributes(result, resultSet);
+ return result;
}
private Projection findProjection(final SQLStatementContext
sqlStatementContext, final int columnIndex) {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseProxyConnectorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseProxyConnectorTest.java
index 638ddd37c75..cb1861c97da 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseProxyConnectorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseProxyConnectorTest.java
@@ -512,7 +512,7 @@ class StandardDatabaseProxyConnectorTest {
when(dialectDatabaseMetaData.getTransactionOption()).thenReturn(dialectTransactionOption);
QueryHeaderBuilder queryHeaderBuilder = mock(QueryHeaderBuilder.class);
QueryHeader queryHeader = new QueryHeader("", "", "order_id",
"order_id", Types.INTEGER, "int4", 4, 0, true, false, false, false);
-
when(queryHeaderBuilder.build(any(ShardingSphereResultSetMetaData.class),
eq(resultSet), any(), eq("order_id"), eq("order_id"),
eq(1))).thenReturn(queryHeader);
+
when(queryHeaderBuilder.build(any(ShardingSphereResultSetMetaData.class),
any(), eq("order_id"), eq("order_id"), eq(1))).thenReturn(queryHeader);
try (
MockedConstruction<KernelProcessor> mockedKernelProcessor =
mockConstruction(KernelProcessor.class,
(mock, context) ->
when(mock.generateExecutionContext(any(QueryContext.class),
any(RuleMetaData.class),
any(ConfigurationProperties.class))).thenReturn(executionContext));
@@ -530,7 +530,8 @@ class StandardDatabaseProxyConnectorTest {
assertThat(mockedMergeEngine.constructed().size(), is(1));
assertTrue(engine.next());
assertNotNull(engine.getRowData());
-
verify(queryHeaderBuilder).build(any(ShardingSphereResultSetMetaData.class),
eq(resultSet), any(), eq("order_id"), eq("order_id"), eq(1));
+
verify(queryHeaderBuilder).build(any(ShardingSphereResultSetMetaData.class),
any(), eq("order_id"), eq("order_id"), eq(1));
+ verify(queryHeaderBuilder).appendProtocolAttributes(queryHeader,
resultSet);
}
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngineTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngineTest.java
index df98fc08b3f..75522e2a009 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngineTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderEngineTest.java
@@ -39,6 +39,7 @@ import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class QueryHeaderBuilderEngineTest {
@@ -94,11 +95,12 @@ class QueryHeaderBuilderEngineTest {
QueryHeader expectedQueryHeader = mock(QueryHeader.class);
try (MockedStatic<DatabaseTypedSPILoader> spiLoader =
mockStatic(DatabaseTypedSPILoader.class)) {
QueryHeaderBuilder queryHeaderBuilder =
mock(QueryHeaderBuilder.class);
- when(queryHeaderBuilder.build(resultSetMetaData, resultSet,
database, "col_name", "col_label", 1)).thenReturn(expectedQueryHeader);
+ when(queryHeaderBuilder.build(resultSetMetaData, database,
"col_name", "col_label", 1)).thenReturn(expectedQueryHeader);
spiLoader.when(() ->
DatabaseTypedSPILoader.getService(QueryHeaderBuilder.class,
databaseType)).thenReturn(queryHeaderBuilder);
QueryHeader actualQueryHeader =
new
QueryHeaderBuilderEngine(databaseType).build(sqlStatementContext,
resultSetMetaData, resultSet, database, 1);
assertThat(actualQueryHeader, is(expectedQueryHeader));
+
verify(queryHeaderBuilder).appendProtocolAttributes(expectedQueryHeader,
resultSet);
}
}
diff --git
a/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilder.java
b/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilder.java
index a3199c6039f..86bada17f08 100644
---
a/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilder.java
+++
b/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilder.java
@@ -26,9 +26,6 @@ import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
/**
* Query header builder for PostgreSQL.
@@ -46,29 +43,18 @@ public final class PostgreSQLQueryHeaderBuilder implements
QueryHeaderBuilder {
@Override
public QueryHeader build(final ShardingSphereResultSetMetaData
resultSetMetaData, final ShardingSphereDatabase database, final String
columnName, final String columnLabel,
final int columnIndex) throws SQLException {
- return createQueryHeader(columnLabel,
- resultSetMetaData.getColumnType(columnIndex),
resultSetMetaData.getColumnTypeName(columnIndex),
resultSetMetaData.getColumnDisplaySize(columnIndex), Collections.emptyMap());
- }
-
- @Override
- public QueryHeader build(final ShardingSphereResultSetMetaData
resultSetMetaData, final ResultSet resultSet, final ShardingSphereDatabase
database, final String columnName,
- final String columnLabel, final int columnIndex)
throws SQLException {
int columnType = resultSetMetaData.getColumnType(columnIndex);
- String columnTypeName =
resultSetMetaData.getColumnTypeName(columnIndex);
- return createQueryHeader(columnLabel, columnType, columnTypeName,
resultSetMetaData.getColumnDisplaySize(columnIndex),
getProtocolAttributes(resultSet, columnType, columnTypeName));
+ final String columnTypeName =
resultSetMetaData.getColumnTypeName(columnIndex);
+ return new QueryHeader(UNUSED_STRING_FIELD, UNUSED_STRING_FIELD,
columnLabel, UNUSED_STRING_FIELD, columnType, columnTypeName,
resultSetMetaData.getColumnDisplaySize(columnIndex),
+ UNUSED_INT_FIELD, UNUSED_BOOLEAN_FIELD, UNUSED_BOOLEAN_FIELD,
UNUSED_BOOLEAN_FIELD, UNUSED_BOOLEAN_FIELD);
}
- private QueryHeader createQueryHeader(final String columnLabel, final int
columnType, final String columnTypeName, final int columnLength, final
Map<String, Object> protocolAttributes) {
- return new QueryHeader(UNUSED_STRING_FIELD, UNUSED_STRING_FIELD,
columnLabel, UNUSED_STRING_FIELD, columnType, columnTypeName, columnLength,
- UNUSED_INT_FIELD, UNUSED_BOOLEAN_FIELD, UNUSED_BOOLEAN_FIELD,
UNUSED_BOOLEAN_FIELD, UNUSED_BOOLEAN_FIELD, protocolAttributes);
- }
-
- private Map<String, Object> getProtocolAttributes(final ResultSet
resultSet, final int columnType, final String columnTypeName) throws
SQLException {
- if (Types.STRUCT != columnType) {
- return Collections.emptyMap();
+ @Override
+ public void appendProtocolAttributes(final QueryHeader queryHeader, final
ResultSet resultSet) throws SQLException {
+ if (Types.STRUCT == queryHeader.getColumnType()) {
+
PostgreSQLColumnTypeOIDLoader.findTypeOID(resultSet.getStatement().getConnection(),
queryHeader.getColumnTypeName())
+ .ifPresent(optional ->
queryHeader.getProtocolAttributes().put(TYPE_OID, optional));
}
- Optional<Integer> typeOID =
PostgreSQLColumnTypeOIDLoader.findTypeOID(resultSet.getStatement().getConnection(),
columnTypeName);
- return typeOID.<Map<String, Object>>map(integer ->
Collections.singletonMap(TYPE_OID, integer)).orElse(Collections.emptyMap());
}
@Override
diff --git
a/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilderTest.java
b/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilderTest.java
index f8f82b5eb5d..14251dd4c82 100644
---
a/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilderTest.java
+++
b/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/response/header/query/PostgreSQLQueryHeaderBuilderTest.java
@@ -56,7 +56,7 @@ class PostgreSQLQueryHeaderBuilderTest {
}
@Test
- void assertBuildPostgreSQLCompositeQueryHeader() throws SQLException {
+ void assertAppendProtocolAttributes() throws SQLException {
int columnIndex = 1;
ShardingSphereResultSetMetaData resultSetMetaData =
mock(ShardingSphereResultSetMetaData.class);
when(resultSetMetaData.getColumnType(columnIndex)).thenReturn(Types.STRUCT);
@@ -68,17 +68,21 @@ class PostgreSQLQueryHeaderBuilderTest {
when(statement.getConnection()).thenReturn(connection);
try (MockedStatic<PostgreSQLColumnTypeOIDLoader> loader =
mockStatic(PostgreSQLColumnTypeOIDLoader.class)) {
loader.when(() ->
PostgreSQLColumnTypeOIDLoader.findTypeOID(connection,
"record_type")).thenReturn(Optional.of(2249));
- QueryHeader actual = new
PostgreSQLQueryHeaderBuilder().build(resultSetMetaData, resultSet, null, null,
"record", columnIndex);
+ PostgreSQLQueryHeaderBuilder builder = new
PostgreSQLQueryHeaderBuilder();
+ QueryHeader actual = builder.build(resultSetMetaData, null, null,
"record", columnIndex);
+ builder.appendProtocolAttributes(actual, resultSet);
assertThat(actual.getProtocolAttributes().get(PostgreSQLQueryHeaderBuilder.TYPE_OID),
is(2249));
}
}
@Test
- void assertBuildPostgreSQLQueryHeaderFromResultSet() throws SQLException {
+ void assertAppendProtocolAttributesForNonCompositeColumn() throws
SQLException {
ShardingSphereResultSetMetaData resultSetMetaData =
mock(ShardingSphereResultSetMetaData.class);
when(resultSetMetaData.getColumnType(1)).thenReturn(Types.INTEGER);
ResultSet resultSet = mock(ResultSet.class);
- QueryHeader actual = new
PostgreSQLQueryHeaderBuilder().build(resultSetMetaData, resultSet, null, null,
"id", 1);
+ PostgreSQLQueryHeaderBuilder builder = new
PostgreSQLQueryHeaderBuilder();
+ QueryHeader actual = builder.build(resultSetMetaData, null, null,
"id", 1);
+ builder.appendProtocolAttributes(actual, resultSet);
assertTrue(actual.getProtocolAttributes().isEmpty());
verifyNoInteractions(resultSet);
}
diff --git
a/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
b/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
index b026d5f3b06..a493db7ae19 100644
---
a/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
+++
b/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
@@ -137,8 +137,8 @@ class PortalTest {
@Test
void assertExecuteSelectStatementAndReturnAllRows() throws SQLException,
ReflectiveOperationException {
QueryResponseHeader responseHeader = mock(QueryResponseHeader.class);
- QueryHeader queryHeader = new QueryHeader("schema", "table",
"columnLabel", "columnName", Types.STRUCT, "record_type", 0, 0, false, false,
false, false,
-
Collections.singletonMap(PostgreSQLQueryHeaderBuilder.TYPE_OID, 2249));
+ QueryHeader queryHeader = new QueryHeader("schema", "table",
"columnLabel", "columnName", Types.STRUCT, "record_type", 0, 0, false, false,
false, false);
+
queryHeader.getProtocolAttributes().put(PostgreSQLQueryHeaderBuilder.TYPE_OID,
2249);
QueryHeader binaryQueryHeader = new QueryHeader("schema", "table",
"columnLabel", "columnName", Types.STRUCT, "record_type", 0, 0, false, false,
false, false);
when(responseHeader.getQueryHeaders()).thenReturn(Arrays.asList(queryHeader,
binaryQueryHeader));
when(proxyBackendHandler.execute()).thenReturn(responseHeader);
diff --git
a/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java
b/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java
index 2c64ed34715..38da72425a3 100644
---
a/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java
+++
b/proxy/frontend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java
@@ -18,6 +18,7 @@
package
org.apache.shardingsphere.proxy.frontend.postgresql.command.query.simple;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import
org.apache.shardingsphere.database.exception.core.exception.data.InvalidParameterValueException;
import org.apache.shardingsphere.database.protocol.packet.DatabasePacket;
import
org.apache.shardingsphere.database.protocol.postgresql.packet.PostgreSQLPacket;
import
org.apache.shardingsphere.database.protocol.postgresql.packet.command.query.PostgreSQLColumnDescription;
@@ -27,18 +28,17 @@ import
org.apache.shardingsphere.database.protocol.postgresql.packet.command.que
import
org.apache.shardingsphere.database.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket;
import
org.apache.shardingsphere.database.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket;
import
org.apache.shardingsphere.database.protocol.postgresql.packet.handshake.PostgreSQLParameterStatusPacket;
-import
org.apache.shardingsphere.database.exception.core.exception.data.InvalidParameterValueException;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.handler.ProxySQLComQueryParser;
+import
org.apache.shardingsphere.proxy.backend.postgresql.response.header.query.PostgreSQLQueryHeaderBuilder;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import
org.apache.shardingsphere.proxy.backend.postgresql.response.header.query.PostgreSQLQueryHeaderBuilder;
import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import
org.apache.shardingsphere.proxy.frontend.postgresql.command.PortalContext;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dal.VariableAssignSegment;
@@ -72,11 +72,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
-import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -117,9 +117,9 @@ class PostgreSQLComQueryExecutorTest {
@Test
void assertExecuteQueryWithColumnDescription() throws SQLException,
ReflectiveOperationException {
QueryResponseHeader queryResponseHeader =
mock(QueryResponseHeader.class);
- when(queryResponseHeader.getQueryHeaders()).thenReturn(
- Collections.singletonList(new QueryHeader("schema", "table",
"label", "column", Types.STRUCT, "record_type", 2, 3, true, true, true, true,
-
Collections.singletonMap(PostgreSQLQueryHeaderBuilder.TYPE_OID, 2249))));
+ QueryHeader queryHeader = new QueryHeader("schema", "table", "label",
"column", Types.STRUCT, "record_type", 2, 3, true, true, true, true);
+
queryHeader.getProtocolAttributes().put(PostgreSQLQueryHeaderBuilder.TYPE_OID,
2249);
+
when(queryResponseHeader.getQueryHeaders()).thenReturn(Collections.singletonList(queryHeader));
when(proxyBackendHandler.execute()).thenReturn(queryResponseHeader);
Collection<DatabasePacket> actual = queryExecutor.execute();
PostgreSQLRowDescriptionPacket rowDescriptionPacket =
(PostgreSQLRowDescriptionPacket) actual.iterator().next();