This is an automated email from the ASF dual-hosted git repository.
menghaoranss 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 d1a5becae7b Use database default schema in Firebird prepare executor
(#39594)
d1a5becae7b is described below
commit d1a5becae7bc7fc8cab8a558369753df79233361
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Aug 25 11:23:43 2026 +0800
Use database default schema in Firebird prepare executor (#39594)
---
.../prepare/FirebirdPrepareStatementCommandExecutor.java | 14 +++++++-------
.../FirebirdPrepareStatementCommandExecutorTest.java | 12 +++++++++---
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git
a/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
b/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
index f5eec4e6bad..67246f91ee5 100644
---
a/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
+++
b/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.proxy.frontend.firebird.command.query.statemen
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import
org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
import
org.apache.shardingsphere.database.connector.firebird.metadata.data.FirebirdBlobInfoRegistry;
import
org.apache.shardingsphere.database.connector.firebird.metadata.data.FirebirdNonFixedLengthColumnSizeRegistry;
import
org.apache.shardingsphere.database.exception.core.exception.syntax.database.NoDatabaseSelectedException;
@@ -48,6 +47,7 @@ import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectS
import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.UpdateStatementContext;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
@@ -238,8 +238,8 @@ public final class FirebirdPrepareStatementCommandExecutor
implements CommandExe
private void processReturnValues(final SQLStatementContext
sqlStatementContext, final MetaDataContexts metaDataContexts, final
Collection<FirebirdReturnColumnPacket> describeColumns,
final
Collection<FirebirdSQLInfoPacketType> requestedItems) {
String databaseName = connectionSession.getCurrentDatabaseName();
- String schemaName = new
DatabaseTypeRegistry(sqlStatementContext.getSqlStatement().getDatabaseType()).getDefaultSchemaName(databaseName);
- ShardingSphereSchema schema =
metaDataContexts.getMetaData().getDatabase(databaseName).getSchema(schemaName);
+ ShardingSphereDatabase database =
metaDataContexts.getMetaData().getDatabase(databaseName);
+ ShardingSphereSchema schema =
database.findDefaultSchema().orElse(null);
Collection<Projection> projections =
getProjections(sqlStatementContext, schema);
int columnCount = 0;
for (Projection each : projections) {
@@ -327,10 +327,10 @@ public final class
FirebirdPrepareStatementCommandExecutor implements CommandExe
Collection<ColumnSegment> affectedColumns =
findAffectedColumns(sqlStatementContext);
int parametersCount =
sqlStatementContext.getSqlStatement().getParameterMarkers().size();
String databaseName = connectionSession.getCurrentDatabaseName();
- String schemaName = new
DatabaseTypeRegistry(sqlStatementContext.getSqlStatement().getDatabaseType()).getDefaultSchemaName(databaseName);
+ ShardingSphereSchema schema =
metaDataContexts.getMetaData().getDatabase(databaseName).findDefaultSchema().orElse(null);
int columnCount = 0;
for (ColumnSegment columnSegment : affectedColumns) {
- ShardingSphereTable table =
metaDataContexts.getMetaData().getDatabase(databaseName).getSchema(schemaName).getTable(columnSegment.getColumnBoundInfo().getOriginalTable().getValue());
+ ShardingSphereTable table =
schema.getTable(columnSegment.getColumnBoundInfo().getOriginalTable().getValue());
ShardingSphereColumn column =
table.getColumn(columnSegment.getColumnBoundInfo().getOriginalColumn().getValue());
processColumn(describeColumns, requestedItems, table, column,
columnSegment.getOwner().map(OwnerSegment::getIdentifier).orElse(null),
columnSegment.getIdentifier(), ++columnCount);
}
@@ -347,10 +347,10 @@ public final class
FirebirdPrepareStatementCommandExecutor implements CommandExe
affectedColumns.addAll(processInsertValueContext(sqlStatementContext, context));
}
String databaseName = connectionSession.getCurrentDatabaseName();
- String schemaName = new
DatabaseTypeRegistry(sqlStatementContext.getSqlStatement().getDatabaseType()).getDefaultSchemaName(databaseName);
+ ShardingSphereSchema schema =
metaDataContexts.getMetaData().getDatabase(databaseName).findDefaultSchema().orElse(null);
int columnCount = 0;
for (String tableName : tableNames) {
- ShardingSphereTable table =
metaDataContexts.getMetaData().getDatabase(databaseName).getSchema(schemaName).getTable(tableName);
+ ShardingSphereTable table = schema.getTable(tableName);
for (String columnName : affectedColumns) {
ShardingSphereColumn column = table.getColumn(columnName);
processColumn(describeColumns, requestedItems, table, column,
null, null, ++columnCount);
diff --git
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
index 4a721c557e0..f1145d48038 100644
---
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
+++
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
@@ -71,6 +71,7 @@ import java.sql.Types;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -78,7 +79,9 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -121,7 +124,8 @@ class FirebirdPrepareStatementCommandExecutorTest {
when(packet.getStatementId()).thenReturn(1);
when(packet.nextItem()).thenReturn(true, false);
when(packet.getCurrentItem()).thenReturn(FirebirdSQLInfoPacketType.STMT_TYPE);
-
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts()).thenReturn(createMetaDataContexts());
+ MetaDataContexts metaDataContexts = createMetaDataContexts();
+
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts()).thenReturn(metaDataContexts);
}
@AfterEach
@@ -138,9 +142,11 @@ class FirebirdPrepareStatementCommandExecutorTest {
ShardingSphereColumn blobColumn = new ShardingSphereColumn("content",
Types.BLOB, false, false, true, true, false, true);
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Arrays.asList(column, blobColumn), Collections.emptyList(),
Collections.emptyList());
ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType, Collections.singleton(table), Collections.emptyList());
- ShardingSphereDatabase database = new ShardingSphereDatabase(
+ ShardingSphereDatabase database = spy(new ShardingSphereDatabase(
"foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), Collections.singleton(schema),
- new ConfigurationProperties(new Properties()));
+ new ConfigurationProperties(new Properties())));
+ doReturn(Optional.of(schema)).when(database).findDefaultSchema();
+ doReturn(null).when(database).getSchema("FOO_DB");
ShardingSphereMetaData metaData = new ShardingSphereMetaData(
Collections.singleton(database), new
ResourceMetaData(Collections.emptyMap()), globalRuleMetaData, new
ConfigurationProperties(new Properties()));
return new MetaDataContexts(metaData, new ShardingSphereStatistics());