From d8e0c48cd8a607a99d1bb01effd42b4ac508c3fe Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sun, 24 Nov 2024 21:51:54 +0800 Subject: [PATCH] Add DialectDatabaseMetaData.isDDLNeedImplicitCommit() to decouple Firebrid database type in driver module (#33783) --- .../database/DialectDatabaseMetaData.java | 9 +++++++++ .../database/FirebirdDatabaseMetaData.java | 5 +++++ .../jdbc/DriverJDBCPushDownExecuteExecutor.java | 15 ++++++++------- .../DriverJDBCPushDownExecuteUpdateExecutor.java | 15 ++++++++------- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/DialectDatabaseMetaData.java b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/DialectDatabaseMetaData.java index c62f2bc6de5a5..1a8eecca89ccf 100644 --- a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/DialectDatabaseMetaData.java +++ b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/DialectDatabaseMetaData.java @@ -138,4 +138,13 @@ default boolean isSupportThreeTierStorageStructure() { default boolean isSupportGlobalCSN() { return false; } + + /** + * Whether DDL need implicit commit. + * + * @return need or not + */ + default boolean isDDLNeedImplicitCommit() { + return false; + } } diff --git a/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java index a03a6e59680f5..cf86f821b7b32 100644 --- a/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java +++ b/infra/database/type/firebird/src/main/java/org/apache/shardingsphere/infra/database/firebird/metadata/database/FirebirdDatabaseMetaData.java @@ -41,6 +41,11 @@ public String formatTableNamePattern(final String tableNamePattern) { return tableNamePattern.toUpperCase(); } + @Override + public boolean isDDLNeedImplicitCommit() { + return true; + } + @Override public String getDatabaseType() { return "Firebird"; diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java index 5071dc31653d5..bc384be2e74af 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteExecutor.java @@ -27,6 +27,8 @@ import org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; +import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; +import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup; import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext; import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupReportContext; @@ -43,10 +45,8 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine; -import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DALStatement; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; -import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; import java.sql.Connection; import java.sql.ResultSet; @@ -104,7 +104,7 @@ private boolean doExecute(final ShardingSphereDatabase database, final Execution processEngine.executeSQL(executionGroupContext, executionContext.getQueryContext()); List results = jdbcExecutor.execute(executionGroupContext, new ExecuteCallbackFactory(prepareEngine.getType()).newInstance(database, executeCallback, executionContext.getSqlStatementContext().getSqlStatement())); - if (isNeedImplicitCommit(executionContext.getQueryContext().getSqlStatementContext().getSqlStatement())) { + if (isNeedImplicitCommit(executionContext.getQueryContext().getSqlStatementContext())) { connection.commit(); } if (MetaDataRefreshEngine.isRefreshMetaDataRequired(executionContext.getSqlStatementContext())) { @@ -125,10 +125,6 @@ private Collection getStatements(final ExecutionGroup> getParameterSets(final ExecutionGroup executionGroup) { Collection> result = new LinkedList<>(); for (JDBCExecutionUnit each : executionGroup.getInputs()) { @@ -137,6 +133,11 @@ private Collection> getParameterSets(final ExecutionGroup updateCounts = jdbcExecutor.execute(executionGroupContext, callback); if (MetaDataRefreshEngine.isRefreshMetaDataRequired(executionContext.getQueryContext().getSqlStatementContext())) { - if (isNeedImplicitCommit(executionContext.getQueryContext().getSqlStatementContext().getSqlStatement())) { + if (isNeedImplicitCommit(executionContext.getQueryContext().getSqlStatementContext())) { connection.commit(); } new MetaDataRefreshEngine(connection.getContextManager().getPersistServiceFacade().getMetaDataManagerPersistService(), database, props) @@ -129,10 +129,6 @@ private Collection getStatements(final ExecutionGroup> getParameterSets(final ExecutionGroup executionGroup) { Collection> result = new LinkedList<>(); for (JDBCExecutionUnit each : executionGroup.getInputs()) { @@ -141,6 +137,11 @@ private Collection> getParameterSets(final ExecutionGroup rules, final SQLStatementContext sqlStatementContext) { if (!(sqlStatementContext instanceof TableAvailable)) { return false;