You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/04/19 10:51:53 UTC
[shardingsphere] branch master updated: Refactor governance event param and rename schema to database (#16919)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 b91c4f3b563 Refactor governance event param and rename schema to database (#16919)
b91c4f3b563 is described below
commit b91c4f3b5633c80060b2abd33bc3638a05fda6a5
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Tue Apr 19 18:51:46 2022 +0800
Refactor governance event param and rename schema to database (#16919)
* Rename schemaName to databaseName
* Rename schema name to database name
* Rename
* Rename database name
* Fix CI
* Rename schema to database
* Rename
* Fixed unit test
* Adjust qualified database
---
.../protocol/mysql/constant/MySQLServerInfo.java | 14 +-
.../dbdiscovery/spi/DatabaseDiscoveryType.java | 12 +-
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 8 +-
.../fixture/TestDatabaseDiscoveryType.java | 6 +-
.../fixture/MGRDatabaseDiscoveryTypeFixture.java | 6 +-
.../mysql/AbstractDatabaseDiscoveryType.java | 6 +-
.../mysql/type/MGRDatabaseDiscoveryType.java | 10 +-
.../type/ShowSlaveStatusDatabaseDiscoveryType.java | 16 +-
.../opengauss/OpenGaussDatabaseDiscoveryType.java | 12 +-
.../rule/ReadwriteSplittingRule.java | 2 +-
.../rule/ReadwriteSplittingRuleTest.java | 10 +-
...QualifiedSchema.java => QualifiedDatabase.java} | 12 +-
.../metadata/schema/event/SchemaAlteredEvent.java | 5 +-
.../metadata/schema/util/SystemSchemaUtil.java | 6 +-
.../rule/event/impl/DataSourceDisabledEvent.java | 2 +-
.../event/impl/DataSourceNameDisabledEvent.java | 4 +-
.../event/impl/PrimaryDataSourceChangedEvent.java | 4 +-
...dSchemaTest.java => QualifiedDatabaseTest.java} | 8 +-
.../type/AlterIndexStatementSchemaRefresher.java | 3 +-
.../type/AlterTableStatementSchemaRefresher.java | 3 +-
.../type/AlterViewStatementSchemaRefresher.java | 3 +-
.../type/CreateIndexStatementSchemaRefresher.java | 3 +-
.../type/CreateTableStatementSchemaRefresher.java | 3 +-
.../type/CreateViewStatementSchemaRefresher.java | 3 +-
.../type/DropIndexStatementSchemaRefresher.java | 7 +-
.../type/DropTableStatementSchemaRefresher.java | 3 +-
.../type/DropViewStatementSchemaRefresher.java | 3 +-
.../type/RenameTableStatementSchemaRefresher.java | 3 +-
.../infra/executor/check/SQLCheckEngine.java | 14 +-
.../infra/executor/check/SQLChecker.java | 10 +-
.../authority/checker/AuthorityChecker.java | 10 +-
.../mode/manager/ContextManager.java | 236 ++++++++++-----------
.../mode/metadata/MetaDataContexts.java | 12 +-
.../metadata/persist/MetaDataPersistService.java | 4 +-
.../persist/node/DatabaseMetaDataNode.java | 6 +-
.../service/SchemaMetaDataPersistService.java | 27 +--
.../service/impl/DatabaseRulePersistService.java | 6 +-
.../mode/manager/ContextManagerTest.java | 102 ++++-----
.../service/SchemaMetaDataPersistServiceTest.java | 4 +-
.../cluster/ClusterContextManagerBuilder.java | 6 +-
.../ClusterContextManagerCoordinator.java | 58 ++---
.../event/datasource/DataSourceChangedEvent.java | 2 +-
.../event/rule/RuleConfigurationsChangedEvent.java | 2 +-
.../config/event/schema/SchemaChangedEvent.java | 2 +
.../event/version/SchemaVersionChangedEvent.java | 2 +-
...maDeletedEvent.java => DatabaseAddedEvent.java} | 6 +-
...maAddedEvent.java => DatabaseDeletedEvent.java} | 6 +-
.../SchemaMetaDataRegistrySubscriber.java | 4 +-
.../metadata/watcher/MetaDataChangedWatcher.java | 32 +--
.../storage/event/DisabledStateChangedEvent.java | 4 +-
.../storage/event/PrimaryStateChangedEvent.java | 4 +-
.../status/storage/node/StorageStatusNode.java | 8 +-
.../subscriber/StorageNodeStatusSubscriber.java | 6 +-
.../watcher/StorageNodeStateChangedWatcher.java | 6 +-
.../ClusterContextManagerCoordinatorTest.java | 78 +++----
.../SchemaMetaDataRegistrySubscriberTest.java | 6 +-
.../status/storage/node/StorageStatusNodeTest.java | 6 +-
.../StorageNodeStatusSubscriberTest.java | 10 +-
.../StorageNodeStateChangedWatcherTest.java | 10 +-
.../communication/DatabaseCommunicationEngine.java | 8 +-
.../DatabaseCommunicationEngineFactory.java | 4 +-
.../backend/communication/ProxySQLExecutor.java | 10 +-
.../communication/ReactiveProxySQLExecutor.java | 8 +-
.../jdbc/JDBCDatabaseCommunicationEngine.java | 12 +-
.../jdbc/connection/JDBCBackendConnection.java | 4 +-
.../jdbc/executor/ProxyJDBCExecutor.java | 2 +-
.../callback/ProxyJDBCExecutorCallback.java | 4 +-
.../transaction/JDBCBackendTransactionManager.java | 2 +-
.../vertx/VertxBackendConnection.java | 8 +-
.../proxy/backend/context/ProxyContext.java | 28 +--
.../proxy/backend/session/ConnectionSession.java | 32 +--
.../backend/text/SchemaRequiredBackendHandler.java | 20 +-
.../text/TextProtocolBackendHandlerFactory.java | 16 +-
.../admin/DatabaseAdminBackendHandlerFactory.java | 2 +-
.../admin/DatabaseAdminQueryBackendHandler.java | 2 +-
.../executor/AbstractDatabaseMetadataExecutor.java | 60 +++---
.../admin/mysql/MySQLAdminExecutorFactory.java | 14 +-
.../mysql/executor/ShowCreateDatabaseExecutor.java | 8 +-
.../executor/ShowCurrentDatabaseExecutor.java | 2 +-
.../mysql/executor/ShowDatabasesExecutor.java | 2 +-
.../admin/mysql/executor/ShowTablesExecutor.java | 18 +-
.../admin/mysql/executor/ShowVersionExecutor.java | 2 +-
.../executor/UnicastResourceShowExecutor.java | 20 +-
.../admin/mysql/executor/UseDatabaseExecutor.java | 8 +-
.../SelectInformationSchemataExecutor.java | 10 +-
.../opengauss/OpenGaussSelectDatabaseExecutor.java | 6 +-
.../executor/SelectDatabaseExecutor.java | 12 +-
.../postgresql/executor/SelectTableExecutor.java | 10 +-
.../data/impl/BroadcastDatabaseBackendHandler.java | 26 +--
.../impl/SchemaAssignedDatabaseBackendHandler.java | 8 +-
.../data/impl/UnicastDatabaseBackendHandler.java | 28 +--
.../database/CreateDatabaseBackendHandler.java | 4 +-
.../text/database/DropDatabaseBackendHandler.java | 16 +-
.../text/distsql/DistSQLBackendHandlerFactory.java | 14 +-
.../ral/advanced/ParseDistSQLBackendHandler.java | 6 +-
.../ral/advanced/PreviewDistSQLBackendHandler.java | 20 +-
.../executor/ShowShardingHintStatusExecutor.java | 2 +-
.../queryable/CountInstanceRulesHandler.java | 2 +-
.../ExportSchemaConfigurationHandler.java | 12 +-
...ShowReadwriteSplittingReadResourcesHandler.java | 20 +-
.../common/queryable/ShowTableMetadataHandler.java | 22 +-
.../ImportSchemaConfigurationHandler.java | 12 +-
.../updatable/RefreshTableMetadataHandler.java | 18 +-
.../SetReadwriteSplittingStatusHandler.java | 68 +++---
.../rdl/resource/AddResourceBackendHandler.java | 10 +-
.../rdl/resource/AlterResourceBackendHandler.java | 6 +-
.../rdl/rule/RuleDefinitionBackendHandler.java | 2 +-
.../DatabaseCommunicationEngineFactoryTest.java | 6 +-
.../jdbc/JDBCDatabaseCommunicationEngineTest.java | 4 +-
.../jdbc/connection/JDBCBackendConnectionTest.java | 4 +-
.../JDBCBackendTransactionManagerTest.java | 4 +-
.../proxy/backend/context/ProxyContextTest.java | 26 +--
.../backend/session/ConnectionSessionTest.java | 10 +-
.../TextProtocolBackendHandlerFactoryTest.java | 12 +-
.../DatabaseOperateBackendHandlerFactoryTest.java | 12 +-
.../executor/ShowCreateDatabaseExecutorTest.java | 10 +-
.../executor/ShowFunctionStatusExecutorTest.java | 6 +-
.../executor/ShowProcedureStatusExecutorTest.java | 6 +-
.../mysql/executor/ShowTablesExecutorTest.java | 6 +-
.../mysql/executor/ShowVersionExecutorTest.java | 8 +-
.../mysql/executor/UseDatabaseExecutorTest.java | 12 +-
.../executor/fixture/AuthorityCheckerFixture.java | 6 +-
.../OpenGaussSelectDatabaseExecutorTest.java | 2 +-
.../impl/BroadcastDatabaseBackendHandlerTest.java | 6 +-
.../SchemaAssignedDatabaseBackendHandlerTest.java | 6 +-
.../impl/UnicastDatabaseBackendHandlerTest.java | 6 +-
.../database/CreateDatabaseBackendHandlerTest.java | 2 +-
.../database/DropDatabaseBackendHandlerTest.java | 12 +-
.../distsql/DistSQLBackendHandlerFactoryTest.java | 16 +-
.../distsql/fixture/TestDatabaseDiscoveryType.java | 6 +-
.../common/queryable/CountInstanceRulesTest.java | 6 +-
.../ExportSchemaConfigurationHandlerTest.java | 2 +-
.../queryable/ShowTableMetadataHandlerTest.java | 10 +-
.../queryable/ShowVariableBackendHandlerTest.java | 12 +-
.../ImportSchemaConfigurationHandlerTest.java | 2 +-
.../updatable/SetVariableBackendHandlerTest.java | 18 +-
.../resource/AddResourceBackendHandlerTest.java | 12 +-
.../resource/AlterResourceBackendHandlerTest.java | 20 +-
.../resource/DropResourceBackendHandlerTest.java | 2 +-
.../text/distsql/rql/RQLBackendHandlerTest.java | 2 +-
.../rql/RuleDefinitionBackendHandlerTest.java | 4 +-
.../proxy/version/ShardingSphereProxyVersion.java | 8 +-
.../frontend/command/CommandExecutorTask.java | 2 +-
.../netty/FrontendChannelInboundHandler.java | 2 +-
.../netty/FrontendChannelInboundHandlerTest.java | 2 +-
.../FrontDatabaseProtocolTypeFactoryTest.java | 4 +-
.../authentication/MySQLAuthenticationEngine.java | 2 +-
.../admin/initdb/MySQLComInitDbExecutor.java | 10 +-
.../execute/MySQLComStmtExecuteExecutor.java | 12 +-
.../prepare/MySQLComStmtPrepareExecutor.java | 6 +-
.../fieldlist/MySQLComFieldListPacketExecutor.java | 12 +-
.../text/query/MySQLMultiStatementsHandler.java | 12 +-
.../command/MySQLCommandExecutorFactoryTest.java | 4 +-
.../execute/MySQLComStmtExecuteExecutorTest.java | 12 +-
.../query/MySQLComQueryPacketExecutorTest.java | 4 +-
.../query/MySQLMultiStatementsHandlerTest.java | 2 +-
.../OpenGaussAuthenticationHandler.java | 4 +-
.../PostgreSQLAuthenticationHandler.java | 4 +-
.../command/query/extended/JDBCPortal.java | 6 +-
.../PostgreSQLBatchedStatementsExecutor.java | 10 +-
.../describe/PostgreSQLComDescribeExecutor.java | 10 +-
.../extended/parse/PostgreSQLComParseExecutor.java | 2 +-
.../PostgreSQLComDescribeExecutorTest.java | 8 +-
.../parse/PostgreSQLComParseExecutorTest.java | 15 +-
.../ReactiveMySQLComStmtExecuteExecutor.java | 8 +-
.../ReactiveMySQLComFieldListPacketExecutor.java | 12 +-
166 files changed, 966 insertions(+), 981 deletions(-)
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
index 5a2d9cf54e5..f62ca0ba7b7 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
@@ -47,24 +47,24 @@ public final class MySQLServerInfo {
/**
* Set server version.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param serverVersion server version
*/
- public static void setServerVersion(final String schemaName, final String serverVersion) {
- SERVER_VERSIONS.put(schemaName, String.format(SERVER_VERSION_PATTERN, serverVersion, CommonConstants.PROXY_VERSION.get()));
+ public static void setServerVersion(final String databaseName, final String serverVersion) {
+ SERVER_VERSIONS.put(databaseName, String.format(SERVER_VERSION_PATTERN, serverVersion, CommonConstants.PROXY_VERSION.get()));
}
/**
* Get current server version by schemaName.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @return server version
*/
- public static String getServerVersion(final String schemaName) {
- if (schemaName == null) {
+ public static String getServerVersion(final String databaseName) {
+ if (databaseName == null) {
return getDefaultServerVersion();
}
- return SERVER_VERSIONS.getOrDefault(schemaName, getDefaultServerVersion());
+ return SERVER_VERSIONS.getOrDefault(databaseName, getDefaultServerVersion());
}
/**
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java
index faf95c60329..b7d2265e264 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/spi/DatabaseDiscoveryType.java
@@ -32,30 +32,30 @@ public interface DatabaseDiscoveryType extends ShardingSphereAlgorithm {
/**
* Check database discovery configuration.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param dataSourceMap data source map
* @throws SQLException SQL exception
*/
- void checkDatabaseDiscoveryConfiguration(String schemaName, Map<String, DataSource> dataSourceMap) throws SQLException;
+ void checkDatabaseDiscoveryConfiguration(String databaseName, Map<String, DataSource> dataSourceMap) throws SQLException;
/**
* Update primary data source.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param dataSourceMap data source map
* @param disabledDataSourceNames disabled data source names
* @param groupName group name
*/
- void updatePrimaryDataSource(String schemaName, Map<String, DataSource> dataSourceMap, Collection<String> disabledDataSourceNames, String groupName);
+ void updatePrimaryDataSource(String databaseName, Map<String, DataSource> dataSourceMap, Collection<String> disabledDataSourceNames, String groupName);
/**
* Update member state.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param dataSourceMap data source map
* @param groupName group name
*/
- void updateMemberState(String schemaName, Map<String, DataSource> dataSourceMap, String groupName);
+ void updateMemberState(String databaseName, Map<String, DataSource> dataSourceMap, String groupName);
/**
* Get primary data source.
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index f905938caa9..2d28dcab89b 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -158,15 +158,15 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai
if (event instanceof DataSourceNameDisabledEvent) {
for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
if (((DataSourceNameDisabledEvent) event).isDisabled()) {
- entry.getValue().disableDataSource(((DataSourceNameDisabledEvent) event).getQualifiedSchema().getDataSourceName());
+ entry.getValue().disableDataSource(((DataSourceNameDisabledEvent) event).getQualifiedDatabase().getDataSourceName());
} else {
- entry.getValue().enableDataSource(((DataSourceNameDisabledEvent) event).getQualifiedSchema().getDataSourceName());
+ entry.getValue().enableDataSource(((DataSourceNameDisabledEvent) event).getQualifiedDatabase().getDataSourceName());
}
}
} else if (event instanceof PrimaryDataSourceChangedEvent) {
for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) {
- if (entry.getValue().getGroupName().equals(((PrimaryDataSourceChangedEvent) event).getQualifiedSchema().getGroupName())) {
- entry.getValue().updatePrimaryDataSourceName(((PrimaryDataSourceChangedEvent) event).getQualifiedSchema().getDataSourceName());
+ if (entry.getValue().getGroupName().equals(((PrimaryDataSourceChangedEvent) event).getQualifiedDatabase().getGroupName())) {
+ entry.getValue().updatePrimaryDataSourceName(((PrimaryDataSourceChangedEvent) event).getQualifiedDatabase().getDataSourceName());
}
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java
index 3ee0c007bc0..7e1a0be196e 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/fixture/TestDatabaseDiscoveryType.java
@@ -26,15 +26,15 @@ import java.util.Map;
public final class TestDatabaseDiscoveryType implements DatabaseDiscoveryType {
@Override
- public void checkDatabaseDiscoveryConfiguration(final String schemaName, final Map<String, DataSource> dataSourceMap) {
+ public void checkDatabaseDiscoveryConfiguration(final String databaseName, final Map<String, DataSource> dataSourceMap) {
}
@Override
- public void updatePrimaryDataSource(final String schemaName, final Map<String, DataSource> activeDataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
+ public void updatePrimaryDataSource(final String databaseName, final Map<String, DataSource> activeDataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
}
@Override
- public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String databaseName, final Map<String, DataSource> dataSourceMap, final String groupName) {
}
@Override
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/MGRDatabaseDiscoveryTypeFixture.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/MGRDatabaseDiscoveryTypeF [...]
index a54b068a2b7..280671e0acf 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/MGRDatabaseDiscoveryTypeFixture.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/fixture/MGRDatabaseDiscoveryTypeFixture.java
@@ -36,17 +36,17 @@ public final class MGRDatabaseDiscoveryTypeFixture implements DatabaseDiscoveryT
}
@Override
- public void checkDatabaseDiscoveryConfiguration(final String schemaName, final Map<String, DataSource> dataSourceMap) {
+ public void checkDatabaseDiscoveryConfiguration(final String databaseName, final Map<String, DataSource> dataSourceMap) {
}
@Override
- public void updatePrimaryDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
+ public void updatePrimaryDataSource(final String databaseName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
}
@Override
- public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String databaseName, final Map<String, DataSource> dataSourceMap, final String groupName) {
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java
index c3bf80bea91..51ca2431d95 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.dbdiscovery.mysql;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceChangedEvent;
import javax.sql.DataSource;
@@ -42,7 +42,7 @@ public abstract class AbstractDatabaseDiscoveryType implements DatabaseDiscovery
protected abstract String getPrimaryDataSourceURL(Statement statement) throws SQLException;
@Override
- public void updatePrimaryDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
+ public void updatePrimaryDataSource(final String databaseName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
Map<String, DataSource> activeDataSourceMap = new HashMap<>(dataSourceMap);
if (!disabledDataSourceNames.isEmpty()) {
activeDataSourceMap.entrySet().removeIf(each -> disabledDataSourceNames.contains(each.getKey()));
@@ -53,7 +53,7 @@ public abstract class AbstractDatabaseDiscoveryType implements DatabaseDiscovery
}
if (!newPrimaryDataSource.equals(oldPrimaryDataSource)) {
oldPrimaryDataSource = newPrimaryDataSource;
- ShardingSphereEventBus.getInstance().post(new PrimaryDataSourceChangedEvent(new QualifiedSchema(schemaName, groupName, newPrimaryDataSource)));
+ ShardingSphereEventBus.getInstance().post(new PrimaryDataSourceChangedEvent(new QualifiedDatabase(databaseName, groupName, newPrimaryDataSource)));
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java
index 82161f75868..7f800400035 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java
@@ -64,7 +64,7 @@ public final class MGRDatabaseDiscoveryType extends AbstractDatabaseDiscoveryTyp
private Properties props = new Properties();
@Override
- public void checkDatabaseDiscoveryConfiguration(final String schemaName, final Map<String, DataSource> dataSourceMap) throws SQLException {
+ public void checkDatabaseDiscoveryConfiguration(final String databaseName, final Map<String, DataSource> dataSourceMap) throws SQLException {
try (Connection connection = dataSourceMap.values().stream().findFirst().get().getConnection();
Statement statement = connection.createStatement()) {
checkPluginIsActive(statement);
@@ -153,12 +153,12 @@ public final class MGRDatabaseDiscoveryType extends AbstractDatabaseDiscoveryTyp
}
@Override
- public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String databaseName, final Map<String, DataSource> dataSourceMap, final String groupName) {
List<String> memberDataSourceURLs = findMemberDataSourceURLs(dataSourceMap);
if (memberDataSourceURLs.isEmpty()) {
return;
}
- determineDisabledDataSource(schemaName, dataSourceMap, memberDataSourceURLs, groupName);
+ determineDisabledDataSource(databaseName, dataSourceMap, memberDataSourceURLs, groupName);
}
private List<String> findMemberDataSourceURLs(final Map<String, DataSource> dataSourceMap) {
@@ -178,7 +178,7 @@ public final class MGRDatabaseDiscoveryType extends AbstractDatabaseDiscoveryTyp
return result;
}
- private void determineDisabledDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final List<String> memberDataSourceURLs, final String groupName) {
+ private void determineDisabledDataSource(final String databaseName, final Map<String, DataSource> dataSourceMap, final List<String> memberDataSourceURLs, final String groupName) {
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
if (entry.getKey().equals(getPrimaryDataSource())) {
continue;
@@ -196,7 +196,7 @@ public final class MGRDatabaseDiscoveryType extends AbstractDatabaseDiscoveryTyp
} catch (final SQLException ex) {
log.error("An exception occurred while find data source urls", ex);
}
- ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(schemaName, groupName, entry.getKey(),
+ ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(databaseName, groupName, entry.getKey(),
new StorageNodeDataSource(StorageNodeRole.MEMBER, disable ? StorageNodeStatus.DISABLED : StorageNodeStatus.ENABLED)));
}
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java
index b16c8882f97..ced3a18c81a 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java
@@ -52,10 +52,10 @@ public final class ShowSlaveStatusDatabaseDiscoveryType extends AbstractDatabase
private Properties props = new Properties();
@Override
- public void checkDatabaseDiscoveryConfiguration(final String schemaName, final Map<String, DataSource> dataSourceMap) throws SQLException {
+ public void checkDatabaseDiscoveryConfiguration(final String databaseName, final Map<String, DataSource> dataSourceMap) throws SQLException {
Collection<String> result = getPrimaryDataSourceURLS(dataSourceMap);
- Preconditions.checkState(!result.isEmpty(), "Not found primary data source for schemaName `%s`", schemaName);
- Preconditions.checkState(1 == result.size(), "More than one primary data source for schemaName `%s`", schemaName);
+ Preconditions.checkState(!result.isEmpty(), "Not found primary data source for databaseName `%s`", databaseName);
+ Preconditions.checkState(1 == result.size(), "More than one primary data source for databaseName `%s`", databaseName);
}
private Collection<String> getPrimaryDataSourceURLS(final Map<String, DataSource> dataSourceMap) throws SQLException {
@@ -87,24 +87,24 @@ public final class ShowSlaveStatusDatabaseDiscoveryType extends AbstractDatabase
}
@Override
- public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String databaseName, final Map<String, DataSource> dataSourceMap, final String groupName) {
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
if (entry.getKey().equals(getPrimaryDataSource())) {
continue;
}
- determineDatasourceState(schemaName, entry.getKey(), entry.getValue(), groupName);
+ determineDatasourceState(databaseName, entry.getKey(), entry.getValue(), groupName);
}
}
- private void determineDatasourceState(final String schemaName, final String datasourceName, final DataSource dataSource, final String groupName) {
+ private void determineDatasourceState(final String databaseName, final String datasourceName, final DataSource dataSource, final String groupName) {
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
long replicationDelayMilliseconds = getSecondsBehindMaster(statement) * 1000L;
if (replicationDelayMilliseconds < Long.parseLong(props.getProperty("delay-milliseconds-threshold"))) {
- ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(schemaName, groupName, datasourceName,
+ ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(databaseName, groupName, datasourceName,
new StorageNodeDataSource(StorageNodeRole.MEMBER, StorageNodeStatus.ENABLED, replicationDelayMilliseconds)));
} else {
- ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(schemaName, groupName, datasourceName,
+ ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(databaseName, groupName, datasourceName,
new StorageNodeDataSource(StorageNodeRole.MEMBER, StorageNodeStatus.DISABLED, replicationDelayMilliseconds)));
}
} catch (SQLException ex) {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java
index cd2dc0adf98..f6fab8db670 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java
@@ -22,7 +22,7 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceChangedEvent;
import org.apache.shardingsphere.infra.storage.StorageNodeDataSource;
@@ -54,12 +54,12 @@ public final class OpenGaussDatabaseDiscoveryType implements DatabaseDiscoveryTy
private Properties props = new Properties();
@Override
- public void checkDatabaseDiscoveryConfiguration(final String schemaName, final Map<String, DataSource> dataSourceMap) {
+ public void checkDatabaseDiscoveryConfiguration(final String databaseName, final Map<String, DataSource> dataSourceMap) {
// TODO Check openGauss configuration
}
@Override
- public void updatePrimaryDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
+ public void updatePrimaryDataSource(final String databaseName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
String newPrimaryDataSource = determinePrimaryDataSource(dataSourceMap);
if (newPrimaryDataSource.isEmpty()) {
oldPrimaryDataSource = "";
@@ -67,7 +67,7 @@ public final class OpenGaussDatabaseDiscoveryType implements DatabaseDiscoveryTy
}
if (!newPrimaryDataSource.equals(oldPrimaryDataSource)) {
oldPrimaryDataSource = newPrimaryDataSource;
- ShardingSphereEventBus.getInstance().post(new PrimaryDataSourceChangedEvent(new QualifiedSchema(schemaName, groupName, newPrimaryDataSource)));
+ ShardingSphereEventBus.getInstance().post(new PrimaryDataSourceChangedEvent(new QualifiedDatabase(databaseName, groupName, newPrimaryDataSource)));
}
}
@@ -90,7 +90,7 @@ public final class OpenGaussDatabaseDiscoveryType implements DatabaseDiscoveryTy
}
@Override
- public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String databaseName, final Map<String, DataSource> dataSourceMap, final String groupName) {
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
boolean disable = true;
try (Connection connection = entry.getValue().getConnection();
@@ -105,7 +105,7 @@ public final class OpenGaussDatabaseDiscoveryType implements DatabaseDiscoveryTy
} catch (final SQLException ex) {
log.error("An exception occurred while find data source urls", ex);
}
- ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(schemaName, groupName, entry.getKey(),
+ ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(databaseName, groupName, entry.getKey(),
new StorageNodeDataSource(StorageNodeRole.MEMBER, disable ? StorageNodeStatus.DISABLED : StorageNodeStatus.ENABLED)));
}
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
index 810149208eb..7edac443173 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
@@ -120,7 +120,7 @@ public final class ReadwriteSplittingRule implements SchemaRule, DataSourceConta
public void updateStatus(final DataSourceStatusChangedEvent event) {
if (event instanceof DataSourceNameDisabledEvent) {
for (Entry<String, ReadwriteSplittingDataSourceRule> entry : dataSourceRules.entrySet()) {
- entry.getValue().updateDisabledDataSourceNames(((DataSourceNameDisabledEvent) event).getQualifiedSchema().getDataSourceName(),
+ entry.getValue().updateDisabledDataSourceNames(((DataSourceNameDisabledEvent) event).getQualifiedDatabase().getDataSourceName(),
((DataSourceNameDisabledEvent) event).isDisabled());
}
}
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
index 070df59ef54..ddd687373b8 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.readwritesplitting.rule;
import com.google.common.collect.ImmutableMap;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -78,23 +78,23 @@ public final class ReadwriteSplittingRuleTest {
@Test
public void assertUpdateRuleStatusWithNotExistDataSource() {
ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule();
- readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedSchema("readwrite_splitting_db.readwrite.read_ds"), true));
+ readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds"), true));
assertThat(readwriteSplittingRule.getSingleDataSourceRule().getReadDataSourceNames(), is(Arrays.asList("read_ds_0", "read_ds_1")));
}
@Test
public void assertUpdateRuleStatus() {
ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule();
- readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedSchema("readwrite_splitting_db.readwrite.read_ds_0"), true));
+ readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), true));
assertThat(readwriteSplittingRule.getSingleDataSourceRule().getReadDataSourceNames(), is(Collections.singletonList("read_ds_1")));
}
@Test
public void assertUpdateRuleStatusWithEnable() {
ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule();
- readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedSchema("readwrite_splitting_db.readwrite.read_ds_0"), true));
+ readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), true));
assertThat(readwriteSplittingRule.getSingleDataSourceRule().getReadDataSourceNames(), is(Collections.singletonList("read_ds_1")));
- readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedSchema("readwrite_splitting_db.readwrite.read_ds_0"), false));
+ readwriteSplittingRule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), false));
assertThat(readwriteSplittingRule.getSingleDataSourceRule().getReadDataSourceNames(), is(Arrays.asList("read_ds_0", "read_ds_1")));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedSchema.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedDatabase.java
similarity index 83%
rename from shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedSchema.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedDatabase.java
index f12ff93e60f..29096f7d419 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedSchema.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedDatabase.java
@@ -24,29 +24,29 @@ import lombok.RequiredArgsConstructor;
import java.util.List;
/**
- * Qualified schema.
+ * Qualified database.
*/
@RequiredArgsConstructor
@Getter
-public final class QualifiedSchema {
+public final class QualifiedDatabase {
private static final String DELIMITER = ".";
- private final String schemaName;
+ private final String databaseName;
private final String groupName;
private final String dataSourceName;
- public QualifiedSchema(final String value) {
+ public QualifiedDatabase(final String value) {
List<String> values = Splitter.on(DELIMITER).splitToList(value);
- schemaName = values.get(0);
+ databaseName = values.get(0);
groupName = values.get(1);
dataSourceName = values.get(2);
}
@Override
public String toString() {
- return String.join(DELIMITER, schemaName, groupName, dataSourceName);
+ return String.join(DELIMITER, databaseName, groupName, dataSourceName);
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/event/SchemaAlteredEvent.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/event/SchemaAlteredEvent.java
index 4e3f3939005..352be1876b4 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/event/SchemaAlteredEvent.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/event/SchemaAlteredEvent.java
@@ -29,13 +29,16 @@ import java.util.Collection;
@Getter
public final class SchemaAlteredEvent {
+ private final String databaseName;
+
private final String schemaName;
private final Collection<TableMetaData> alteredTables = new ArrayList<>();
private final Collection<String> droppedTables = new ArrayList<>();
- public SchemaAlteredEvent(final String schemaName) {
+ public SchemaAlteredEvent(final String databaseName, final String schemaName) {
+ this.databaseName = databaseName;
this.schemaName = schemaName;
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/SystemSchemaUtil.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/SystemSchemaUtil.java
index 089da34e809..fb63a821cbb 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/SystemSchemaUtil.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/util/SystemSchemaUtil.java
@@ -34,16 +34,16 @@ public class SystemSchemaUtil {
*
* @param databaseType databaseType
* @param schemaNames schema names
- * @param sessionSchemaName session schema name
+ * @param sessionDatabaseName session database name
* @return whether sql statement contains system schema or not
*/
- public static boolean containsSystemSchema(final DatabaseType databaseType, final Collection<String> schemaNames, final String sessionSchemaName) {
+ public static boolean containsSystemSchema(final DatabaseType databaseType, final Collection<String> schemaNames, final String sessionDatabaseName) {
for (String each : schemaNames) {
if (!databaseType.getSystemSchemas().contains(each)) {
continue;
}
return true;
}
- return databaseType.getSystemSchemas().contains(sessionSchemaName);
+ return databaseType.getSystemSchemas().contains(sessionDatabaseName);
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceDisabledEvent.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceDisabledEvent.java
index bc2cae3717b..050e287b1ee 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceDisabledEvent.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceDisabledEvent.java
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.storage.StorageNodeDataSource;
@Getter
public final class DataSourceDisabledEvent implements DataSourceStatusChangedEvent {
- private final String schemaName;
+ private final String databaseName;
private final String groupName;
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceNameDisabledEvent.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceNameDisabledEvent.java
index 5193e0ea465..eadab629a51 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceNameDisabledEvent.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/DataSourceNameDisabledEvent.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.infra.rule.event.impl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
/**
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
@Getter
public final class DataSourceNameDisabledEvent implements DataSourceStatusChangedEvent {
- private final QualifiedSchema qualifiedSchema;
+ private final QualifiedDatabase qualifiedDatabase;
private final boolean isDisabled;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/PrimaryDataSourceChangedEvent.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/PrimaryDataSourceChangedEvent.java
index cffb80b7815..fd65d2f7617 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/PrimaryDataSourceChangedEvent.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/event/impl/PrimaryDataSourceChangedEvent.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.infra.rule.event.impl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
/**
@@ -29,5 +29,5 @@ import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
@Getter
public final class PrimaryDataSourceChangedEvent implements DataSourceStatusChangedEvent {
- private final QualifiedSchema qualifiedSchema;
+ private final QualifiedDatabase qualifiedDatabase;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedSchemaTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedDatabaseTest.java
similarity index 80%
rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedSchemaTest.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedDatabaseTest.java
index 020a13c1c96..d8eaa014708 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedSchemaTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/QualifiedDatabaseTest.java
@@ -22,12 +22,12 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-public final class QualifiedSchemaTest {
+public final class QualifiedDatabaseTest {
@Test
- public void assertNewQualifiedSchemaWithSchemaNameAndDataSourceName() {
- QualifiedSchema actual = new QualifiedSchema("test_schema.test_group_name.test_ds");
- assertThat(actual.getSchemaName(), is("test_schema"));
+ public void assertNewQualifiedDatabaseWithDatabaseNameAndDataSourceName() {
+ QualifiedDatabase actual = new QualifiedDatabase("test_db.test_group_name.test_ds");
+ assertThat(actual.getDatabaseName(), is("test_db"));
assertThat(actual.getGroupName(), is("test_group_name"));
assertThat(actual.getDataSourceName(), is("test_ds"));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java
index f5feea34fa5..0fbb74e5bde 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterIndexStatementSchemaRefresher.java
@@ -59,7 +59,8 @@ public final class AlterIndexStatementSchemaRefresher implements MetaDataRefresh
tableMetaData.getIndexes().remove(indexName);
String renameIndexName = renameIndex.get().getIdentifier().getValue();
tableMetaData.getIndexes().put(renameIndexName, new IndexMetaData(renameIndexName));
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
event.getAlteredTables().add(tableMetaData);
ShardingSphereEventBus.getInstance().post(event);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java
index 7962c244809..1556af4c175 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterTableStatementSchemaRefresher.java
@@ -49,7 +49,8 @@ public final class AlterTableStatementSchemaRefresher implements MetaDataRefresh
public void refresh(final ShardingSphereMetaData schemaMetaData, final FederationDatabaseMetaData database, final Map<String, OptimizerPlannerContext> optimizerPlanners,
final Collection<String> logicDataSourceNames, final AlterTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
String tableName = sqlStatement.getTable().getTableName().getIdentifier().getValue();
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
if (sqlStatement.getRenameTable().isPresent()) {
String renameTable = sqlStatement.getRenameTable().get().getTableName().getIdentifier().getValue();
putTableMetaData(schemaMetaData, database, optimizerPlanners, logicDataSourceNames, renameTable, props);
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java
index d4652ef3d33..89a413bff6d 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/AlterViewStatementSchemaRefresher.java
@@ -51,7 +51,8 @@ public final class AlterViewStatementSchemaRefresher implements MetaDataRefreshe
public void refresh(final ShardingSphereMetaData schemaMetaData, final FederationDatabaseMetaData database, final Map<String, OptimizerPlannerContext> optimizerPlanners,
final Collection<String> logicDataSourceNames, final AlterViewStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
String viewName = sqlStatement.getView().getTableName().getIdentifier().getValue();
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
Optional<SimpleTableSegment> renameView = AlterViewStatementHandler.getRenameView(sqlStatement);
if (renameView.isPresent()) {
String renameViewName = renameView.get().getTableName().getIdentifier().getValue();
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java
index 598f143ec7d..7f92a2509d0 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateIndexStatementSchemaRefresher.java
@@ -49,7 +49,8 @@ public final class CreateIndexStatementSchemaRefresher implements MetaDataRefres
}
String tableName = sqlStatement.getTable().getTableName().getIdentifier().getValue();
schemaMetaData.getDefaultSchema().get(tableName).getIndexes().put(indexName, new IndexMetaData(indexName));
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
event.getAlteredTables().add(schemaMetaData.getDefaultSchema().get(tableName));
ShardingSphereEventBus.getInstance().post(event);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java
index 2446667f952..db57a136b50 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateTableStatementSchemaRefresher.java
@@ -59,7 +59,8 @@ public final class CreateTableStatementSchemaRefresher implements MetaDataRefres
schemaMetaData.getDefaultSchema().put(tableName, tableMetaData);
database.put(tableMetaData);
optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database));
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
event.getAlteredTables().add(tableMetaData);
ShardingSphereEventBus.getInstance().post(event);
});
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java
index a483d761c6b..825cf6f90e3 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/CreateViewStatementSchemaRefresher.java
@@ -59,7 +59,8 @@ public final class CreateViewStatementSchemaRefresher implements MetaDataRefresh
schemaMetaData.getDefaultSchema().put(viewName, viewMetaData);
database.put(viewMetaData);
optimizerPlanners.put(database.getName(), OptimizerPlannerContextFactory.create(database));
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
event.getAlteredTables().add(viewMetaData);
ShardingSphereEventBus.getInstance().post(event);
});
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java
index 1fc3ef84968..e8a858ffb4a 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropIndexStatementSchemaRefresher.java
@@ -54,7 +54,8 @@ public final class DropIndexStatementSchemaRefresher implements MetaDataRefreshe
for (String each : getIndexNames(sqlStatement)) {
tableMetaData.getIndexes().remove(each);
}
- post(schemaMetaData.getName(), tableMetaData);
+ //TODO Get real schema name
+ post(schemaMetaData.getName(), schemaMetaData.getName(), tableMetaData);
}
}
@@ -70,8 +71,8 @@ public final class DropIndexStatementSchemaRefresher implements MetaDataRefreshe
return dropIndexStatement.getIndexes().stream().map(each -> each.getIdentifier().getValue()).collect(Collectors.toCollection(LinkedList::new));
}
- private void post(final String schemaName, final TableMetaData tableMetaData) {
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaName);
+ private void post(final String databaseName, final String schemaName, final TableMetaData tableMetaData) {
+ SchemaAlteredEvent event = new SchemaAlteredEvent(databaseName, schemaName);
event.getAlteredTables().add(tableMetaData);
ShardingSphereEventBus.getInstance().post(event);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java
index df6491ff349..cdc3796a2a0 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropTableStatementSchemaRefresher.java
@@ -43,7 +43,8 @@ public final class DropTableStatementSchemaRefresher implements MetaDataRefreshe
@Override
public void refresh(final ShardingSphereMetaData schemaMetaData, final FederationDatabaseMetaData database, final Map<String, OptimizerPlannerContext> optimizerPlanners,
final Collection<String> logicDataSourceNames, final DropTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
sqlStatement.getTables().forEach(each -> {
schemaMetaData.getDefaultSchema().remove(each.getTableName().getIdentifier().getValue());
database.remove(each.getTableName().getIdentifier().getValue());
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java
index c44a368b7a3..74e389f7be3 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/DropViewStatementSchemaRefresher.java
@@ -42,7 +42,8 @@ public final class DropViewStatementSchemaRefresher implements MetaDataRefresher
@Override
public void refresh(final ShardingSphereMetaData schemaMetaData, final FederationDatabaseMetaData database, final Map<String, OptimizerPlannerContext> optimizerPlanners,
final Collection<String> logicDataSourceNames, final DropViewStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
sqlStatement.getViews().forEach(each -> {
schemaMetaData.getDefaultSchema().remove(each.getTableName().getIdentifier().getValue());
event.getDroppedTables().add(each.getTableName().getIdentifier().getValue());
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java
index 0c3e0ee442c..7b00a9dc283 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresher.java
@@ -49,7 +49,8 @@ public final class RenameTableStatementSchemaRefresher implements MetaDataRefres
@Override
public void refresh(final ShardingSphereMetaData schemaMetaData, final FederationDatabaseMetaData database, final Map<String, OptimizerPlannerContext> optimizerPlanners,
final Collection<String> logicDataSourceNames, final RenameTableStatement sqlStatement, final ConfigurationProperties props) throws SQLException {
- SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName());
+ //TODO Get real schema name
+ SchemaAlteredEvent event = new SchemaAlteredEvent(schemaMetaData.getName(), schemaMetaData.getName());
for (RenameTableDefinitionSegment each : sqlStatement.getRenameTables()) {
String tableName = each.getTable().getTableName().getIdentifier().getValue();
String renameTable = each.getRenameTable().getTableName().getIdentifier().getValue();
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java
index 6db8622c3a5..0ae0dcc77a8 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLCheckEngine.java
@@ -43,17 +43,17 @@ public final class SQLCheckEngine {
}
/**
- * Check schema.
+ * Check database.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param rules rules
* @param grantee grantee
* @return check result
*/
@SuppressWarnings({"rawtypes", "unchecked"})
- public static boolean check(final String schemaName, final Collection<ShardingSphereRule> rules, final Grantee grantee) {
+ public static boolean check(final String databaseName, final Collection<ShardingSphereRule> rules, final Grantee grantee) {
for (Entry<ShardingSphereRule, SQLChecker> entry : OrderedSPIRegistry.getRegisteredServices(SQLChecker.class, rules).entrySet()) {
- boolean checkResult = entry.getValue().check(schemaName, grantee, entry.getKey());
+ boolean checkResult = entry.getValue().check(databaseName, grantee, entry.getKey());
if (!checkResult) {
return false;
}
@@ -67,15 +67,15 @@ public final class SQLCheckEngine {
* @param sqlStatement SQL statement
* @param parameters SQL parameters
* @param rules rules
- * @param currentSchema current schema
+ * @param currentDatabase current database
* @param metaDataMap meta data map
* @param grantee grantee
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static void check(final SQLStatement sqlStatement, final List<Object> parameters, final Collection<ShardingSphereRule> rules,
- final String currentSchema, final Map<String, ShardingSphereMetaData> metaDataMap, final Grantee grantee) {
+ final String currentDatabase, final Map<String, ShardingSphereMetaData> metaDataMap, final Grantee grantee) {
for (Entry<ShardingSphereRule, SQLChecker> entry : OrderedSPIRegistry.getRegisteredServices(SQLChecker.class, rules).entrySet()) {
- SQLCheckResult checkResult = entry.getValue().check(sqlStatement, parameters, grantee, currentSchema, metaDataMap, entry.getKey());
+ SQLCheckResult checkResult = entry.getValue().check(sqlStatement, parameters, grantee, currentDatabase, metaDataMap, entry.getKey());
if (!checkResult.isPassed()) {
throw new SQLCheckException(checkResult.getErrorMessage());
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java
index 9359227c126..e551b11e348 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/check/SQLChecker.java
@@ -33,14 +33,14 @@ import java.util.function.BiPredicate;
public interface SQLChecker<T extends ShardingSphereRule> extends OrderedSPI<T> {
/**
- * Check schema.
+ * Check database.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param grantee grantee
* @param rule rule
* @return check result
*/
- boolean check(String schemaName, Grantee grantee, T rule);
+ boolean check(String databaseName, Grantee grantee, T rule);
/**
* Check SQL.
@@ -48,12 +48,12 @@ public interface SQLChecker<T extends ShardingSphereRule> extends OrderedSPI<T>
* @param sqlStatement SQL statement
* @param parameters SQL parameters
* @param grantee grantee
- * @param currentSchema current schema
+ * @param currentDatabase current database
* @param metaDataMap meta data map
* @param rule rule
* @return SQL check result
*/
- SQLCheckResult check(SQLStatement sqlStatement, List<Object> parameters, Grantee grantee, String currentSchema, Map<String, ShardingSphereMetaData> metaDataMap, T rule);
+ SQLCheckResult check(SQLStatement sqlStatement, List<Object> parameters, Grantee grantee, String currentDatabase, Map<String, ShardingSphereMetaData> metaDataMap, T rule);
/**
* Check User.
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
index e1ef4ceecd3..b8b2219df14 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/main/java/org/apache/shardingsphere/authority/checker/AuthorityChecker.java
@@ -56,16 +56,16 @@ import java.util.function.BiPredicate;
public final class AuthorityChecker implements SQLChecker<AuthorityRule> {
@Override
- public boolean check(final String schemaName, final Grantee grantee, final AuthorityRule authorityRule) {
+ public boolean check(final String databaseName, final Grantee grantee, final AuthorityRule authorityRule) {
if (null == grantee) {
return true;
}
- return authorityRule.findPrivileges(grantee).map(optional -> optional.hasPrivileges(schemaName)).orElse(false);
+ return authorityRule.findPrivileges(grantee).map(optional -> optional.hasPrivileges(databaseName)).orElse(false);
}
@Override
public SQLCheckResult check(final SQLStatement sqlStatement, final List<Object> parameters, final Grantee grantee,
- final String currentSchema, final Map<String, ShardingSphereMetaData> metaDataMap, final AuthorityRule authorityRule) {
+ final String currentDatabase, final Map<String, ShardingSphereMetaData> metaDataMap, final AuthorityRule authorityRule) {
if (null == grantee) {
return new SQLCheckResult(true, "");
}
@@ -73,8 +73,8 @@ public final class AuthorityChecker implements SQLChecker<AuthorityRule> {
if (!privileges.isPresent()) {
return new SQLCheckResult(false, String.format("Access denied for user '%s'@'%s'", grantee.getUsername(), grantee.getHostname()));
}
- if (null != currentSchema && !privileges.filter(optional -> optional.hasPrivileges(currentSchema)).isPresent()) {
- return new SQLCheckResult(false, String.format("Unknown database '%s'", currentSchema));
+ if (null != currentDatabase && !privileges.filter(optional -> optional.hasPrivileges(currentDatabase)).isPresent()) {
+ return new SQLCheckResult(false, String.format("Unknown database '%s'", currentDatabase));
}
PrivilegeType privilegeType = getPrivilege(sqlStatement);
String errorMessage = Objects.isNull(privilegeType) ? "" : String.format("Access denied for operation %s", privilegeType.name());
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
index 6fa5cf46bca..8be9d0cd8b5 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
@@ -97,11 +97,11 @@ public final class ContextManager implements AutoCloseable {
/**
* Get data source map.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @return data source map
*/
- public Map<String, DataSource> getDataSourceMap(final String schemaName) {
- return metaDataContexts.getMetaData(schemaName).getResource().getDataSources();
+ public Map<String, DataSource> getDataSourceMap(final String databaseName) {
+ return metaDataContexts.getMetaData(databaseName).getResource().getDataSources();
}
/**
@@ -125,79 +125,79 @@ public final class ContextManager implements AutoCloseable {
/**
* Add schema.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @throws SQLException SQL exception
*/
- public void addSchema(final String schemaName) throws SQLException {
- if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
+ public void addDatabase(final String databaseName) throws SQLException {
+ if (metaDataContexts.getMetaDataMap().containsKey(databaseName)) {
return;
}
- MetaDataContexts newMetaDataContexts = buildNewMetaDataContext(schemaName);
- FederationDatabaseMetaData databaseMetaData = newMetaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(schemaName);
- metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().put(schemaName, databaseMetaData);
- metaDataContexts.getOptimizerContext().getPlannerContexts().put(schemaName, OptimizerPlannerContextFactory.create(databaseMetaData));
- metaDataContexts.getMetaDataMap().put(schemaName, newMetaDataContexts.getMetaData(schemaName));
- metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persist(schemaName));
+ MetaDataContexts newMetaDataContexts = buildNewMetaDataContext(databaseName);
+ FederationDatabaseMetaData databaseMetaData = newMetaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName);
+ metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().put(databaseName, databaseMetaData);
+ metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(databaseMetaData));
+ metaDataContexts.getMetaDataMap().put(databaseName, newMetaDataContexts.getMetaData(databaseName));
+ metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persist(databaseName));
renewAllTransactionContext();
}
/**
- * Alter schema.
+ * Alter database.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param schemas schemas
*/
- public void alterSchema(final String schemaName, final Map<String, ShardingSphereSchema> schemas) {
+ public void alterDatabase(final String databaseName, final Map<String, ShardingSphereSchema> schemas) {
ShardingSphereMetaData alteredMetaData = new ShardingSphereMetaData(
- schemaName, metaDataContexts.getMetaData(schemaName).getResource(), metaDataContexts.getMetaData(schemaName).getRuleMetaData(), schemas);
+ databaseName, metaDataContexts.getMetaData(databaseName).getResource(), metaDataContexts.getMetaData(databaseName).getRuleMetaData(), schemas);
Map<String, ShardingSphereMetaData> alteredMetaDataMap = new HashMap<>(metaDataContexts.getMetaDataMap());
- alteredMetaDataMap.put(schemaName, alteredMetaData);
- FederationDatabaseMetaData alteredDatabaseMetaData = new FederationDatabaseMetaData(schemaName, schemas);
- metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().put(schemaName, alteredDatabaseMetaData);
- metaDataContexts.getOptimizerContext().getPlannerContexts().put(schemaName, OptimizerPlannerContextFactory.create(alteredDatabaseMetaData));
+ alteredMetaDataMap.put(databaseName, alteredMetaData);
+ FederationDatabaseMetaData alteredDatabaseMetaData = new FederationDatabaseMetaData(databaseName, schemas);
+ metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().put(databaseName, alteredDatabaseMetaData);
+ metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(alteredDatabaseMetaData));
renewMetaDataContexts(rebuildMetaDataContexts(alteredMetaDataMap));
}
/**
- * Alter schema.
+ * Alter database.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param changedTableMetaData changed table meta data
* @param deletedTable deleted table
*/
- public void alterSchema(final String schemaName, final TableMetaData changedTableMetaData, final String deletedTable) {
- Optional.ofNullable(changedTableMetaData).ifPresent(optional -> alterTableSchema(schemaName, optional));
- Optional.ofNullable(deletedTable).ifPresent(optional -> deleteTableSchema(schemaName, optional));
+ public void alterDatabase(final String databaseName, final TableMetaData changedTableMetaData, final String deletedTable) {
+ Optional.ofNullable(changedTableMetaData).ifPresent(optional -> alterTableSchema(databaseName, optional));
+ Optional.ofNullable(deletedTable).ifPresent(optional -> deleteTableSchema(databaseName, optional));
}
- private void alterTableSchema(final String schemaName, final TableMetaData changedTableMetaData) {
- ShardingSphereMetaData metaData = metaDataContexts.getMetaData(schemaName);
- alterSingleTableDataNodes(schemaName, metaData, changedTableMetaData);
- FederationDatabaseMetaData databaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(schemaName);
+ private void alterTableSchema(final String databaseName, final TableMetaData changedTableMetaData) {
+ ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName);
+ alterSingleTableDataNodes(databaseName, metaData, changedTableMetaData);
+ FederationDatabaseMetaData databaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName);
metaData.getDefaultSchema().put(changedTableMetaData.getName(), changedTableMetaData);
databaseMetaData.put(changedTableMetaData);
- metaDataContexts.getOptimizerContext().getPlannerContexts().put(schemaName, OptimizerPlannerContextFactory.create(databaseMetaData));
+ metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(databaseMetaData));
}
- private void alterSingleTableDataNodes(final String schemaName, final ShardingSphereMetaData metaData, final TableMetaData changedTableMetaData) {
+ private void alterSingleTableDataNodes(final String databaseName, final ShardingSphereMetaData metaData, final TableMetaData changedTableMetaData) {
if (!containsInDataNodeContainedRule(changedTableMetaData.getName(), metaData)) {
- refreshRules(schemaName, metaData);
+ refreshRules(databaseName, metaData);
}
}
- private void refreshRules(final String schemaName, final ShardingSphereMetaData metaData) {
- Collection<ShardingSphereRule> rules = SchemaRulesBuilder.buildRules(schemaName, new DataSourceProvidedDatabaseConfiguration(metaData.getResource().getDataSources(),
+ private void refreshRules(final String databaseName, final ShardingSphereMetaData metaData) {
+ Collection<ShardingSphereRule> rules = SchemaRulesBuilder.buildRules(databaseName, new DataSourceProvidedDatabaseConfiguration(metaData.getResource().getDataSources(),
metaData.getRuleMetaData().getConfigurations()), new ConfigurationProperties(metaDataContexts.getProps().getProps()));
metaData.getRuleMetaData().getRules().clear();
metaData.getRuleMetaData().getRules().addAll(rules);
}
- private void deleteTableSchema(final String schemaName, final String deletedTable) {
- ShardingSphereMetaData metaData = metaDataContexts.getMetaData(schemaName);
- FederationDatabaseMetaData databaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(schemaName);
+ private void deleteTableSchema(final String databaseName, final String deletedTable) {
+ ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName);
+ FederationDatabaseMetaData databaseMetaData = metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName);
metaData.getDefaultSchema().remove(deletedTable);
databaseMetaData.remove(deletedTable);
- metaDataContexts.getOptimizerContext().getPlannerContexts().put(schemaName, OptimizerPlannerContextFactory.create(databaseMetaData));
+ metaDataContexts.getOptimizerContext().getPlannerContexts().put(databaseName, OptimizerPlannerContextFactory.create(databaseMetaData));
}
private boolean containsInDataNodeContainedRule(final String tableName, final ShardingSphereMetaData schemaMetaData) {
@@ -205,103 +205,103 @@ public final class ContextManager implements AutoCloseable {
}
/**
- * Delete schema.
+ * Delete data base.
*
- * @param schemaName schema name
+ * @param databaseName database name
*/
- public void deleteSchema(final String schemaName) {
- if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
- metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().remove(schemaName);
- metaDataContexts.getOptimizerContext().getParserContexts().remove(schemaName);
- metaDataContexts.getOptimizerContext().getPlannerContexts().remove(schemaName);
- ShardingSphereMetaData removeMetaData = metaDataContexts.getMetaDataMap().remove(schemaName);
+ public void deleteDatabase(final String databaseName) {
+ if (metaDataContexts.getMetaDataMap().containsKey(databaseName)) {
+ metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().remove(databaseName);
+ metaDataContexts.getOptimizerContext().getParserContexts().remove(databaseName);
+ metaDataContexts.getOptimizerContext().getPlannerContexts().remove(databaseName);
+ ShardingSphereMetaData removeMetaData = metaDataContexts.getMetaDataMap().remove(databaseName);
closeDataSources(removeMetaData);
- removeAndCloseTransactionEngine(schemaName);
- metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().delete(schemaName));
+ removeAndCloseTransactionEngine(databaseName);
+ metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().delete(databaseName));
}
}
/**
* Add resource.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param dataSourcePropsMap data source properties map
* @throws SQLException SQL exception
*/
- public void addResource(final String schemaName, final Map<String, DataSourceProperties> dataSourcePropsMap) throws SQLException {
- refreshMetaDataContext(schemaName, dataSourcePropsMap);
- metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().append(schemaName, dataSourcePropsMap));
+ public void addResource(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap) throws SQLException {
+ refreshMetaDataContext(databaseName, dataSourcePropsMap);
+ metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, dataSourcePropsMap));
}
/**
* Alter resource.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param dataSourcePropsMap data source properties map
* @throws SQLException SQL exception
*/
- public void alterResource(final String schemaName, final Map<String, DataSourceProperties> dataSourcePropsMap) throws SQLException {
- refreshMetaDataContext(schemaName, dataSourcePropsMap);
- metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().append(schemaName, dataSourcePropsMap));
+ public void alterResource(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap) throws SQLException {
+ refreshMetaDataContext(databaseName, dataSourcePropsMap);
+ metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().append(databaseName, dataSourcePropsMap));
}
/**
* Drop resource.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param toBeDroppedResourceNames to be dropped resource names
*/
- public void dropResource(final String schemaName, final Collection<String> toBeDroppedResourceNames) {
- toBeDroppedResourceNames.forEach(metaDataContexts.getMetaData(schemaName).getResource().getDataSources()::remove);
- metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().drop(schemaName, toBeDroppedResourceNames));
+ public void dropResource(final String databaseName, final Collection<String> toBeDroppedResourceNames) {
+ toBeDroppedResourceNames.forEach(metaDataContexts.getMetaData(databaseName).getResource().getDataSources()::remove);
+ metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().drop(databaseName, toBeDroppedResourceNames));
}
/**
* Alter rule configuration.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param ruleConfigs collection of rule configurations
*/
- public void alterRuleConfiguration(final String schemaName, final Collection<RuleConfiguration> ruleConfigs) {
+ public void alterRuleConfiguration(final String databaseName, final Collection<RuleConfiguration> ruleConfigs) {
try {
- MetaDataContexts changedMetaDataContexts = buildChangedMetaDataContext(metaDataContexts.getMetaDataMap().get(schemaName), ruleConfigs);
+ MetaDataContexts changedMetaDataContexts = buildChangedMetaDataContext(metaDataContexts.getMetaDataMap().get(databaseName), ruleConfigs);
metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().putAll(changedMetaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases());
Map<String, ShardingSphereMetaData> metaDataMap = new HashMap<>(metaDataContexts.getMetaDataMap());
metaDataMap.putAll(changedMetaDataContexts.getMetaDataMap());
renewMetaDataContexts(rebuildMetaDataContexts(metaDataMap));
} catch (final SQLException ex) {
- log.error("Alter schema:{} rule configuration failed", schemaName, ex);
+ log.error("Alter database:{} rule configuration failed", databaseName, ex);
}
}
/**
* Alter data source configuration.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param dataSourcePropsMap altered data source properties map
*/
- public void alterDataSourceConfiguration(final String schemaName, final Map<String, DataSourceProperties> dataSourcePropsMap) {
+ public void alterDataSourceConfiguration(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap) {
try {
- MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSource(metaDataContexts.getMetaDataMap().get(schemaName), dataSourcePropsMap);
- refreshMetaDataContext(schemaName, changedMetaDataContext, dataSourcePropsMap);
+ MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSource(metaDataContexts.getMetaDataMap().get(databaseName), dataSourcePropsMap);
+ refreshMetaDataContext(databaseName, changedMetaDataContext, dataSourcePropsMap);
} catch (final SQLException ex) {
- log.error("Alter schema:{} data source configuration failed", schemaName, ex);
+ log.error("Alter database:{} data source configuration failed", databaseName, ex);
}
}
/**
* Alter data source and rule configuration.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param dataSourcePropsMap data source props map
* @param ruleConfigs rule configurations
*/
- public void alterDataSourceAndRuleConfiguration(final String schemaName, final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<RuleConfiguration> ruleConfigs) {
+ public void alterDataSourceAndRuleConfiguration(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap, final Collection<RuleConfiguration> ruleConfigs) {
try {
- MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSourceAndRule(metaDataContexts.getMetaDataMap().get(schemaName), dataSourcePropsMap, ruleConfigs);
- refreshMetaDataContext(schemaName, changedMetaDataContext, dataSourcePropsMap);
+ MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithChangedDataSourceAndRule(metaDataContexts.getMetaDataMap().get(databaseName), dataSourcePropsMap, ruleConfigs);
+ refreshMetaDataContext(databaseName, changedMetaDataContext, dataSourcePropsMap);
} catch (SQLException ex) {
- log.error("Alter schema:{} data source and rule configuration failed", schemaName, ex);
+ log.error("Alter database:{} data source and rule configuration failed", databaseName, ex);
}
}
@@ -339,73 +339,73 @@ public final class ContextManager implements AutoCloseable {
/**
* Reload meta data.
*
- * @param schemaName schema name to be reload
+ * @param databaseName database name to be reload
*/
- public void reloadMetaData(final String schemaName) {
+ public void reloadMetaData(final String databaseName) {
try {
- ShardingSphereSchema schema = loadActualSchema(schemaName);
- alterSchema(schemaName, Collections.singletonMap(schemaName, schema));
- metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persist(schemaName, schemaName, schema));
+ ShardingSphereSchema schema = loadActualSchema(databaseName);
+ alterDatabase(databaseName, Collections.singletonMap(databaseName, schema));
+ metaDataContexts.getMetaDataPersistService().ifPresent(optional -> optional.getSchemaMetaDataService().persist(databaseName, databaseName, schema));
} catch (final SQLException ex) {
- log.error("Reload schema:{} meta data failed", schemaName, ex);
+ log.error("Reload database:{} meta data failed", databaseName, ex);
}
}
/**
* Reload table meta data.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param tableName logic table name
*/
- public void reloadMetaData(final String schemaName, final String tableName) {
+ public void reloadMetaData(final String databaseName, final String tableName) {
try {
SchemaBuilderMaterials materials = new SchemaBuilderMaterials(
- metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType(), metaDataContexts.getMetaData(schemaName).getResource().getDataSources(),
- metaDataContexts.getMetaData(schemaName).getRuleMetaData().getRules(), metaDataContexts.getProps());
- loadTableMetaData(schemaName, tableName, materials);
+ metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType(), metaDataContexts.getMetaData(databaseName).getResource().getDataSources(),
+ metaDataContexts.getMetaData(databaseName).getRuleMetaData().getRules(), metaDataContexts.getProps());
+ loadTableMetaData(databaseName, tableName, materials);
} catch (final SQLException ex) {
- log.error("Reload table:{} meta data of schema:{} failed", tableName, schemaName, ex);
+ log.error("Reload table:{} meta data of database:{} failed", tableName, databaseName, ex);
}
}
/**
* Reload single data source table meta data.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param tableName logic table name
* @param dataSourceName data source name
*/
- public void reloadMetaData(final String schemaName, final String tableName, final String dataSourceName) {
+ public void reloadMetaData(final String databaseName, final String tableName, final String dataSourceName) {
try {
SchemaBuilderMaterials materials = new SchemaBuilderMaterials(
- metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType(), Collections.singletonMap(dataSourceName,
- metaDataContexts.getMetaData(schemaName).getResource().getDataSources().get(dataSourceName)),
- metaDataContexts.getMetaData(schemaName).getRuleMetaData().getRules(), metaDataContexts.getProps());
- loadTableMetaData(schemaName, tableName, materials);
+ metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType(), Collections.singletonMap(dataSourceName,
+ metaDataContexts.getMetaData(databaseName).getResource().getDataSources().get(dataSourceName)),
+ metaDataContexts.getMetaData(databaseName).getRuleMetaData().getRules(), metaDataContexts.getProps());
+ loadTableMetaData(databaseName, tableName, materials);
} catch (final SQLException ex) {
- log.error("Reload table:{} meta data of schema:{} with data source:{} failed", tableName, schemaName, dataSourceName, ex);
+ log.error("Reload table:{} meta data of database:{} with data source:{} failed", tableName, databaseName, dataSourceName, ex);
}
}
- private void loadTableMetaData(final String schemaName, final String tableName, final SchemaBuilderMaterials materials) throws SQLException {
+ private void loadTableMetaData(final String databaseName, final String tableName, final SchemaBuilderMaterials materials) throws SQLException {
TableMetaData tableMetaData = TableMetaDataBuilder.load(Collections.singletonList(tableName), materials).getOrDefault(tableName, new TableMetaData());
if (!tableMetaData.getColumns().isEmpty()) {
- metaDataContexts.getMetaData(schemaName).getDefaultSchema().put(tableName, tableMetaData);
+ metaDataContexts.getMetaData(databaseName).getDefaultSchema().put(tableName, tableMetaData);
metaDataContexts.getMetaDataPersistService().ifPresent(optional ->
- optional.getSchemaMetaDataService().persist(schemaName, schemaName, metaDataContexts.getMetaData(schemaName).getDefaultSchema()));
+ optional.getSchemaMetaDataService().persist(databaseName, databaseName, metaDataContexts.getMetaData(databaseName).getDefaultSchema()));
}
}
- private ShardingSphereSchema loadActualSchema(final String schemaName) throws SQLException {
- Map<String, DataSource> dataSourceMap = metaDataContexts.getMetaData(schemaName).getResource().getDataSources();
- Collection<ShardingSphereRule> rules = metaDataContexts.getMetaDataMap().get(schemaName).getRuleMetaData().getRules();
+ private ShardingSphereSchema loadActualSchema(final String databaseName) throws SQLException {
+ Map<String, DataSource> dataSourceMap = metaDataContexts.getMetaData(databaseName).getResource().getDataSources();
+ Collection<ShardingSphereRule> rules = metaDataContexts.getMetaDataMap().get(databaseName).getRuleMetaData().getRules();
return SchemaLoader.load(dataSourceMap, rules, metaDataContexts.getProps().getProps());
}
- private Collection<DataSource> getPendingClosedDataSources(final String schemaName, final Map<String, DataSourceProperties> dataSourcePropsMap) {
+ private Collection<DataSource> getPendingClosedDataSources(final String databaseName, final Map<String, DataSourceProperties> dataSourcePropsMap) {
Collection<DataSource> result = new LinkedList<>();
- result.addAll(getDeletedDataSources(metaDataContexts.getMetaData(schemaName), dataSourcePropsMap).values());
- result.addAll(getChangedDataSources(metaDataContexts.getMetaData(schemaName), dataSourcePropsMap).values());
+ result.addAll(getDeletedDataSources(metaDataContexts.getMetaData(databaseName), dataSourcePropsMap).values());
+ result.addAll(getChangedDataSources(metaDataContexts.getMetaData(databaseName), dataSourcePropsMap).values());
return result;
}
@@ -447,23 +447,23 @@ public final class ContextManager implements AutoCloseable {
metaDataContexts.getMetaDataMap(), metaDataContexts.getGlobalRuleMetaData(), metaDataContexts.getExecutorEngine(), metaDataContexts.getOptimizerContext(), props);
}
- private void refreshMetaDataContext(final String schemaName, final Map<String, DataSourceProperties> dataSourceProps) throws SQLException {
- MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithAddedDataSource(metaDataContexts.getMetaDataMap().get(schemaName), dataSourceProps);
+ private void refreshMetaDataContext(final String databaseName, final Map<String, DataSourceProperties> dataSourceProps) throws SQLException {
+ MetaDataContexts changedMetaDataContext = buildChangedMetaDataContextWithAddedDataSource(metaDataContexts.getMetaDataMap().get(databaseName), dataSourceProps);
metaDataContexts.getMetaDataMap().putAll(changedMetaDataContext.getMetaDataMap());
metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().putAll(changedMetaDataContext.getOptimizerContext().getFederationMetaData().getDatabases());
metaDataContexts.getOptimizerContext().getParserContexts().putAll(changedMetaDataContext.getOptimizerContext().getParserContexts());
metaDataContexts.getOptimizerContext().getPlannerContexts().putAll(changedMetaDataContext.getOptimizerContext().getPlannerContexts());
- renewTransactionContext(schemaName, metaDataContexts.getMetaData(schemaName).getResource());
+ renewTransactionContext(databaseName, metaDataContexts.getMetaData(databaseName).getResource());
}
- private void refreshMetaDataContext(final String schemaName, final MetaDataContexts changedMetaDataContext, final Map<String, DataSourceProperties> dataSourcePropsMap) {
+ private void refreshMetaDataContext(final String databaseName, final MetaDataContexts changedMetaDataContext, final Map<String, DataSourceProperties> dataSourcePropsMap) {
metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases().putAll(changedMetaDataContext.getOptimizerContext().getFederationMetaData().getDatabases());
Map<String, ShardingSphereMetaData> metaDataMap = new HashMap<>(metaDataContexts.getMetaDataMap());
metaDataMap.putAll(changedMetaDataContext.getMetaDataMap());
- Collection<DataSource> pendingClosedDataSources = getPendingClosedDataSources(schemaName, dataSourcePropsMap);
+ Collection<DataSource> pendingClosedDataSources = getPendingClosedDataSources(databaseName, dataSourcePropsMap);
renewMetaDataContexts(rebuildMetaDataContexts(metaDataMap));
- renewTransactionContext(schemaName, metaDataContexts.getMetaData(schemaName).getResource());
- closeDataSources(schemaName, pendingClosedDataSources);
+ renewTransactionContext(databaseName, metaDataContexts.getMetaData(databaseName).getResource());
+ closeDataSources(databaseName, pendingClosedDataSources);
}
private MetaDataContexts buildChangedMetaDataContextWithAddedDataSource(final ShardingSphereMetaData originalMetaData,
@@ -553,12 +553,12 @@ public final class ContextManager implements AutoCloseable {
}
}
- private void renewTransactionContext(final String schemaName, final ShardingSphereResource resource) {
- ShardingSphereTransactionManagerEngine changedStaleEngine = transactionContexts.getEngines().get(schemaName);
+ private void renewTransactionContext(final String databaseName, final ShardingSphereResource resource) {
+ ShardingSphereTransactionManagerEngine changedStaleEngine = transactionContexts.getEngines().get(databaseName);
if (null != changedStaleEngine) {
closeTransactionEngine(changedStaleEngine);
}
- transactionContexts.getEngines().put(schemaName, createNewEngine(resource.getDatabaseType(), resource.getDataSources()));
+ transactionContexts.getEngines().put(databaseName, createNewEngine(resource.getDatabaseType(), resource.getDataSources()));
}
private ShardingSphereTransactionManagerEngine createNewEngine(final DatabaseType databaseType, final Map<String, DataSource> dataSources) {
@@ -575,10 +575,10 @@ public final class ContextManager implements AutoCloseable {
return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
}
- private MetaDataContexts buildNewMetaDataContext(final String schemaName) throws SQLException {
+ private MetaDataContexts buildNewMetaDataContext(final String databaseName) throws SQLException {
Properties props = metaDataContexts.getProps().getProps();
MetaDataContextsBuilder metaDataContextsBuilder = new MetaDataContextsBuilder(metaDataContexts.getGlobalRuleMetaData().getConfigurations(), props);
- metaDataContextsBuilder.addDatabase(schemaName, DatabaseTypeRegistry.getDefaultDatabaseType(), new DataSourceProvidedDatabaseConfiguration(new HashMap<>(), new LinkedList<>()), props);
+ metaDataContextsBuilder.addDatabase(databaseName, DatabaseTypeRegistry.getDefaultDatabaseType(), new DataSourceProvidedDatabaseConfiguration(new HashMap<>(), new LinkedList<>()), props);
return metaDataContextsBuilder.build(metaDataContexts.getMetaDataPersistService().orElse(null));
}
@@ -588,13 +588,13 @@ public final class ContextManager implements AutoCloseable {
}
}
- private void closeDataSources(final String schemaName, final Collection<DataSource> dataSources) {
- ShardingSphereResource resource = metaDataContexts.getMetaData(schemaName).getResource();
+ private void closeDataSources(final String databaseName, final Collection<DataSource> dataSources) {
+ ShardingSphereResource resource = metaDataContexts.getMetaData(databaseName).getResource();
dataSources.forEach(resource::close);
}
- private void removeAndCloseTransactionEngine(final String schemaName) {
- ShardingSphereTransactionManagerEngine staleEngine = transactionContexts.getEngines().remove(schemaName);
+ private void removeAndCloseTransactionEngine(final String databaseName) {
+ ShardingSphereTransactionManagerEngine staleEngine = transactionContexts.getEngines().remove(databaseName);
closeTransactionEngine(staleEngine);
}
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
index 579b626d1f3..d9af36a1a43 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java
@@ -69,22 +69,22 @@ public final class MetaDataContexts implements AutoCloseable {
}
/**
- * Get all schema names.
+ * Get all database names.
*
- * @return all schema names
+ * @return all database names
*/
- public Collection<String> getAllSchemaNames() {
+ public Collection<String> getAllDatabaseNames() {
return metaDataMap.keySet();
}
/**
* Get meta data.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @return meta data
*/
- public ShardingSphereMetaData getMetaData(final String schemaName) {
- return metaDataMap.get(schemaName);
+ public ShardingSphereMetaData getMetaData(final String databaseName) {
+ return metaDataMap.get(databaseName);
}
@Override
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
index 53de4c20e66..7e5c9562cda 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java
@@ -63,7 +63,7 @@ public final class MetaDataPersistService {
private final ComputeNodePersistService computeNodePersistService;
- private final DatabaseVersionPersistService schemaVersionPersistService;
+ private final DatabaseVersionPersistService databaseVersionPersistService;
public MetaDataPersistService(final PersistRepository repository) {
this.repository = repository;
@@ -73,7 +73,7 @@ public final class MetaDataPersistService {
globalRuleService = new GlobalRulePersistService(repository);
propsService = new PropertiesPersistService(repository);
computeNodePersistService = new ComputeNodePersistService(repository);
- schemaVersionPersistService = new DatabaseVersionPersistService(repository);
+ databaseVersionPersistService = new DatabaseVersionPersistService(repository);
}
/**
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java
index 4f34c73d0a5..1cad008a270 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java
@@ -78,12 +78,12 @@ public final class DatabaseMetaDataNode {
/**
* Get rule path.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param version rule version
* @return rule path
*/
- public static String getRulePath(final String schemaName, final String version) {
- return Joiner.on("/").join(getFullMetaDataPath(schemaName, VERSIONS), version, RULE_NODE);
+ public static String getRulePath(final String databaseName, final String version) {
+ return Joiner.on("/").join(getFullMetaDataPath(databaseName, VERSIONS), version, RULE_NODE);
}
/**
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java
index e583ab737a5..d2a373fc123 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistService.java
@@ -58,17 +58,6 @@ public final class SchemaMetaDataPersistService {
persistTables(databaseName, schemaName, schema.getTables());
}
- /**
- * Persist table meta data.
- *
- * @param schemaName schema name
- * @param tableMetaData table meta data
- */
- public void persist(final String schemaName, final TableMetaData tableMetaData) {
- repository.persist(DatabaseMetaDataNode.getTableMetaDataPath(schemaName, schemaName, tableMetaData.getName().toLowerCase()),
- YamlEngine.marshal(new TableMetaDataYamlSwapper().swapToYamlConfiguration(tableMetaData)));
- }
-
/**
* Persist table meta data.
*
@@ -84,10 +73,10 @@ public final class SchemaMetaDataPersistService {
/**
* Persist schema tables.
*
- * @param schemaName schema name
+ * @param databaseName database name
*/
- public void persist(final String schemaName) {
- repository.persist(DatabaseMetaDataNode.getMetaDataTablesPath(schemaName, schemaName), "");
+ public void persist(final String databaseName) {
+ repository.persist(DatabaseMetaDataNode.getMetaDataTablesPath(databaseName, databaseName), "");
}
private void compareAndPersist(final String databaseName, final String schemaName, final ShardingSphereSchema schema, final ShardingSphereSchema originalSchema) {
@@ -122,16 +111,6 @@ public final class SchemaMetaDataPersistService {
repository.delete(DatabaseMetaDataNode.getDatabaseNamePath(databaseName));
}
- /**
- * Delete table meta data.
- *
- * @param schemaName schema name
- * @param tableName table name
- */
- public void delete(final String schemaName, final String tableName) {
- repository.delete(DatabaseMetaDataNode.getTableMetaDataPath(schemaName, schemaName, tableName));
- }
-
/**
* Delete table meta data.
*
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DatabaseRulePersistService.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DatabaseRulePersistService.java
index 7358280aeb0..107facfcb8c 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DatabaseRulePersistService.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/service/impl/DatabaseRulePersistService.java
@@ -76,10 +76,10 @@ public final class DatabaseRulePersistService implements DatabaseBasedPersistSer
@SuppressWarnings("unchecked")
@Override
- public Collection<RuleConfiguration> load(final String schemaName, final String version) {
- String yamlContent = repository.get(DatabaseMetaDataNode.getRulePath(schemaName, version));
+ public Collection<RuleConfiguration> load(final String databaseName, final String version) {
+ String yamlContent = repository.get(DatabaseMetaDataNode.getRulePath(databaseName, version));
return Strings.isNullOrEmpty(yamlContent) ? new LinkedList<>() : new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(YamlEngine.unmarshal(repository.get(DatabaseMetaDataNode
- .getRulePath(schemaName, getDatabaseActiveVersion(schemaName))), Collection.class, true));
+ .getRulePath(databaseName, getDatabaseActiveVersion(databaseName))), Collection.class, true));
}
@Override
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
index 9c0c0a87000..996d752ce76 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
@@ -85,7 +85,7 @@ public final class ContextManagerTest {
when(metaDataContexts.getGlobalRuleMetaData().getRules()).thenReturn(Collections.emptyList());
when(metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases()).thenReturn(new LinkedHashMap<>());
when(metaDataContexts.getProps()).thenReturn(new ConfigurationProperties(new Properties()));
- when(metaDataContexts.getMetaData("foo_schema").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
+ when(metaDataContexts.getMetaData("foo_db").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
}
@Test
@@ -112,44 +112,44 @@ public final class ContextManagerTest {
}
@Test
- public void assertAddSchema() throws SQLException {
+ public void assertAddDatabase() throws SQLException {
when(metaDataContexts.getMetaDataMap()).thenReturn(new LinkedHashMap<>());
- contextManager.addSchema("foo_schema");
- assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().containsKey("foo_schema"));
- assertTrue(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_schema"));
+ contextManager.addDatabase("foo_db");
+ assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().containsKey("foo_db"));
+ assertTrue(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_db"));
}
@Test
- public void assertAlterSchema() {
- contextManager.alterSchema("foo_schema", Collections.singletonMap("foo_schema", new ShardingSphereSchema(Collections.singletonMap("foo_table",
+ public void assertAlterDatabase() {
+ contextManager.alterDatabase("foo_db", Collections.singletonMap("foo_db", new ShardingSphereSchema(Collections.singletonMap("foo_table",
new TableMetaData("foo_table", Collections.emptyList(), Collections.emptyList(), Collections.emptyList())))));
- assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_schema").getDefaultSchema().containsTable("foo_table"));
- assertTrue(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_schema"));
- Map<String, FederationSchemaMetaData> schemas = contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().get("foo_schema").getSchemas();
- assertTrue(schemas.get("foo_schema").getTables().containsKey("foo_table"));
+ assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getDefaultSchema().containsTable("foo_table"));
+ assertTrue(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_db"));
+ Map<String, FederationSchemaMetaData> schemas = contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().get("foo_db").getSchemas();
+ assertTrue(schemas.get("foo_db").getTables().containsKey("foo_table"));
}
@Test
- public void assertDeleteSchema() {
- when(metaDataContexts.getMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", mock(ShardingSphereMetaData.class))));
- when(metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", mock(FederationDatabaseMetaData.class))));
- when(metaDataContexts.getOptimizerContext().getParserContexts()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", mock(OptimizerParserContext.class))));
- when(metaDataContexts.getOptimizerContext().getPlannerContexts()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", mock(OptimizerPlannerContext.class))));
- contextManager.deleteSchema("foo_schema");
- assertFalse(contextManager.getMetaDataContexts().getMetaDataMap().containsKey("foo_schema"));
- assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_schema"));
- assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getParserContexts().containsKey("foo_schema"));
- assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getPlannerContexts().containsKey("foo_schema"));
+ public void assertDeleteDatabase() {
+ when(metaDataContexts.getMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(ShardingSphereMetaData.class))));
+ when(metaDataContexts.getOptimizerContext().getFederationMetaData().getDatabases()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(FederationDatabaseMetaData.class))));
+ when(metaDataContexts.getOptimizerContext().getParserContexts()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(OptimizerParserContext.class))));
+ when(metaDataContexts.getOptimizerContext().getPlannerContexts()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", mock(OptimizerPlannerContext.class))));
+ contextManager.deleteDatabase("foo_db");
+ assertFalse(contextManager.getMetaDataContexts().getMetaDataMap().containsKey("foo_db"));
+ assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().containsKey("foo_db"));
+ assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getParserContexts().containsKey("foo_db"));
+ assertFalse(contextManager.getMetaDataContexts().getOptimizerContext().getPlannerContexts().containsKey("foo_db"));
}
@Test
public void assertAddResource() throws SQLException {
ShardingSphereResource resource = mock(ShardingSphereResource.class);
when(resource.getDatabaseType()).thenReturn(new MySQLDatabaseType());
- when(metaDataContexts.getMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", new ShardingSphereMetaData(
- "foo_schema", resource, new ShardingSphereRuleMetaData(new LinkedList<>(), new LinkedList<>()), Collections.emptyMap()))));
- contextManager.addResource("foo_schema", createToBeAddedDataSourceProperties());
- assertAddedDataSources(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_schema").getResource().getDataSources());
+ when(metaDataContexts.getMetaDataMap()).thenReturn(new HashMap<>(Collections.singletonMap("foo_db", new ShardingSphereMetaData(
+ "foo_db", resource, new ShardingSphereRuleMetaData(new LinkedList<>(), new LinkedList<>()), Collections.emptyMap()))));
+ contextManager.addResource("foo_db", createToBeAddedDataSourceProperties());
+ assertAddedDataSources(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getResource().getDataSources());
}
private Map<String, DataSourceProperties> createToBeAddedDataSourceProperties() {
@@ -173,19 +173,19 @@ public final class ContextManagerTest {
@Test
public void assertAlterResource() throws SQLException {
- Map<String, ShardingSphereMetaData> originalMetaDataMap = new HashMap<>(Collections.singletonMap("foo_schema", createOriginalMetaData()));
+ Map<String, ShardingSphereMetaData> originalMetaDataMap = new HashMap<>(Collections.singletonMap("foo_db", createOriginalMetaData()));
when(metaDataContexts.getMetaDataMap()).thenReturn(originalMetaDataMap);
- contextManager.alterResource("foo_schema", Collections.singletonMap("bar_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties("test", "test"))));
- assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaDataMap().get("foo_schema").getResource().getDataSources().get("bar_ds"));
+ contextManager.alterResource("foo_db", Collections.singletonMap("bar_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties("test", "test"))));
+ assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getResource().getDataSources().get("bar_ds"));
}
private ShardingSphereMetaData createOriginalMetaData() {
ShardingSphereResource resource = mock(ShardingSphereResource.class);
- when(resource.getDataSources()).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource()));
+ when(resource.getDataSources()).thenReturn(Collections.singletonMap("foo_db", new MockedDataSource()));
when(resource.getDatabaseType()).thenReturn(new MySQLDatabaseType());
ShardingSphereRuleMetaData ruleMetaData = mock(ShardingSphereRuleMetaData.class);
when(ruleMetaData.getConfigurations()).thenReturn(new LinkedList<>());
- return new ShardingSphereMetaData("foo_schema", resource, ruleMetaData, Collections.emptyMap());
+ return new ShardingSphereMetaData("foo_db", resource, ruleMetaData, Collections.emptyMap());
}
private void assertAlteredDataSource(final MockedDataSource actual) {
@@ -196,31 +196,31 @@ public final class ContextManagerTest {
@Test
public void assertDropResource() {
- when(metaDataContexts.getMetaData("foo_schema").getResource().getDataSources()).thenReturn(new HashMap<>(Collections.singletonMap("foo_ds", new MockedDataSource())));
- contextManager.dropResource("foo_schema", Collections.singleton("foo_ds"));
- assertTrue(contextManager.getMetaDataContexts().getMetaData("foo_schema").getResource().getDataSources().isEmpty());
+ when(metaDataContexts.getMetaData("foo_db").getResource().getDataSources()).thenReturn(new HashMap<>(Collections.singletonMap("foo_ds", new MockedDataSource())));
+ contextManager.dropResource("foo_db", Collections.singleton("foo_ds"));
+ assertTrue(contextManager.getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources().isEmpty());
}
@Test
public void assertAlterRuleConfiguration() {
ShardingSphereResource resource = mock(ShardingSphereResource.class);
when(resource.getDatabaseType()).thenReturn(new MySQLDatabaseType());
- when(metaDataContexts.getMetaDataMap()).thenReturn(Collections.singletonMap("foo_schema",
- new ShardingSphereMetaData("foo_schema", resource, mock(ShardingSphereRuleMetaData.class), Collections.emptyMap())));
+ when(metaDataContexts.getMetaDataMap()).thenReturn(Collections.singletonMap("foo_db",
+ new ShardingSphereMetaData("foo_db", resource, mock(ShardingSphereRuleMetaData.class), Collections.emptyMap())));
when(metaDataContexts.getMetaDataPersistService()).thenReturn(Optional.of(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS)));
RuleConfiguration ruleConfig = mock(RuleConfiguration.class);
- contextManager.alterRuleConfiguration("foo_schema", Collections.singleton(ruleConfig));
- assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_schema").getRuleMetaData().getConfigurations().contains(ruleConfig));
+ contextManager.alterRuleConfiguration("foo_db", Collections.singleton(ruleConfig));
+ assertTrue(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getRuleMetaData().getConfigurations().contains(ruleConfig));
}
@Test
public void assertAlterDataSourceConfiguration() {
- ShardingSphereMetaData originalMetaData = new ShardingSphereMetaData("foo_schema", createOriginalResource(), createOriginalRuleMetaData(), Collections.emptyMap());
- when(metaDataContexts.getMetaData("foo_schema")).thenReturn(originalMetaData);
- when(metaDataContexts.getMetaDataMap()).thenReturn(Collections.singletonMap("foo_schema", originalMetaData));
- contextManager.alterDataSourceConfiguration("foo_schema", Collections.singletonMap("foo_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties("test", "test"))));
- assertThat(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_schema").getResource().getDataSources().size(), is(1));
- assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaData("foo_schema").getResource().getDataSources().get("foo_ds"));
+ ShardingSphereMetaData originalMetaData = new ShardingSphereMetaData("foo_db", createOriginalResource(), createOriginalRuleMetaData(), Collections.emptyMap());
+ when(metaDataContexts.getMetaData("foo_db")).thenReturn(originalMetaData);
+ when(metaDataContexts.getMetaDataMap()).thenReturn(Collections.singletonMap("foo_db", originalMetaData));
+ contextManager.alterDataSourceConfiguration("foo_db", Collections.singletonMap("foo_ds", new DataSourceProperties(MockedDataSource.class.getName(), createProperties("test", "test"))));
+ assertThat(contextManager.getMetaDataContexts().getMetaDataMap().get("foo_db").getResource().getDataSources().size(), is(1));
+ assertAlteredDataSource((MockedDataSource) contextManager.getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources().get("foo_ds"));
}
private ShardingSphereResource createOriginalResource() {
@@ -256,18 +256,18 @@ public final class ContextManagerTest {
@Test
public void assertReloadMetaData() {
- when(metaDataContexts.getMetaData("foo_schema").getResource().getDataSources()).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource()));
+ when(metaDataContexts.getMetaData("foo_db").getResource().getDataSources()).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource()));
SchemaMetaDataPersistService schemaMetaDataPersistService = mock(SchemaMetaDataPersistService.class, RETURNS_DEEP_STUBS);
MetaDataPersistService metaDataPersistService = mock(MetaDataPersistService.class);
when(metaDataPersistService.getSchemaMetaDataService()).thenReturn(schemaMetaDataPersistService);
when(metaDataContexts.getMetaDataPersistService()).thenReturn(Optional.of(metaDataPersistService));
- contextManager.reloadMetaData("foo_schema");
- verify(schemaMetaDataPersistService, times(1)).persist(eq("foo_schema"), eq("foo_schema"), any(ShardingSphereSchema.class));
- contextManager.reloadMetaData("foo_schema", "foo_table");
- assertNotNull(contextManager.getMetaDataContexts().getMetaData("foo_schema"));
- contextManager.reloadMetaData("foo_schema", "foo_table", "foo_ds");
- assertNotNull(contextManager.getMetaDataContexts().getMetaData("foo_schema").getDefaultSchema());
- assertTrue(contextManager.getMetaDataContexts().getMetaData("foo_schema").getResource().getDataSources().containsKey("foo_ds"));
+ contextManager.reloadMetaData("foo_db");
+ verify(schemaMetaDataPersistService, times(1)).persist(eq("foo_db"), eq("foo_db"), any(ShardingSphereSchema.class));
+ contextManager.reloadMetaData("foo_db", "foo_table");
+ assertNotNull(contextManager.getMetaDataContexts().getMetaData("foo_db"));
+ contextManager.reloadMetaData("foo_db", "foo_table", "foo_ds");
+ assertNotNull(contextManager.getMetaDataContexts().getMetaData("foo_db").getDefaultSchema());
+ assertTrue(contextManager.getMetaDataContexts().getMetaData("foo_db").getResource().getDataSources().containsKey("foo_ds"));
}
private Map<String, Object> createProperties(final String username, final String password) {
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java
index 46ff4f6923a..098e09283a6 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/service/SchemaMetaDataPersistServiceTest.java
@@ -103,8 +103,8 @@ public final class SchemaMetaDataPersistServiceTest {
@Test
public void assertPersistTableMetaData() {
TableMetaData tableMetaData = new TableMetaData("FOO_TABLE", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
- new SchemaMetaDataPersistService(repository).persist("foo_db", tableMetaData);
- verify(repository).persist(eq("/metadata/foo_db/schemas/foo_db/tables/foo_table"), anyString());
+ new SchemaMetaDataPersistService(repository).persist("foo_db", "foo_schema", tableMetaData);
+ verify(repository).persist(eq("/metadata/foo_db/schemas/foo_schema/tables/foo_table"), anyString());
}
@SneakyThrows({IOException.class, URISyntaxException.class})
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 11fbd67c671..889608158ae 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -93,15 +93,15 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
}
private Properties getTransactionProperties(final MetaDataContexts metaDataContexts) {
- Optional<String> schemaName = metaDataContexts.getAllSchemaNames().stream().findFirst();
+ Optional<String> databaseName = metaDataContexts.getAllDatabaseNames().stream().findFirst();
Optional<TransactionRule> transactionRule =
metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
Optional<TransactionConfigurationFileGenerator> fileGenerator = transactionRule.isPresent()
? TransactionConfigurationFileGeneratorFactory.newInstance(transactionRule.get().getProviderType()) : Optional.empty();
- if (!schemaName.isPresent() || !fileGenerator.isPresent()) {
+ if (!databaseName.isPresent() || !fileGenerator.isPresent()) {
return transactionRule.isPresent() ? transactionRule.get().getProps() : new Properties();
}
- ShardingSphereMetaData metaData = metaDataContexts.getMetaData(schemaName.get());
+ ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName.get());
Properties result = fileGenerator.get().getTransactionProps(transactionRule.get().getProps(),
new DataSourceProvidedDatabaseConfiguration(metaData.getResource().getDataSources(), metaData.getRuleMetaData().getConfigurations()), getType());
Optional<TransactionRuleConfiguration> transactionRuleConfig = metaDataContexts.getGlobalRuleMetaData().findSingleRuleConfiguration(TransactionRuleConfiguration.class);
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java
index a6148011854..7c7c9937c50 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinator.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecu
import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.BatchYamlExecuteProcessContext;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceChangedEvent;
import org.apache.shardingsphere.infra.rule.identifier.type.InstanceAwareRule;
@@ -40,8 +40,8 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.confi
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.RuleConfigurationsChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.schema.SchemaChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.version.SchemaVersionChangedEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaDeletedEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseAddedEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.ShowProcessListManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.lock.ShowProcessListSimpleLock;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.process.node.ProcessNode;
@@ -87,23 +87,23 @@ public final class ClusterContextManagerCoordinator {
/**
* Renew to persist meta data.
*
- * @param event schema added event
+ * @param event database added event
* @throws SQLException SQL exception
*/
@Subscribe
- public synchronized void renew(final SchemaAddedEvent event) throws SQLException {
- persistSchema(event.getSchemaName());
- contextManager.addSchema(event.getSchemaName());
+ public synchronized void renew(final DatabaseAddedEvent event) throws SQLException {
+ persistDatabase(event.getDatabaseName());
+ contextManager.addDatabase(event.getDatabaseName());
}
/**
- * Renew to delete schema.
+ * Renew to delete database.
*
- * @param event schema delete event
+ * @param event database delete event
*/
@Subscribe
- public synchronized void renew(final SchemaDeletedEvent event) {
- contextManager.deleteSchema(event.getSchemaName());
+ public synchronized void renew(final DatabaseDeletedEvent event) {
+ contextManager.deleteDatabase(event.getDatabaseName());
}
/**
@@ -123,7 +123,7 @@ public final class ClusterContextManagerCoordinator {
*/
@Subscribe
public synchronized void renew(final SchemaChangedEvent event) {
- contextManager.alterSchema(event.getSchemaName(), event.getChangedTableMetaData(), event.getDeletedTable());
+ contextManager.alterDatabase(event.getDatabaseName(), event.getChangedTableMetaData(), event.getDeletedTable());
}
/**
@@ -133,8 +133,8 @@ public final class ClusterContextManagerCoordinator {
*/
@Subscribe
public synchronized void renew(final RuleConfigurationsChangedEvent event) {
- if (metaDataPersistService.getSchemaVersionPersistService().isActiveVersion(event.getSchemaName(), event.getSchemaVersion())) {
- contextManager.alterRuleConfiguration(event.getSchemaName(), event.getRuleConfigurations());
+ if (metaDataPersistService.getDatabaseVersionPersistService().isActiveVersion(event.getDatabaseName(), event.getSchemaVersion())) {
+ contextManager.alterRuleConfiguration(event.getDatabaseName(), event.getRuleConfigurations());
buildSpecialRules();
}
}
@@ -146,8 +146,8 @@ public final class ClusterContextManagerCoordinator {
*/
@Subscribe
public synchronized void renew(final DataSourceChangedEvent event) {
- if (metaDataPersistService.getSchemaVersionPersistService().isActiveVersion(event.getSchemaName(), event.getSchemaVersion())) {
- contextManager.alterDataSourceConfiguration(event.getSchemaName(), event.getDataSourcePropertiesMap());
+ if (metaDataPersistService.getDatabaseVersionPersistService().isActiveVersion(event.getDatabaseName(), event.getSchemaVersion())) {
+ contextManager.alterDataSourceConfiguration(event.getDatabaseName(), event.getDataSourcePropertiesMap());
buildSpecialRules();
}
}
@@ -159,8 +159,8 @@ public final class ClusterContextManagerCoordinator {
*/
@Subscribe
public synchronized void renew(final DisabledStateChangedEvent event) {
- QualifiedSchema qualifiedSchema = event.getQualifiedSchema();
- contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getSchemaName()).getRuleMetaData().getRules()
+ QualifiedDatabase qualifiedSchema = event.getQualifiedSchema();
+ contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getDatabaseName()).getRuleMetaData().getRules()
.stream()
.filter(each -> each instanceof StatusContainedRule)
.forEach(each -> ((StatusContainedRule) each)
@@ -174,8 +174,8 @@ public final class ClusterContextManagerCoordinator {
*/
@Subscribe
public synchronized void renew(final PrimaryStateChangedEvent event) {
- QualifiedSchema qualifiedSchema = event.getQualifiedSchema();
- contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getSchemaName()).getRuleMetaData().getRules()
+ QualifiedDatabase qualifiedSchema = event.getQualifiedDatabase();
+ contextManager.getMetaDataContexts().getMetaDataMap().get(qualifiedSchema.getDatabaseName()).getRuleMetaData().getRules()
.stream()
.filter(each -> each instanceof StatusContainedRule)
.forEach(each -> ((StatusContainedRule) each)
@@ -265,9 +265,9 @@ public final class ClusterContextManagerCoordinator {
*/
@Subscribe
public synchronized void renew(final SchemaVersionChangedEvent event) {
- Map<String, DataSourceProperties> dataSourcePropertiesMap = metaDataPersistService.getDataSourceService().load(event.getSchemaName(), event.getActiveVersion());
- Collection<RuleConfiguration> ruleConfigs = metaDataPersistService.getSchemaRuleService().load(event.getSchemaName(), event.getActiveVersion());
- contextManager.alterDataSourceAndRuleConfiguration(event.getSchemaName(), dataSourcePropertiesMap, ruleConfigs);
+ Map<String, DataSourceProperties> dataSourcePropertiesMap = metaDataPersistService.getDataSourceService().load(event.getDatabaseName(), event.getActiveVersion());
+ Collection<RuleConfiguration> ruleConfigs = metaDataPersistService.getSchemaRuleService().load(event.getDatabaseName(), event.getActiveVersion());
+ contextManager.alterDataSourceAndRuleConfiguration(event.getDatabaseName(), dataSourcePropertiesMap, ruleConfigs);
}
/**
@@ -304,12 +304,12 @@ public final class ClusterContextManagerCoordinator {
}
}
- private void persistSchema(final String schemaName) {
- if (!metaDataPersistService.getDataSourceService().isExisted(schemaName)) {
- metaDataPersistService.getDataSourceService().persist(schemaName, new LinkedHashMap<>());
+ private void persistDatabase(final String databaseName) {
+ if (!metaDataPersistService.getDataSourceService().isExisted(databaseName)) {
+ metaDataPersistService.getDataSourceService().persist(databaseName, new LinkedHashMap<>());
}
- if (!metaDataPersistService.getSchemaRuleService().isExisted(schemaName)) {
- metaDataPersistService.getSchemaRuleService().persist(schemaName, new LinkedList<>());
+ if (!metaDataPersistService.getSchemaRuleService().isExisted(databaseName)) {
+ metaDataPersistService.getSchemaRuleService().persist(databaseName, new LinkedList<>());
}
}
@@ -327,6 +327,6 @@ public final class ClusterContextManagerCoordinator {
Map<String, StorageNodeDataSource> storageNodes = registryCenter.getStorageNodeStatusService().loadStorageNodes();
Map<String, StorageNodeDataSource> disableDataSources = storageNodes.entrySet().stream().filter(entry -> StorageNodeStatus.DISABLED.name().toLowerCase().equals(entry.getValue().getStatus()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
- disableDataSources.forEach((key, value) -> rule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedSchema(key), true)));
+ disableDataSources.forEach((key, value) -> rule.updateStatus(new DataSourceNameDisabledEvent(new QualifiedDatabase(key), true)));
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/datasource/DataSourceChangedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/datasource/DataSourceChangedEvent.java
index 0a310177c2c..0bc1ada9df5 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/datasource/DataSourceChangedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/datasource/DataSourceChangedEvent.java
@@ -31,7 +31,7 @@ import java.util.Map;
@Getter
public final class DataSourceChangedEvent implements GovernanceEvent {
- private final String schemaName;
+ private final String databaseName;
private final String schemaVersion;
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/rule/RuleConfigurationsChangedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/rule/RuleConfigurationsChangedEvent.java
index 6a499e5b75b..ec1deeee7ed 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/rule/RuleConfigurationsChangedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/rule/RuleConfigurationsChangedEvent.java
@@ -31,7 +31,7 @@ import java.util.Collection;
@Getter
public final class RuleConfigurationsChangedEvent implements GovernanceEvent {
- private final String schemaName;
+ private final String databaseName;
private final String schemaVersion;
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/schema/SchemaChangedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/schema/SchemaChangedEvent.java
index ef40a36b3f4..aa520705208 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/schema/SchemaChangedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/schema/SchemaChangedEvent.java
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.Gover
@Getter
public final class SchemaChangedEvent implements GovernanceEvent {
+ private final String databaseName;
+
private final String schemaName;
private final TableMetaData changedTableMetaData;
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/version/SchemaVersionChangedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/version/SchemaVersionChangedEvent.java
index cb728acda42..90f8ddfdd1a 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/version/SchemaVersionChangedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/version/SchemaVersionChangedEvent.java
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.Gover
@Getter
public final class SchemaVersionChangedEvent implements GovernanceEvent {
- private final String schemaName;
+ private final String databaseName;
private final String activeVersion;
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/SchemaDeletedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseAddedEvent.java
similarity index 89%
rename from shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/SchemaDeletedEvent.java
rename to shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseAddedEvent.java
index 921ce15ff9a..45ed6cf1c04 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/SchemaDeletedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseAddedEvent.java
@@ -22,11 +22,11 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
/**
- * Schema deleted event.
+ * database added event.
*/
@RequiredArgsConstructor
@Getter
-public final class SchemaDeletedEvent implements GovernanceEvent {
+public final class DatabaseAddedEvent implements GovernanceEvent {
- private final String schemaName;
+ private final String databaseName;
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/SchemaAddedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseDeletedEvent.java
similarity index 89%
rename from shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/SchemaAddedEvent.java
rename to shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseDeletedEvent.java
index ed3739cc3fb..b10b37feb4e 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/SchemaAddedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/event/DatabaseDeletedEvent.java
@@ -22,11 +22,11 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
/**
- * Schema added event.
+ * database deleted event.
*/
@RequiredArgsConstructor
@Getter
-public final class SchemaAddedEvent implements GovernanceEvent {
+public final class DatabaseDeletedEvent implements GovernanceEvent {
- private final String schemaName;
+ private final String databaseName;
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriber.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegistrySu [...]
index d57c7340d7c..44499c2da16 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriber.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriber.java
@@ -42,7 +42,7 @@ public final class SchemaMetaDataRegistrySubscriber {
*/
@Subscribe
public void update(final SchemaAlteredEvent event) {
- event.getAlteredTables().forEach(each -> persistService.persist(event.getSchemaName(), each));
- event.getDroppedTables().forEach(each -> persistService.delete(event.getSchemaName(), each));
+ event.getAlteredTables().forEach(each -> persistService.persist(event.getDatabaseName(), event.getSchemaName(), each));
+ event.getDroppedTables().forEach(each -> persistService.delete(event.getDatabaseName(), event.getSchemaName(), each));
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java
index 95a19e7e092..bdccfd57d86 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/watcher/MetaDataChangedWatcher.java
@@ -33,8 +33,8 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.confi
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.RuleConfigurationsChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.schema.SchemaChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.version.SchemaVersionChangedEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaDeletedEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseAddedEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent;
import org.apache.shardingsphere.mode.metadata.persist.node.DatabaseMetaDataNode;
import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent.Type;
@@ -67,8 +67,8 @@ public final class MetaDataChangedWatcher implements GovernanceWatcher<Governanc
@Override
public Optional<GovernanceEvent> createGovernanceEvent(final DataChangedEvent event) {
- if (isLogicSchemaChanged(event)) {
- return buildLogicSchemaChangedEvent(event);
+ if (isLogicDatabaseChanged(event)) {
+ return buildLogicDatabaseChangedEvent(event);
} else if (isTableMetaDataChanged(event)) {
return buildTableMetaDataChangedEvent(event);
} else if (DataChangedEvent.Type.UPDATED == event.getType()) {
@@ -77,24 +77,25 @@ public final class MetaDataChangedWatcher implements GovernanceWatcher<Governanc
return Optional.empty();
}
- private boolean isLogicSchemaChanged(final DataChangedEvent event) {
+ private boolean isLogicDatabaseChanged(final DataChangedEvent event) {
return DatabaseMetaDataNode.getDatabaseNameByDatabasePath(event.getKey()).isPresent();
}
private boolean isTableMetaDataChanged(final DataChangedEvent event) {
Optional<String> databaseName = DatabaseMetaDataNode.getDatabaseName(event.getKey());
+ Optional<String> schemaName = DatabaseMetaDataNode.getSchemaName(event.getKey());
Optional<String> tableName = DatabaseMetaDataNode.getTableName(event.getKey());
- return databaseName.isPresent() && tableName.isPresent()
+ return databaseName.isPresent() && tableName.isPresent() && schemaName.isPresent()
&& !SystemSchemaBuilderRule.isSystemTable(databaseName.get(), tableName.get()) && !Strings.isNullOrEmpty(event.getValue());
}
- private Optional<GovernanceEvent> buildLogicSchemaChangedEvent(final DataChangedEvent event) {
+ private Optional<GovernanceEvent> buildLogicDatabaseChangedEvent(final DataChangedEvent event) {
String databaseName = DatabaseMetaDataNode.getDatabaseNameByDatabasePath(event.getKey()).get();
if (DataChangedEvent.Type.ADDED == event.getType() || DataChangedEvent.Type.UPDATED == event.getType()) {
- return Optional.of(new SchemaAddedEvent(databaseName));
+ return Optional.of(new DatabaseAddedEvent(databaseName));
}
if (DataChangedEvent.Type.DELETED == event.getType()) {
- return Optional.of(new SchemaDeletedEvent(databaseName));
+ return Optional.of(new DatabaseDeletedEvent(databaseName));
}
return Optional.empty();
}
@@ -119,17 +120,17 @@ public final class MetaDataChangedWatcher implements GovernanceWatcher<Governanc
}
@SuppressWarnings("unchecked")
- private DataSourceChangedEvent createDataSourceChangedEvent(final String schemaName, final String schemaVersion, final DataChangedEvent event) {
+ private DataSourceChangedEvent createDataSourceChangedEvent(final String databaseName, final String schemaVersion, final DataChangedEvent event) {
Map<String, Map<String, Object>> yamlDataSources = YamlEngine.unmarshal(event.getValue(), Map.class);
Map<String, DataSourceProperties> dataSourcePropertiesMap = yamlDataSources.isEmpty()
? new HashMap<>()
: yamlDataSources.entrySet().stream().collect(Collectors.toMap(
Entry::getKey, entry -> new YamlDataSourceConfigurationSwapper().swapToDataSourceProperties(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
- return new DataSourceChangedEvent(schemaName, schemaVersion, dataSourcePropertiesMap);
+ return new DataSourceChangedEvent(databaseName, schemaVersion, dataSourcePropertiesMap);
}
- private GovernanceEvent createRuleChangedEvent(final String schemaName, final String schemaVersion, final DataChangedEvent event) {
- return new RuleConfigurationsChangedEvent(schemaName, schemaVersion, getRuleConfigurations(event.getValue()));
+ private GovernanceEvent createRuleChangedEvent(final String databaseName, final String schemaVersion, final DataChangedEvent event) {
+ return new RuleConfigurationsChangedEvent(databaseName, schemaVersion, getRuleConfigurations(event.getValue()));
}
@SuppressWarnings("unchecked")
@@ -142,10 +143,11 @@ public final class MetaDataChangedWatcher implements GovernanceWatcher<Governanc
private Optional<GovernanceEvent> buildTableMetaDataChangedEvent(final DataChangedEvent event) {
String databaseName = DatabaseMetaDataNode.getDatabaseName(event.getKey()).get();
+ String schemaName = DatabaseMetaDataNode.getSchemaName(event.getKey()).get();
String tableName = DatabaseMetaDataNode.getTableName(event.getKey()).get();
if (DataChangedEvent.Type.DELETED == event.getType()) {
- return Optional.of(new SchemaChangedEvent(databaseName, null, tableName));
+ return Optional.of(new SchemaChangedEvent(databaseName, schemaName, null, tableName));
}
- return Optional.of(new SchemaChangedEvent(databaseName, new TableMetaDataYamlSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlTableMetaData.class)), null));
+ return Optional.of(new SchemaChangedEvent(databaseName, schemaName, new TableMetaDataYamlSwapper().swapToObject(YamlEngine.unmarshal(event.getValue(), YamlTableMetaData.class)), null));
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/DisabledStateChangedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/DisabledStateChangedEvent.java
index 11e1b00f603..b6cff04206f 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/DisabledStateChangedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/DisabledStateChangedEvent.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
/**
* Disabled state event.
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
@Getter
public final class DisabledStateChangedEvent implements GovernanceEvent {
- private final QualifiedSchema qualifiedSchema;
+ private final QualifiedDatabase qualifiedSchema;
private final boolean disabled;
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/PrimaryStateChangedEvent.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/PrimaryStateChangedEvent.java
index 30dd4beec88..df6f847ff15 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/PrimaryStateChangedEvent.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/event/PrimaryStateChangedEvent.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
/**
* Primary state event.
@@ -29,5 +29,5 @@ import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
@Getter
public final class PrimaryStateChangedEvent implements GovernanceEvent {
- private final QualifiedSchema qualifiedSchema;
+ private final QualifiedDatabase qualifiedDatabase;
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNode.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNode.java
index 8b256d5da79..ed82edebff0 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNode.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNode.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.StatusNode;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import java.util.Optional;
import java.util.regex.Matcher;
@@ -61,7 +61,7 @@ public final class StorageStatusNode {
* @param schema cluster schema
* @return status path of storage node
*/
- public static String getStatusPath(final QualifiedSchema schema) {
+ public static String getStatusPath(final QualifiedDatabase schema) {
return String.join("/", "", StatusNode.ROOT_NODE, STORAGE_NODES, ATTRIBUTES_NODE, schema.toString());
}
@@ -71,9 +71,9 @@ public final class StorageStatusNode {
* @param storageNodePath storage node path
* @return extracted qualified schema
*/
- public static Optional<QualifiedSchema> extractQualifiedSchema(final String storageNodePath) {
+ public static Optional<QualifiedDatabase> extractQualifiedSchema(final String storageNodePath) {
Pattern pattern = Pattern.compile(getRootPath() + "/(\\S+)$", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(storageNodePath);
- return matcher.find() ? Optional.of(new QualifiedSchema(matcher.group(1))) : Optional.empty();
+ return matcher.find() ? Optional.of(new QualifiedDatabase(matcher.group(1))) : Optional.empty();
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatus [...]
index b9209256a56..0e34765a3a0 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriber.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.storage.StorageNodeRole;
import org.apache.shardingsphere.infra.storage.StorageNodeStatus;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node.StorageStatusNode;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
/**
@@ -48,7 +48,7 @@ public final class StorageNodeStatusSubscriber {
*/
@Subscribe
public void update(final DataSourceDisabledEvent event) {
- repository.persist(StorageStatusNode.getStatusPath(new QualifiedSchema(event.getSchemaName(), event.getGroupName(), event.getDataSourceName())),
+ repository.persist(StorageStatusNode.getStatusPath(new QualifiedDatabase(event.getDatabaseName(), event.getGroupName(), event.getDataSourceName())),
YamlEngine.marshal(event.getStorageNodeDataSource()));
}
@@ -59,6 +59,6 @@ public final class StorageNodeStatusSubscriber {
*/
@Subscribe
public void update(final PrimaryDataSourceChangedEvent event) {
- repository.persist(StorageStatusNode.getStatusPath(event.getQualifiedSchema()), YamlEngine.marshal(new StorageNodeDataSource(StorageNodeRole.PRIMARY, StorageNodeStatus.ENABLED)));
+ repository.persist(StorageStatusNode.getStatusPath(event.getQualifiedDatabase()), YamlEngine.marshal(new StorageNodeDataSource(StorageNodeRole.PRIMARY, StorageNodeStatus.ENABLED)));
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChan [...]
index 3864a7b809c..feb1b0c2ed6 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.watcher;
import org.apache.commons.lang.StringUtils;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.storage.StorageNodeDataSource;
import org.apache.shardingsphere.infra.storage.StorageNodeRole;
import org.apache.shardingsphere.infra.storage.StorageNodeStatus;
@@ -56,9 +56,9 @@ public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<G
if (StringUtils.isEmpty(event.getValue())) {
return Optional.empty();
}
- Optional<QualifiedSchema> qualifiedSchema = StorageStatusNode.extractQualifiedSchema(event.getKey());
+ Optional<QualifiedDatabase> qualifiedSchema = StorageStatusNode.extractQualifiedSchema(event.getKey());
if (qualifiedSchema.isPresent()) {
- QualifiedSchema schema = qualifiedSchema.get();
+ QualifiedDatabase schema = qualifiedSchema.get();
StorageNodeDataSource storageNodeDataSource = YamlEngine.unmarshal(event.getValue(), StorageNodeDataSource.class);
if (StorageNodeRole.PRIMARY.name().toLowerCase().equals(storageNodeDataSource.getRole())) {
return Optional.of(new PrimaryStateChangedEvent(schema));
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index 9f1a606b0dc..7d753b5f337 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -40,7 +40,7 @@ import org.apache.shardingsphere.infra.metadata.resource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.resource.DataSourcesMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -57,8 +57,8 @@ import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.confi
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.RuleConfigurationsChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.schema.SchemaChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.version.SchemaVersionChangedEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaAddedEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.SchemaDeletedEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseAddedEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.event.DatabaseDeletedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOnlineEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.LabelsEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.StateEvent;
@@ -140,13 +140,13 @@ public final class ClusterContextManagerCoordinatorTest {
}
@Test
- public void assertSchemaAdd() throws SQLException {
- SchemaAddedEvent event = new SchemaAddedEvent("schema_add");
- when(metaDataPersistService.getDataSourceService().load("schema_add")).thenReturn(getDataSourcePropertiesMap());
- when(metaDataPersistService.getSchemaRuleService().load("schema_add")).thenReturn(Collections.emptyList());
+ public void assertDatabaseAdd() throws SQLException {
+ DatabaseAddedEvent event = new DatabaseAddedEvent("db_add");
+ when(metaDataPersistService.getDataSourceService().load("db_add")).thenReturn(getDataSourcePropertiesMap());
+ when(metaDataPersistService.getSchemaRuleService().load("db_add")).thenReturn(Collections.emptyList());
coordinator.renew(event);
- assertNotNull(contextManager.getMetaDataContexts().getMetaData("schema_add"));
- assertNotNull(contextManager.getMetaDataContexts().getMetaData("schema_add").getResource().getDataSources());
+ assertNotNull(contextManager.getMetaDataContexts().getMetaData("db_add"));
+ assertNotNull(contextManager.getMetaDataContexts().getMetaData("db_add").getResource().getDataSources());
}
private Map<String, DataSourceProperties> getDataSourcePropertiesMap() {
@@ -160,9 +160,9 @@ public final class ClusterContextManagerCoordinatorTest {
@Test
public void assertSchemaDelete() {
- SchemaDeletedEvent event = new SchemaDeletedEvent("schema");
+ DatabaseDeletedEvent event = new DatabaseDeletedEvent("db");
coordinator.renew(event);
- assertNull(contextManager.getMetaDataContexts().getMetaData("schema"));
+ assertNull(contextManager.getMetaDataContexts().getMetaData("db"));
}
@Test
@@ -177,37 +177,37 @@ public final class ClusterContextManagerCoordinatorTest {
@Test
public void assertSchemaChanged() {
TableMetaData changedTableMetaData = new TableMetaData("t_order", Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
- SchemaChangedEvent event = new SchemaChangedEvent("schema", changedTableMetaData, null);
+ SchemaChangedEvent event = new SchemaChangedEvent("db", "db", changedTableMetaData, null);
coordinator.renew(event);
- assertTrue(contextManager.getMetaDataContexts().getAllSchemaNames().contains("schema"));
- verify(contextManager.getMetaDataContexts().getMetaData("schema").getDefaultSchema()).put(eq("t_order"), eq(event.getChangedTableMetaData()));
+ assertTrue(contextManager.getMetaDataContexts().getAllDatabaseNames().contains("db"));
+ verify(contextManager.getMetaDataContexts().getMetaData("db").getDefaultSchema()).put(eq("t_order"), eq(event.getChangedTableMetaData()));
}
@Test
public void assertRuleConfigurationsChanged() {
- when(metaDataPersistService.getSchemaVersionPersistService().isActiveVersion("schema", "0")).thenReturn(Boolean.TRUE);
- assertThat(contextManager.getMetaDataContexts().getMetaData("schema"), is(metaData));
- RuleConfigurationsChangedEvent event = new RuleConfigurationsChangedEvent("schema", "0", new LinkedList<>());
+ when(metaDataPersistService.getDatabaseVersionPersistService().isActiveVersion("db", "0")).thenReturn(Boolean.TRUE);
+ assertThat(contextManager.getMetaDataContexts().getMetaData("db"), is(metaData));
+ RuleConfigurationsChangedEvent event = new RuleConfigurationsChangedEvent("db", "0", new LinkedList<>());
coordinator.renew(event);
- assertThat(contextManager.getMetaDataContexts().getMetaData("schema"), not(metaData));
+ assertThat(contextManager.getMetaDataContexts().getMetaData("db"), not(metaData));
}
@Test
public void assertDisableStateChanged() {
StatusContainedRule statusContainedRule = mock(StatusContainedRule.class);
when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.singletonList(statusContainedRule));
- DisabledStateChangedEvent event = new DisabledStateChangedEvent(new QualifiedSchema("schema.readwrite_ds.ds_0"), true);
+ DisabledStateChangedEvent event = new DisabledStateChangedEvent(new QualifiedDatabase("db.readwrite_ds.ds_0"), true);
coordinator.renew(event);
verify(statusContainedRule, times(1)).updateStatus(argThat((ArgumentMatcher<DataSourceNameDisabledEvent>) argumentEvent ->
- Objects.equals(event.getQualifiedSchema(), argumentEvent.getQualifiedSchema()) && argumentEvent.isDisabled()));
+ Objects.equals(event.getQualifiedSchema(), argumentEvent.getQualifiedDatabase()) && argumentEvent.isDisabled()));
}
@Test
public void assertDataSourceChanged() {
- when(metaDataPersistService.getSchemaVersionPersistService().isActiveVersion("schema", "0")).thenReturn(Boolean.TRUE);
- DataSourceChangedEvent event = new DataSourceChangedEvent("schema", "0", getChangedDataSourcePropertiesMap());
+ when(metaDataPersistService.getDatabaseVersionPersistService().isActiveVersion("db", "0")).thenReturn(Boolean.TRUE);
+ DataSourceChangedEvent event = new DataSourceChangedEvent("db", "0", getChangedDataSourcePropertiesMap());
coordinator.renew(event);
- assertTrue(contextManager.getMetaDataContexts().getMetaData("schema").getResource().getDataSources().containsKey("ds_2"));
+ assertTrue(contextManager.getMetaDataContexts().getMetaData("db").getResource().getDataSources().containsKey("ds_2"));
}
private Map<String, DataSourceProperties> getChangedDataSourcePropertiesMap() {
@@ -243,7 +243,7 @@ public final class ClusterContextManagerCoordinatorTest {
}
private Map<String, ShardingSphereMetaData> createMetaDataMap() {
- when(metaData.getName()).thenReturn("schema");
+ when(metaData.getName()).thenReturn("db");
ShardingSphereResource resource = mock(ShardingSphereResource.class);
when(resource.getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(metaData.getResource()).thenReturn(resource);
@@ -251,13 +251,13 @@ public final class ClusterContextManagerCoordinatorTest {
when(metaData.getDefaultSchema()).thenReturn(schema);
when(metaData.getRuleMetaData().getRules()).thenReturn(new LinkedList<>());
when(metaData.getRuleMetaData().getConfigurations()).thenReturn(new LinkedList<>());
- return new HashMap<>(Collections.singletonMap("schema", metaData));
+ return new HashMap<>(Collections.singletonMap("db", metaData));
}
private OptimizerContext createOptimizerContext() {
OptimizerContext result = mock(OptimizerContext.class, RETURNS_DEEP_STUBS);
Map<String, FederationDatabaseMetaData> databases = new HashMap<>(1, 1);
- databases.put("schema", new FederationDatabaseMetaData("schema", Collections.emptyMap()));
+ databases.put("db", new FederationDatabaseMetaData("db", Collections.emptyMap()));
when(result.getFederationMetaData().getDatabases()).thenReturn(databases);
return result;
}
@@ -270,8 +270,8 @@ public final class ClusterContextManagerCoordinatorTest {
ShardingSphereRuleMetaData mockShardingSphereRuleMetaData = new ShardingSphereRuleMetaData(new LinkedList<>(), rules);
ShardingSphereMetaData mockShardingSphereMetaData = mock(ShardingSphereMetaData.class);
when(mockShardingSphereMetaData.getRuleMetaData()).thenReturn(mockShardingSphereRuleMetaData);
- contextManager.getMetaDataContexts().getMetaDataMap().put("schema", mockShardingSphereMetaData);
- PrimaryStateChangedEvent mockPrimaryStateChangedEvent = new PrimaryStateChangedEvent(new QualifiedSchema("schema.readwrite_ds.test_ds"));
+ contextManager.getMetaDataContexts().getMetaDataMap().put("db", mockShardingSphereMetaData);
+ PrimaryStateChangedEvent mockPrimaryStateChangedEvent = new PrimaryStateChangedEvent(new QualifiedDatabase("db.readwrite_ds.test_ds"));
coordinator.renew(mockPrimaryStateChangedEvent);
verify(mockStatusContainedRule).updateStatus(any());
}
@@ -320,16 +320,16 @@ public final class ClusterContextManagerCoordinatorTest {
@Test
public void assertRenewSchemaVersionChangedEvent() {
- when(metaDataPersistService.getDataSourceService().load("schema", "1")).thenReturn(getVersionChangedDataSourcePropertiesMap());
- when(metaDataPersistService.getSchemaRuleService().load("schema", "1")).thenReturn(Collections.emptyList());
- SchemaVersionChangedEvent schemaVersionChangedEvent = new SchemaVersionChangedEvent("schema", "1");
+ when(metaDataPersistService.getDataSourceService().load("db", "1")).thenReturn(getVersionChangedDataSourcePropertiesMap());
+ when(metaDataPersistService.getSchemaRuleService().load("db", "1")).thenReturn(Collections.emptyList());
+ SchemaVersionChangedEvent schemaVersionChangedEvent = new SchemaVersionChangedEvent("db", "1");
Map<String, DataSource> dataSourceMap = initContextManager();
coordinator.renew(schemaVersionChangedEvent);
- assertThat(contextManager.getDataSourceMap("schema").get("ds_0"), is(dataSourceMap.get("ds_0")));
- assertNotNull(contextManager.getDataSourceMap("schema").get("ds_1"));
- assertThat(DataSourcePropertiesCreator.create(getChangeMockedDataSource()), is(DataSourcePropertiesCreator.create(contextManager.getDataSourceMap("schema").get("ds_1"))));
- assertNotNull(contextManager.getDataSourceMap("schema").get("primary_ds"));
- assertThat(DataSourcePropertiesCreator.create(getDefaultMockedDataSource()), is(DataSourcePropertiesCreator.create(contextManager.getDataSourceMap("schema").get("primary_ds"))));
+ assertThat(contextManager.getDataSourceMap("db").get("ds_0"), is(dataSourceMap.get("ds_0")));
+ assertNotNull(contextManager.getDataSourceMap("db").get("ds_1"));
+ assertThat(DataSourcePropertiesCreator.create(getChangeMockedDataSource()), is(DataSourcePropertiesCreator.create(contextManager.getDataSourceMap("db").get("ds_1"))));
+ assertNotNull(contextManager.getDataSourceMap("db").get("primary_ds"));
+ assertThat(DataSourcePropertiesCreator.create(getDefaultMockedDataSource()), is(DataSourcePropertiesCreator.create(contextManager.getDataSourceMap("db").get("primary_ds"))));
}
@Test
@@ -354,8 +354,8 @@ public final class ClusterContextManagerCoordinatorTest {
private Map<String, DataSource> initContextManager() {
Map<String, DataSource> result = getDataSourceMap();
ShardingSphereResource shardingSphereResource = new ShardingSphereResource(result, mock(DataSourcesMetaData.class), mock(CachedDatabaseMetaData.class), mock(DatabaseType.class));
- ShardingSphereMetaData mockShardingSphereMetaData = new ShardingSphereMetaData("schema", shardingSphereResource, mock(ShardingSphereRuleMetaData.class), Collections.emptyMap());
- contextManager.getMetaDataContexts().getMetaDataMap().put("schema", mockShardingSphereMetaData);
+ ShardingSphereMetaData mockShardingSphereMetaData = new ShardingSphereMetaData("db", shardingSphereResource, mock(ShardingSphereRuleMetaData.class), Collections.emptyMap());
+ contextManager.getMetaDataContexts().getMetaDataMap().put("db", mockShardingSphereMetaData);
return result;
}
@@ -363,7 +363,7 @@ public final class ClusterContextManagerCoordinatorTest {
Map<String, DataSource> result = new LinkedHashMap<>(3, 1);
result.put("ds_0", getDefaultMockedDataSource());
result.put("ds_1", getDefaultMockedDataSource());
- result.put("schema", getDefaultMockedDataSource());
+ result.put("db", getDefaultMockedDataSource());
return result;
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriberTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegist [...]
index dd85c4e7d25..7ef804e4af7 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriberTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriberTest.java
@@ -50,12 +50,12 @@ public final class SchemaMetaDataRegistrySubscriberTest {
@Test
public void assertUpdateWithMetaDataAlteredEvent() {
- SchemaAlteredEvent event = new SchemaAlteredEvent("foo_db");
+ SchemaAlteredEvent event = new SchemaAlteredEvent("foo_db", "foo_schema");
TableMetaData tableMetaData = new TableMetaData();
event.getAlteredTables().add(tableMetaData);
event.getDroppedTables().add("foo_table");
schemaMetaDataRegistrySubscriber.update(event);
- verify(persistService).persist("foo_db", tableMetaData);
- verify(persistService).delete("foo_db", "foo_table");
+ verify(persistService).persist("foo_db", "foo_schema", tableMetaData);
+ verify(persistService).delete("foo_db", "foo_schema", "foo_table");
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNodeTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNodeTest.java
index b18e0a3fa2d..5e01d369dd3 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNodeTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/node/StorageStatusNodeTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.junit.Test;
import java.util.Optional;
@@ -35,9 +35,9 @@ public final class StorageStatusNodeTest {
@Test
public void assertExtractQualifiedSchema() {
- Optional<QualifiedSchema> actual = StorageStatusNode.extractQualifiedSchema("/nodes/storage_nodes/attributes/replica_query_db.readwrite_ds.replica_ds_0");
+ Optional<QualifiedDatabase> actual = StorageStatusNode.extractQualifiedSchema("/nodes/storage_nodes/attributes/replica_query_db.readwrite_ds.replica_ds_0");
assertTrue(actual.isPresent());
- assertThat(actual.get().getSchemaName(), is("replica_query_db"));
+ assertThat(actual.get().getDatabaseName(), is("replica_query_db"));
assertThat(actual.get().getGroupName(), is("readwrite_ds"));
assertThat(actual.get().getDataSourceName(), is("replica_ds_0"));
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeSt [...]
index 6782536fbdf..362ad74bf2b 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/subscriber/StorageNodeStatusSubscriberTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.subscriber;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceChangedEvent;
import org.apache.shardingsphere.infra.storage.StorageNodeDataSource;
@@ -47,7 +47,7 @@ public final class StorageNodeStatusSubscriberTest {
StorageNodeDataSource storageNodeDataSource = new StorageNodeDataSource(StorageNodeRole.MEMBER, StorageNodeStatus.DISABLED);
DataSourceDisabledEvent dataSourceDisabledEvent = new DataSourceDisabledEvent(schemaName, groupName, dataSourceName, storageNodeDataSource);
new StorageNodeStatusSubscriber(repository).update(dataSourceDisabledEvent);
- verify(repository).persist(StorageStatusNode.getStatusPath(new QualifiedSchema(schemaName, groupName, dataSourceName)), YamlEngine.marshal(storageNodeDataSource));
+ verify(repository).persist(StorageStatusNode.getStatusPath(new QualifiedDatabase(schemaName, groupName, dataSourceName)), YamlEngine.marshal(storageNodeDataSource));
}
@Test
@@ -58,7 +58,7 @@ public final class StorageNodeStatusSubscriberTest {
StorageNodeDataSource storageNodeDataSource = new StorageNodeDataSource(StorageNodeRole.MEMBER, StorageNodeStatus.ENABLED);
DataSourceDisabledEvent dataSourceDisabledEvent = new DataSourceDisabledEvent(schemaName, groupName, dataSourceName, storageNodeDataSource);
new StorageNodeStatusSubscriber(repository).update(dataSourceDisabledEvent);
- verify(repository).persist(StorageStatusNode.getStatusPath(new QualifiedSchema(schemaName, groupName, dataSourceName)), YamlEngine.marshal(storageNodeDataSource));
+ verify(repository).persist(StorageStatusNode.getStatusPath(new QualifiedDatabase(schemaName, groupName, dataSourceName)), YamlEngine.marshal(storageNodeDataSource));
}
@Test
@@ -66,9 +66,9 @@ public final class StorageNodeStatusSubscriberTest {
String schemaName = "replica_query_db";
String groupName = "readwrite_ds";
String dataSourceName = "replica_ds_0";
- PrimaryDataSourceChangedEvent event = new PrimaryDataSourceChangedEvent(new QualifiedSchema(schemaName, groupName, dataSourceName));
+ PrimaryDataSourceChangedEvent event = new PrimaryDataSourceChangedEvent(new QualifiedDatabase(schemaName, groupName, dataSourceName));
new StorageNodeStatusSubscriber(repository).update(event);
- verify(repository).persist(StorageStatusNode.getStatusPath(new QualifiedSchema(schemaName, groupName, dataSourceName)),
+ verify(repository).persist(StorageStatusNode.getStatusPath(new QualifiedDatabase(schemaName, groupName, dataSourceName)),
YamlEngine.marshal(new StorageNodeDataSource(StorageNodeRole.PRIMARY, StorageNodeStatus.ENABLED)));
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeState [...]
index 59cae2a6c03..19736c73a09 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcherTest.java
@@ -39,9 +39,9 @@ public final class StorageNodeStateChangedWatcherTest {
new DataChangedEvent("/nodes/storage_nodes/attributes/replica_query_db.readwrite_ds.replica_ds_0", "role: primary\nstatus: enable\n", Type.ADDED));
assertTrue(actual.isPresent());
PrimaryStateChangedEvent actualEvent = (PrimaryStateChangedEvent) actual.get();
- assertThat(actualEvent.getQualifiedSchema().getSchemaName(), is("replica_query_db"));
- assertThat(actualEvent.getQualifiedSchema().getGroupName(), is("readwrite_ds"));
- assertThat(actualEvent.getQualifiedSchema().getDataSourceName(), is("replica_ds_0"));
+ assertThat(actualEvent.getQualifiedDatabase().getDatabaseName(), is("replica_query_db"));
+ assertThat(actualEvent.getQualifiedDatabase().getGroupName(), is("readwrite_ds"));
+ assertThat(actualEvent.getQualifiedDatabase().getDataSourceName(), is("replica_ds_0"));
}
@Test
@@ -50,7 +50,7 @@ public final class StorageNodeStateChangedWatcherTest {
new DataChangedEvent("/nodes/storage_nodes/attributes/replica_query_db.readwrite_ds.replica_ds_0", "role: member\nstatus: enable\n", Type.ADDED));
assertTrue(actual.isPresent());
DisabledStateChangedEvent actualEvent = (DisabledStateChangedEvent) actual.get();
- assertThat(actualEvent.getQualifiedSchema().getSchemaName(), is("replica_query_db"));
+ assertThat(actualEvent.getQualifiedSchema().getDatabaseName(), is("replica_query_db"));
assertThat(actualEvent.getQualifiedSchema().getGroupName(), is("readwrite_ds"));
assertThat(actualEvent.getQualifiedSchema().getDataSourceName(), is("replica_ds_0"));
assertFalse(actualEvent.isDisabled());
@@ -62,7 +62,7 @@ public final class StorageNodeStateChangedWatcherTest {
new DataChangedEvent("/nodes/storage_nodes/attributes/replica_query_db.readwrite_ds.replica_ds_0", "role: member\nstatus: disable\n", Type.DELETED));
assertTrue(actual.isPresent());
DisabledStateChangedEvent actualEvent = (DisabledStateChangedEvent) actual.get();
- assertThat(actualEvent.getQualifiedSchema().getSchemaName(), is("replica_query_db"));
+ assertThat(actualEvent.getQualifiedSchema().getDatabaseName(), is("replica_query_db"));
assertThat(actualEvent.getQualifiedSchema().getGroupName(), is("readwrite_ds"));
assertThat(actualEvent.getQualifiedSchema().getDataSourceName(), is("replica_ds_0"));
assertTrue(actualEvent.isDisabled());
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 95ddb8c0627..1d84f989636 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
@@ -88,9 +88,9 @@ public abstract class DatabaseCommunicationEngine<T> {
this.metaData = metaData;
this.logicSQL = logicSQL;
this.backendConnection = backendConnection;
- String schemaName = backendConnection.getConnectionSession().getSchemaName();
+ String databaseName = backendConnection.getConnectionSession().getDatabaseName();
metadataRefreshEngine = new MetaDataRefreshEngine(metaData,
- ProxyContext.getInstance().getContextManager().getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().get(schemaName),
+ ProxyContext.getInstance().getContextManager().getMetaDataContexts().getOptimizerContext().getFederationMetaData().getDatabases().get(databaseName),
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getOptimizerContext().getPlannerContexts(),
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps());
}
@@ -219,7 +219,7 @@ public abstract class DatabaseCommunicationEngine<T> {
}
protected void checkLockedSchema(final ExecutionContext executionContext) {
- if (isLockedSchema(backendConnection.getConnectionSession().getSchemaName())) {
+ if (isLockedSchema(backendConnection.getConnectionSession().getDatabaseName())) {
lockedWrite(executionContext.getSqlStatementContext().getSqlStatement());
}
}
@@ -232,6 +232,6 @@ public abstract class DatabaseCommunicationEngine<T> {
if (sqlStatement instanceof SelectStatement) {
return;
}
- throw new SchemaLockedException(backendConnection.getConnectionSession().getSchemaName());
+ throw new SchemaLockedException(backendConnection.getConnectionSession().getDatabaseName());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
index 975af197e7c..98b9cebc719 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
@@ -60,7 +60,7 @@ public final class DatabaseCommunicationEngineFactory {
* @return text protocol backend handler
*/
public <T extends DatabaseCommunicationEngine> T newTextProtocolInstance(final SQLStatementContext<?> sqlStatementContext, final String sql, final BackendConnection<?> backendConnection) {
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getSchemaName());
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, Collections.emptyList());
T result;
if (backendConnection instanceof JDBCBackendConnection) {
@@ -86,7 +86,7 @@ public final class DatabaseCommunicationEngineFactory {
*/
public <T extends DatabaseCommunicationEngine> T newBinaryProtocolInstance(final SQLStatementContext<?> sqlStatementContext, final String sql,
final List<Object> parameters, final BackendConnection<?> backendConnection) {
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getSchemaName());
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, parameters);
T result;
if (backendConnection instanceof JDBCBackendConnection) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
index a86df4f5385..f46a198b841 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
@@ -112,8 +112,8 @@ public final class ProxySQLExecutor {
* @throws SQLException SQL exception
*/
public List<ExecuteResult> execute(final ExecutionContext executionContext) throws SQLException {
- String schemaName = backendConnection.getConnectionSession().getSchemaName();
- Collection<ShardingSphereRule> rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules();
+ String databaseName = backendConnection.getConnectionSession().getDatabaseName();
+ Collection<ShardingSphereRule> rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules();
int maxConnectionsSizePerQuery = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
boolean isReturnGeneratedKeys = executionContext.getSqlStatementContext().getSqlStatement() instanceof MySQLInsertStatement;
return execute(executionContext, rules, maxConnectionsSizePerQuery, isReturnGeneratedKeys);
@@ -142,7 +142,7 @@ public final class ProxySQLExecutor {
} catch (final SQLException ex) {
return getSaneExecuteResults(executionContext, ex);
}
- executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getSchemaName());
+ executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getDatabaseName());
executionGroupContext.setGrantee(backendConnection.getConnectionSession().getGrantee());
// TODO handle query header
return rawExecutor.execute(executionGroupContext, executionContext.getLogicSQL(), new RawSQLExecutorCallback());
@@ -159,13 +159,13 @@ public final class ProxySQLExecutor {
} catch (final SQLException ex) {
return getSaneExecuteResults(executionContext, ex);
}
- executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getSchemaName());
+ executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getDatabaseName());
executionGroupContext.setGrantee(backendConnection.getConnectionSession().getGrantee());
return jdbcExecutor.execute(executionContext.getLogicSQL(), executionGroupContext, isReturnGeneratedKeys, isExceptionThrown);
}
private List<ExecuteResult> getSaneExecuteResults(final ExecutionContext executionContext, final SQLException originalException) throws SQLException {
- DatabaseType databaseType = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName()).getResource().getDatabaseType();
Optional<ExecuteResult> executeResult = JDBCSaneQueryResultEngineFactory.newInstance(databaseType).getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement());
if (executeResult.isPresent()) {
return Collections.singletonList(executeResult.get());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java
index a5b5ff346c0..00ce3eb74da 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java
@@ -96,8 +96,8 @@ public final class ReactiveProxySQLExecutor {
* @throws SQLException SQL exception
*/
public Future<List<ExecuteResult>> execute(final ExecutionContext executionContext) throws SQLException {
- String schemaName = backendConnection.getConnectionSession().getSchemaName();
- Collection<ShardingSphereRule> rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules();
+ String databaseName = backendConnection.getConnectionSession().getDatabaseName();
+ Collection<ShardingSphereRule> rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules();
int maxConnectionsSizePerQuery = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
return useDriverToExecute(executionContext, rules, maxConnectionsSizePerQuery);
}
@@ -113,13 +113,13 @@ public final class ReactiveProxySQLExecutor {
} catch (final SQLException ex) {
return Future.succeededFuture(getSaneExecuteResults(executionContext, ex));
}
- executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getSchemaName());
+ executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getDatabaseName());
executionGroupContext.setGrantee(backendConnection.getConnectionSession().getGrantee());
return reactiveExecutor.execute(executionContext.getLogicSQL(), executionGroupContext);
}
private List<ExecuteResult> getSaneExecuteResults(final ExecutionContext executionContext, final SQLException originalException) throws SQLException {
- DatabaseType databaseType = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getDatabaseName()).getResource().getDatabaseType();
Optional<ExecuteResult> executeResult = JDBCSaneQueryResultEngineFactory.newInstance(databaseType).getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement());
if (executeResult.isPresent()) {
return Collections.singletonList(executeResult.get());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
index d68d0551c5a..893fe8c67e9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
@@ -86,7 +86,7 @@ public final class JDBCDatabaseCommunicationEngine extends DatabaseCommunication
proxySQLExecutor = new ProxySQLExecutor(driverType, backendConnection, this);
this.backendConnection = backendConnection;
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- String databaseName = backendConnection.getConnectionSession().getSchemaName();
+ String databaseName = backendConnection.getConnectionSession().getDatabaseName();
String schemaName = logicSQL.getSqlStatementContext().getTablesContext().getSchemaName().orElse(databaseName);
federationExecutor = FederationExecutorFactory.newInstance(databaseName, schemaName, metaDataContexts.getOptimizerContext(),
metaDataContexts.getProps(), new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), backendConnection.isSerialExecute()));
@@ -123,9 +123,9 @@ public final class JDBCDatabaseCommunicationEngine extends DatabaseCommunication
logicSQL, getMetaData(), ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps());
// TODO move federation route logic to binder
SQLStatementContext<?> sqlStatementContext = logicSQL.getSqlStatementContext();
- String defaultSchemaName = backendConnection.getConnectionSession().getSchemaName();
+ String defaultDatabaseName = backendConnection.getConnectionSession().getDatabaseName();
if (executionContext.getRouteContext().isFederated() || (sqlStatementContext instanceof SelectStatementContext
- && SystemSchemaUtil.containsSystemSchema(sqlStatementContext.getDatabaseType(), sqlStatementContext.getTablesContext().getSchemaNames(), defaultSchemaName))) {
+ && SystemSchemaUtil.containsSystemSchema(sqlStatementContext.getDatabaseType(), sqlStatementContext.getTablesContext().getSchemaNames(), defaultDatabaseName))) {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
ResultSet resultSet = doExecuteFederation(logicSQL, metaDataContexts);
return processExecuteFederation(resultSet, metaDataContexts);
@@ -145,7 +145,7 @@ public final class JDBCDatabaseCommunicationEngine extends DatabaseCommunication
private ResultSet doExecuteFederation(final LogicSQL logicSQL, final MetaDataContexts metaDataContexts) throws SQLException {
boolean isReturnGeneratedKeys = logicSQL.getSqlStatementContext().getSqlStatement() instanceof MySQLInsertStatement;
- DatabaseType databaseType = metaDataContexts.getMetaData(backendConnection.getConnectionSession().getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = metaDataContexts.getMetaData(backendConnection.getConnectionSession().getDatabaseName()).getResource().getDatabaseType();
ProxyJDBCExecutorCallback callback = ProxyJDBCExecutorCallbackFactory.newInstance(getDriverType(), databaseType,
logicSQL.getSqlStatementContext().getSqlStatement(), this, isReturnGeneratedKeys, SQLExecutorExceptionHandler.isExceptionThrown(), true);
backendConnection.setFederationExecutor(federationExecutor);
@@ -158,13 +158,13 @@ public final class JDBCDatabaseCommunicationEngine extends DatabaseCommunication
int maxConnectionsSizePerQuery = metaData.getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
JDBCBackendStatement statementManager = (JDBCBackendStatement) backendConnection.getConnectionSession().getStatementManager();
return new DriverExecutionPrepareEngine<>(getDriverType(), maxConnectionsSizePerQuery, backendConnection, statementManager,
- new StatementOption(isReturnGeneratedKeys), metaData.getMetaData(backendConnection.getConnectionSession().getSchemaName()).getRuleMetaData().getRules());
+ new StatementOption(isReturnGeneratedKeys), metaData.getMetaData(backendConnection.getConnectionSession().getDatabaseName()).getRuleMetaData().getRules());
}
private ResponseHeader processExecuteFederation(final ResultSet resultSet, final MetaDataContexts metaDataContexts) throws SQLException {
int columnCount = resultSet.getMetaData().getColumnCount();
setQueryHeaders(new ArrayList<>(columnCount));
- ShardingSphereMetaData metaData = metaDataContexts.getMetaData(backendConnection.getConnectionSession().getSchemaName());
+ ShardingSphereMetaData metaData = metaDataContexts.getMetaData(backendConnection.getConnectionSession().getDatabaseName());
LazyInitializer<DataNodeContainedRule> dataNodeContainedRule = getDataNodeContainedRuleLazyInitializer(metaData);
QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(null == metaData ? null : metaData.getResource().getDatabaseType());
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
index 58b0768424b..c59d9ac80b2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
@@ -97,8 +97,8 @@ public final class JDBCBackendConnection implements BackendConnection<Void>, Exe
}
private List<Connection> createNewConnections(final String dataSourceName, final int connectionSize, final ConnectionMode connectionMode) throws SQLException {
- Preconditions.checkNotNull(connectionSession.getSchemaName(), "Current schema is null.");
- List<Connection> result = ProxyContext.getInstance().getBackendDataSource().getConnections(connectionSession.getSchemaName(), dataSourceName, connectionSize, connectionMode);
+ Preconditions.checkNotNull(connectionSession.getDatabaseName(), "Current schema is null.");
+ List<Connection> result = ProxyContext.getInstance().getBackendDataSource().getConnections(connectionSession.getDatabaseName(), dataSourceName, connectionSize, connectionMode);
for (Connection each : result) {
replayTransactionOption(each);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java
index f216dd32b08..7bbc939e423 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/ProxyJDBCExecutor.java
@@ -65,7 +65,7 @@ public final class ProxyJDBCExecutor {
final boolean isReturnGeneratedKeys, final boolean isExceptionThrown) throws SQLException {
try {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- DatabaseType databaseType = metaDataContexts.getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getResource().getDatabaseType();
ExecuteProcessEngine.initialize(logicSQL, executionGroupContext, metaDataContexts.getProps());
SQLStatementContext<?> context = logicSQL.getSqlStatementContext();
List<ExecuteResult> result = jdbcExecutor.execute(executionGroupContext,
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
index f9c8d368118..42194b4171b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
@@ -110,10 +110,10 @@ public abstract class ProxyJDBCExecutorCallback extends JDBCExecutorCallback<Exe
if (configuredDatabaseType.isPresent()) {
return configuredDatabaseType.get();
}
- if (ProxyContext.getInstance().getContextManager().getMetaDataContexts().getAllSchemaNames().isEmpty()) {
+ if (ProxyContext.getInstance().getContextManager().getMetaDataContexts().getAllDatabaseNames().isEmpty()) {
return DatabaseTypeRegistry.getTrunkDatabaseType("MySQL");
}
- String schemaName = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getAllSchemaNames().iterator().next();
+ String schemaName = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getAllDatabaseNames().iterator().next();
return ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource().getDatabaseType();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java
index e951e92be3d..ff5f6d612e0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java
@@ -48,7 +48,7 @@ public final class JDBCBackendTransactionManager implements TransactionManager<V
connection = backendConnection;
transactionType = connection.getConnectionSession().getTransactionStatus().getTransactionType();
localTransactionManager = new LocalTransactionManager(backendConnection);
- ShardingSphereTransactionManagerEngine engine = ProxyContext.getInstance().getContextManager().getTransactionContexts().getEngines().get(connection.getConnectionSession().getSchemaName());
+ ShardingSphereTransactionManagerEngine engine = ProxyContext.getInstance().getContextManager().getTransactionContexts().getEngines().get(connection.getConnectionSession().getDatabaseName());
shardingSphereTransactionManager = null == engine ? null : engine.getTransactionManager(transactionType);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java
index c12ff55ec5a..fffe3ca7034 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/vertx/VertxBackendConnection.java
@@ -91,8 +91,8 @@ public final class VertxBackendConnection implements BackendConnection<Future<Vo
}
private List<Future<SqlConnection>> createNewConnections(final String dataSourceName, final int connectionSize) {
- Preconditions.checkNotNull(connectionSession.getSchemaName(), "Current schema is null.");
- List<Future<SqlConnection>> result = ReactiveProxyContext.getInstance().getVertxBackendDataSource().getConnections(connectionSession.getSchemaName(), dataSourceName, connectionSize);
+ Preconditions.checkNotNull(connectionSession.getDatabaseName(), "Current database is null.");
+ List<Future<SqlConnection>> result = ReactiveProxyContext.getInstance().getVertxBackendDataSource().getConnections(connectionSession.getDatabaseName(), dataSourceName, connectionSize);
for (Future<SqlConnection> each : result) {
replayMethodsInvocation(each);
}
@@ -106,9 +106,9 @@ public final class VertxBackendConnection implements BackendConnection<Future<Vo
}
private List<Future<? extends SqlClient>> getConnectionsWithoutTransaction(final String dataSourceName) {
- Preconditions.checkNotNull(connectionSession.getSchemaName(), "Current schema is null.");
+ Preconditions.checkNotNull(connectionSession.getDatabaseName(), "Current database is null.");
// TODO At present, amount of connections without transaction is controlled by Vert.x pool.
- Future<SqlClient> poolFuture = Future.succeededFuture(ReactiveProxyContext.getInstance().getVertxBackendDataSource().getPool(connectionSession.getSchemaName(), dataSourceName));
+ Future<SqlClient> poolFuture = Future.succeededFuture(ReactiveProxyContext.getInstance().getVertxBackendDataSource().getPool(connectionSession.getDatabaseName(), dataSourceName));
return Collections.singletonList(poolFuture);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
index 95ec4030b1e..5a533b76685 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
@@ -64,35 +64,35 @@ public final class ProxyContext {
}
/**
- * Check schema exists.
+ * Check database exists.
*
- * @param schemaName schema name
- * @return schema exists or not
+ * @param databaseName database name
+ * @return database exists or not
*/
- public boolean schemaExists(final String schemaName) {
- return contextManager.getMetaDataContexts().getAllSchemaNames().contains(schemaName);
+ public boolean databaseExists(final String databaseName) {
+ return contextManager.getMetaDataContexts().getAllDatabaseNames().contains(databaseName);
}
/**
* Get ShardingSphere meta data.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @return ShardingSphere meta data
*/
- public ShardingSphereMetaData getMetaData(final String schemaName) {
- if (Strings.isNullOrEmpty(schemaName) || !contextManager.getMetaDataContexts().getAllSchemaNames().contains(schemaName)) {
+ public ShardingSphereMetaData getMetaData(final String databaseName) {
+ if (Strings.isNullOrEmpty(databaseName) || !contextManager.getMetaDataContexts().getAllDatabaseNames().contains(databaseName)) {
throw new NoDatabaseSelectedException();
}
- return contextManager.getMetaDataContexts().getMetaData(schemaName);
+ return contextManager.getMetaDataContexts().getMetaData(databaseName);
}
/**
- * Get all schema names.
+ * Get all database names.
*
- * @return all schema names
+ * @return all database names
*/
- public Collection<String> getAllSchemaNames() {
- return contextManager.getMetaDataContexts().getAllSchemaNames();
+ public Collection<String> getAllDatabaseNames() {
+ return contextManager.getMetaDataContexts().getAllDatabaseNames();
}
/**
@@ -113,7 +113,7 @@ public final class ProxyContext {
// TODO performance enhancement: cache when call init() and pay attention for refresh of rule modification
public Collection<ShardingSphereRule> getRules(final String databaseName) {
Collection<ShardingSphereRule> result = new LinkedList<>();
- if (!Strings.isNullOrEmpty(databaseName) && schemaExists(databaseName)) {
+ if (!Strings.isNullOrEmpty(databaseName) && databaseExists(databaseName)) {
result.addAll(contextManager.getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules());
}
result.addAll(contextManager.getMetaDataContexts().getGlobalRuleMetaData().getRules());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
index ddbbd56f0a8..555220ba167 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
@@ -49,7 +49,7 @@ public final class ConnectionSession {
private final DatabaseType databaseType;
@Setter(AccessLevel.NONE)
- private volatile String schemaName;
+ private volatile String databaseName;
private volatile int connectionId;
@@ -92,39 +92,39 @@ public final class ConnectionSession {
}
/**
- * Change schema of current channel.
+ * Change database of current channel.
*
- * @param schemaName schema name
+ * @param databaseName database name
*/
- public void setCurrentSchema(final String schemaName) {
- if (null != schemaName && schemaName.equals(this.schemaName)) {
+ public void setCurrentDatabase(final String databaseName) {
+ if (null != databaseName && databaseName.equals(this.databaseName)) {
return;
}
if (transactionStatus.isInTransaction()) {
- throw new ShardingSphereException("Failed to switch schema, please terminate current transaction.");
+ throw new ShardingSphereException("Failed to switch database, please terminate current transaction.");
}
if (statementManager instanceof JDBCBackendStatement) {
- ((JDBCBackendStatement) statementManager).setSchemaName(schemaName);
+ ((JDBCBackendStatement) statementManager).setSchemaName(databaseName);
}
- this.schemaName = schemaName;
+ this.databaseName = databaseName;
}
/**
- * Get schema name.
+ * Get database name.
*
- * @return schema name
+ * @return database name
*/
- public String getSchemaName() {
- return null == SQLStatementSchemaHolder.get() ? schemaName : SQLStatementSchemaHolder.get();
+ public String getDatabaseName() {
+ return null == SQLStatementSchemaHolder.get() ? databaseName : SQLStatementSchemaHolder.get();
}
/**
- * Get default schema name.
+ * Get default database name.
*
- * @return default schema name
+ * @return default database name
*/
- public String getDefaultSchemaName() {
- return schemaName;
+ public String getDefaultDatabaseName() {
+ return databaseName;
}
/**
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java
index 72bf2c6c832..ac65027fddb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/SchemaRequiredBackendHandler.java
@@ -46,24 +46,24 @@ public abstract class SchemaRequiredBackendHandler<T extends SQLStatement> imple
@Override
public final ResponseHeader execute() throws SQLException {
- String schemaName = getSchemaName(connectionSession, sqlStatement);
- checkSchema(schemaName);
- return execute(schemaName, sqlStatement);
+ String databaseName = getDatabaseName(connectionSession, sqlStatement);
+ checkDatabase(databaseName);
+ return execute(databaseName, sqlStatement);
}
- protected abstract ResponseHeader execute(String schemaName, T sqlStatement) throws SQLException;
+ protected abstract ResponseHeader execute(String databaseName, T sqlStatement) throws SQLException;
- private String getSchemaName(final ConnectionSession connectionSession, final T sqlStatement) {
+ private String getDatabaseName(final ConnectionSession connectionSession, final T sqlStatement) {
Optional<SchemaSegment> schemaFromSQL = sqlStatement instanceof FromSchemaAvailable ? ((FromSchemaAvailable) sqlStatement).getSchema() : Optional.empty();
- return schemaFromSQL.isPresent() ? schemaFromSQL.get().getIdentifier().getValue() : connectionSession.getSchemaName();
+ return schemaFromSQL.isPresent() ? schemaFromSQL.get().getIdentifier().getValue() : connectionSession.getDatabaseName();
}
- private void checkSchema(final String schemaName) {
- if (null == schemaName) {
+ private void checkDatabase(final String databaseName) {
+ if (null == databaseName) {
throw new NoDatabaseSelectedException();
}
- if (!ProxyContext.getInstance().schemaExists(schemaName)) {
- throw new UnknownDatabaseException(schemaName);
+ if (!ProxyContext.getInstance().databaseExists(databaseName)) {
+ throw new UnknownDatabaseException(databaseName);
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
index 068b8e32293..793798ec5b0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
@@ -97,7 +97,7 @@ public final class TextProtocolBackendHandlerFactory {
return DistSQLBackendHandlerFactory.newInstance(databaseType, (DistSQLStatement) sqlStatement, connectionSession);
}
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(),
- sqlStatement, connectionSession.getDefaultSchemaName());
+ sqlStatement, connectionSession.getDefaultDatabaseName());
Optional<TextProtocolBackendHandler> backendHandler = DatabaseAdminBackendHandlerFactory.newInstance(databaseType, sqlStatementContext, connectionSession, sql);
if (backendHandler.isPresent()) {
return backendHandler.get();
@@ -115,7 +115,7 @@ public final class TextProtocolBackendHandlerFactory {
return databaseOperateHandler.get();
}
String databaseName = sqlStatementContext.getTablesContext().getDatabaseName().isPresent()
- ? sqlStatementContext.getTablesContext().getDatabaseName().get() : connectionSession.getSchemaName();
+ ? sqlStatementContext.getTablesContext().getDatabaseName().get() : connectionSession.getDatabaseName();
SQLCheckEngine.check(sqlStatement, Collections.emptyList(),
getRules(databaseName), databaseName, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), connectionSession.getGrantee());
if (sqlStatement instanceof TCLStatement) {
@@ -126,9 +126,9 @@ public final class TextProtocolBackendHandlerFactory {
}
private static DatabaseType getBackendDatabaseType(final DatabaseType defaultDatabaseType, final ConnectionSession connectionSession) {
- String schemaName = connectionSession.getSchemaName();
- return Strings.isNullOrEmpty(schemaName) || !ProxyContext.getInstance().schemaExists(schemaName)
- ? defaultDatabaseType : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource().getDatabaseType();
+ String databaseName = connectionSession.getDatabaseName();
+ return Strings.isNullOrEmpty(databaseName) || !ProxyContext.getInstance().databaseExists(databaseName)
+ ? defaultDatabaseType : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource().getDatabaseType();
}
private static Optional<ExtraTextProtocolBackendHandler> findExtraTextProtocolBackendHandler(final SQLStatement sqlStatement) {
@@ -147,13 +147,13 @@ public final class TextProtocolBackendHandlerFactory {
return Optional.empty();
}
- private static Collection<ShardingSphereRule> getRules(final String schemaName) {
+ private static Collection<ShardingSphereRule> getRules(final String databaseName) {
MetaDataContexts contexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- if (Strings.isNullOrEmpty(schemaName) || !ProxyContext.getInstance().schemaExists(schemaName)) {
+ if (Strings.isNullOrEmpty(databaseName) || !ProxyContext.getInstance().databaseExists(databaseName)) {
return contexts.getGlobalRuleMetaData().getRules();
}
Collection<ShardingSphereRule> result;
- result = new LinkedList<>(contexts.getMetaData(schemaName).getRuleMetaData().getRules());
+ result = new LinkedList<>(contexts.getMetaData(databaseName).getRuleMetaData().getRules());
result.addAll(contexts.getGlobalRuleMetaData().getRules());
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java
index 6654954bd6a..b860953bca9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java
@@ -76,7 +76,7 @@ public final class DatabaseAdminBackendHandlerFactory {
if (!executorFactory.isPresent()) {
return Optional.empty();
}
- Optional<DatabaseAdminExecutor> executor = executorFactory.get().newInstance(sqlStatementContext, sql, connectionSession.getSchemaName());
+ Optional<DatabaseAdminExecutor> executor = executorFactory.get().newInstance(sqlStatementContext, sql, connectionSession.getDatabaseName());
return executor.map(optional -> createTextProtocolBackendHandler(sqlStatementContext, connectionSession, optional));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java
index efc6d9b6a21..13dd8da3e12 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminQueryBackendHandler.java
@@ -63,7 +63,7 @@ public final class DatabaseAdminQueryBackendHandler implements TextProtocolBacke
private List<QueryHeader> createResponseHeader() throws SQLException {
List<QueryHeader> result = new ArrayList<>(queryResultMetaData.getColumnCount());
- ShardingSphereMetaData metaData = null == connectionSession.getSchemaName() ? null : ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName());
+ ShardingSphereMetaData metaData = null == connectionSession.getDatabaseName() ? null : ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName());
DatabaseType databaseType = null == metaData ? connectionSession.getDatabaseType()
: ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(metaData.getName()).getResource().getDatabaseType();
QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(databaseType);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java
index ddf20c2adbd..01c9e4f768e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/AbstractDatabaseMetadataExecutor.java
@@ -69,17 +69,17 @@ public abstract class AbstractDatabaseMetadataExecutor implements DatabaseAdminQ
@Override
public final void execute(final ConnectionSession connectionSession) throws SQLException {
- List<String> schemaNames = getSchemaNames(connectionSession);
- for (String schemaName : schemaNames) {
- initSchemaData(schemaName);
- getSourceData(schemaName, resultSet -> handleResultSet(schemaName, resultSet));
+ List<String> databaseNames = getDatabaseNames(connectionSession);
+ for (String databaseName : databaseNames) {
+ initDatabaseData(databaseName);
+ getSourceData(databaseName, resultSet -> handleResultSet(databaseName, resultSet));
}
createPreProcessing();
queryResultMetaData = createQueryResultMetaData();
mergedResult = createMergedResult();
}
- private void handleResultSet(final String schemaName, final ResultSet resultSet) throws SQLException {
+ private void handleResultSet(final String databaseName, final ResultSet resultSet) throws SQLException {
while (resultSet.next()) {
Map<String, Object> rowMap = new LinkedHashMap<>();
Map<String, String> aliasMap = new LinkedHashMap<>();
@@ -88,7 +88,7 @@ public abstract class AbstractDatabaseMetadataExecutor implements DatabaseAdminQ
aliasMap.put(metaData.getColumnName(i), metaData.getColumnLabel(i));
rowMap.put(metaData.getColumnLabel(i), resultSet.getString(i));
}
- rowPostProcessing(schemaName, rowMap, aliasMap);
+ rowPostProcessing(databaseName, rowMap, aliasMap);
if (!rowMap.isEmpty()) {
rows.addFirst(rowMap);
}
@@ -96,19 +96,19 @@ public abstract class AbstractDatabaseMetadataExecutor implements DatabaseAdminQ
}
/**
- * Initialize the schema data.
+ * Initialize the database data.
*
- * @param schemaName schema name
+ * @param databaseName database name
*/
- protected abstract void initSchemaData(String schemaName);
+ protected abstract void initDatabaseData(String databaseName);
/**
- * Get the schema names as a condition for SQL execution.
+ * Get the database names as a condition for SQL execution.
*
* @param connectionSession connection session
- * @return schema names
+ * @return database names
*/
- protected abstract List<String> getSchemaNames(ConnectionSession connectionSession);
+ protected abstract List<String> getDatabaseNames(ConnectionSession connectionSession);
/**
* Add default row data.
@@ -128,11 +128,11 @@ public abstract class AbstractDatabaseMetadataExecutor implements DatabaseAdminQ
/**
* Get the source object of the row data.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param rowMap row
* @param aliasMap alias
*/
- protected abstract void rowPostProcessing(String schemaName, Map<String, Object> rowMap, Map<String, String> aliasMap);
+ protected abstract void rowPostProcessing(String databaseName, Map<String, Object> rowMap, Map<String, String> aliasMap);
private MergedResult createMergedResult() {
List<MemoryQueryResultDataRow> resultDataRows = rows.stream()
@@ -159,17 +159,17 @@ public abstract class AbstractDatabaseMetadataExecutor implements DatabaseAdminQ
/**
* Determine whether there is authority.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param grantee grantee
* @return has authority or not
*/
- protected static boolean hasAuthority(final String schemaName, final Grantee grantee) {
- return SQLCheckEngine.check(schemaName, getRules(schemaName), grantee);
+ protected static boolean hasAuthority(final String databaseName, final Grantee grantee) {
+ return SQLCheckEngine.check(databaseName, getRules(databaseName), grantee);
}
- private static Collection<ShardingSphereRule> getRules(final String schemaName) {
+ private static Collection<ShardingSphereRule> getRules(final String databaseName) {
Collection<ShardingSphereRule> result;
- result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules());
+ result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules());
result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules());
return result;
}
@@ -188,30 +188,30 @@ public abstract class AbstractDatabaseMetadataExecutor implements DatabaseAdminQ
}
@Override
- protected void initSchemaData(final String schemaName) {
+ protected void initDatabaseData(final String databaseName) {
}
/**
- * Get the schema names as a condition for SQL execution.
+ * Get the database names as a condition for SQL execution.
*
- * @return schema names
+ * @return database names
*/
@Override
- protected List<String> getSchemaNames(final ConnectionSession connectionSession) {
- String schema = ProxyContext.getInstance().getAllSchemaNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee()))
+ protected List<String> getDatabaseNames(final ConnectionSession connectionSession) {
+ String database = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee()))
.filter(AbstractDatabaseMetadataExecutor::hasDatasource).findFirst().orElseThrow(DatabaseNotExistedException::new);
- return Collections.singletonList(schema);
+ return Collections.singletonList(database);
}
/**
* Get the source data of the row data.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @throws SQLException SQLException
*/
@Override
- protected void getSourceData(final String schemaName, final FunctionWithException<ResultSet, SQLException> callback) throws SQLException {
- ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
+ protected void getSourceData(final String databaseName, final FunctionWithException<ResultSet, SQLException> callback) throws SQLException {
+ ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource();
Optional<Entry<String, DataSource>> dataSourceEntry = resource.getDataSources().entrySet().stream().findFirst();
log.info("Actual SQL: {} ::: {}", dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
try (Connection conn = dataSourceEntry.get().getValue().getConnection();
@@ -224,12 +224,12 @@ public abstract class AbstractDatabaseMetadataExecutor implements DatabaseAdminQ
/**
* Custom processing.
*
- * @param schemaName schema name
+ * @param databaseName database name
* @param rowMap row
* @param aliasMap alias
*/
@Override
- protected void rowPostProcessing(final String schemaName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
+ protected void rowPostProcessing(final String databaseName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
}
/**
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorFactory.java
index 4d494c30107..d00c59d5ef5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/MySQLAdminExecutorFactory.java
@@ -97,7 +97,7 @@ public final class MySQLAdminExecutorFactory implements DatabaseAdminExecutorFac
return Optional.of(new ShowCreateDatabaseExecutor((MySQLShowCreateDatabaseStatement) sqlStatement));
}
if (sqlStatement instanceof SetStatement) {
- if (!hasSchemas() || !hasResources()) {
+ if (!hasDatabases() || !hasResources()) {
return Optional.of(new NoResourceSetExecutor((SetStatement) sqlStatement));
}
if (isSetClientEncoding((SetStatement) sqlStatement)) {
@@ -115,10 +115,10 @@ public final class MySQLAdminExecutorFactory implements DatabaseAdminExecutorFac
|| isShowSpecialFunction((SelectStatement) sqlStatement, ShowCurrentUserExecutor.FUNCTION_NAME_ALIAS)) {
return Optional.of(new ShowCurrentUserExecutor());
}
- if ((!hasSchemas() || !hasResources()) && isShowSpecialFunction((SelectStatement) sqlStatement, ShowTransactionExecutor.TRANSACTION_READ_ONLY)) {
+ if ((!hasDatabases() || !hasResources()) && isShowSpecialFunction((SelectStatement) sqlStatement, ShowTransactionExecutor.TRANSACTION_READ_ONLY)) {
return Optional.of(new ShowTransactionExecutor(ShowTransactionExecutor.TRANSACTION_READ_ONLY));
}
- if ((!hasSchemas() || !hasResources()) && isShowSpecialFunction((SelectStatement) sqlStatement, ShowTransactionExecutor.TRANSACTION_ISOLATION)) {
+ if ((!hasDatabases() || !hasResources()) && isShowSpecialFunction((SelectStatement) sqlStatement, ShowTransactionExecutor.TRANSACTION_ISOLATION)) {
return Optional.of(new ShowTransactionExecutor(ShowTransactionExecutor.TRANSACTION_ISOLATION));
}
if (isShowSpecialFunction((SelectStatement) sqlStatement, ShowCurrentDatabaseExecutor.FUNCTION_NAME)) {
@@ -160,7 +160,7 @@ public final class MySQLAdminExecutorFactory implements DatabaseAdminExecutorFac
private DatabaseAdminExecutor mockExecutor(final String schemaName, final SelectStatement sqlStatement, final String sql) {
boolean isNotUseSchema = !Optional.ofNullable(schemaName).isPresent() && sqlStatement.getFrom() == null;
if (isNotUseSchema) {
- if (!hasSchemas() || !hasResources()) {
+ if (!hasDatabases() || !hasResources()) {
return new NoResourceShowExecutor(sqlStatement);
} else {
// TODO Avoid accessing database here, consider using `org.apache.shardingsphere.proxy.backend.text.data.DatabaseBackendHandler`
@@ -171,12 +171,12 @@ public final class MySQLAdminExecutorFactory implements DatabaseAdminExecutorFac
return null;
}
- private boolean hasSchemas() {
- return !ProxyContext.getInstance().getAllSchemaNames().isEmpty();
+ private boolean hasDatabases() {
+ return !ProxyContext.getInstance().getAllDatabaseNames().isEmpty();
}
private boolean hasResources() {
- return ProxyContext.getInstance().getAllSchemaNames().stream().anyMatch(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource());
+ return ProxyContext.getInstance().getAllDatabaseNames().stream().anyMatch(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource());
}
private boolean isSetClientEncoding(final SetStatement setStatement) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutor.java
index 4b5a15e5da2..66647e552d1 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutor.java
@@ -63,12 +63,12 @@ public final class ShowCreateDatabaseExecutor implements DatabaseAdminQueryExecu
mergedResult = new TransparentMergedResult(getQueryResult(showCreateDatabaseStatement.getSchemaName()));
}
- private QueryResult getQueryResult(final String schemaName) {
- if (!ProxyContext.getInstance().schemaExists(schemaName)) {
- throw new SchemaNotExistedException(schemaName);
+ private QueryResult getQueryResult(final String databaseName) {
+ if (!ProxyContext.getInstance().databaseExists(databaseName)) {
+ throw new SchemaNotExistedException(databaseName);
}
List<MemoryQueryResultDataRow> rows = new LinkedList<>();
- rows.add(new MemoryQueryResultDataRow(Arrays.asList(schemaName, String.format(CREATE_DATABASE_PATTERN, schemaName))));
+ rows.add(new MemoryQueryResultDataRow(Arrays.asList(databaseName, String.format(CREATE_DATABASE_PATTERN, databaseName))));
return new RawMemoryQueryResult(queryResultMetaData, rows);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java
index 10d5077bada..613d23d9f5d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCurrentDatabaseExecutor.java
@@ -41,7 +41,7 @@ public final class ShowCurrentDatabaseExecutor implements DatabaseAdminQueryExec
@Override
public void execute(final ConnectionSession connectionSession) {
- mergedResult = new SingleLocalDataMergedResult(Collections.singleton(connectionSession.getSchemaName()));
+ mergedResult = new SingleLocalDataMergedResult(Collections.singleton(connectionSession.getDatabaseName()));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java
index 70143c236f3..31d3aa25cf2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowDatabasesExecutor.java
@@ -56,7 +56,7 @@ public final class ShowDatabasesExecutor implements DatabaseAdminQueryExecutor {
private Collection<Object> getSchemaNames(final ConnectionSession connectionSession) {
Collection<Object> result = new LinkedList<>();
- for (String each : ProxyContext.getInstance().getAllSchemaNames()) {
+ for (String each : ProxyContext.getInstance().getAllDatabaseNames()) {
if (checkLikePattern(each) && SQLCheckEngine.check(each, getRules(each), connectionSession.getGrantee())) {
result.add(each);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
index 19f1b9ae65c..eb4710efaa2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutor.java
@@ -63,15 +63,15 @@ public final class ShowTablesExecutor implements DatabaseAdminQueryExecutor {
@Override
public void execute(final ConnectionSession connectionSession) {
- queryResultMetaData = createQueryResultMetaData(connectionSession.getSchemaName());
- mergedResult = new TransparentMergedResult(getQueryResult(connectionSession.getSchemaName()));
+ queryResultMetaData = createQueryResultMetaData(connectionSession.getDatabaseName());
+ mergedResult = new TransparentMergedResult(getQueryResult(connectionSession.getDatabaseName()));
}
- private QueryResult getQueryResult(final String schemaName) {
- if (!databaseType.getSystemSchemas().contains(schemaName) && !ProxyContext.getInstance().getMetaData(schemaName).isComplete()) {
+ private QueryResult getQueryResult(final String databaseName) {
+ if (!databaseType.getSystemSchemas().contains(databaseName) && !ProxyContext.getInstance().getMetaData(databaseName).isComplete()) {
return new RawMemoryQueryResult(queryResultMetaData, Collections.emptyList());
}
- List<MemoryQueryResultDataRow> rows = getAllTableNames(schemaName).stream().map(each -> {
+ List<MemoryQueryResultDataRow> rows = getAllTableNames(databaseName).stream().map(each -> {
List<Object> rowValues = new LinkedList<>();
rowValues.add(each);
rowValues.add(TABLE_TYPE);
@@ -80,8 +80,8 @@ public final class ShowTablesExecutor implements DatabaseAdminQueryExecutor {
return new RawMemoryQueryResult(queryResultMetaData, rows);
}
- private Collection<String> getAllTableNames(final String schemaName) {
- Collection<String> result = ProxyContext.getInstance().getMetaData(schemaName).getDefaultSchema().getTables().values().stream().map(TableMetaData::getName).collect(Collectors.toList());
+ private Collection<String> getAllTableNames(final String databaseName) {
+ Collection<String> result = ProxyContext.getInstance().getMetaData(databaseName).getDefaultSchema().getTables().values().stream().map(TableMetaData::getName).collect(Collectors.toList());
if (showTablesStatement.getFilter().isPresent()) {
Optional<String> pattern = showTablesStatement.getFilter().get().getLike().map(each -> SQLUtil.convertLikePatternToRegex(each.getPattern()));
return pattern.isPresent() ? result.stream().filter(each -> RegularUtil.matchesCaseInsensitive(pattern.get(), each)).collect(Collectors.toList()) : result;
@@ -89,9 +89,9 @@ public final class ShowTablesExecutor implements DatabaseAdminQueryExecutor {
return result;
}
- private QueryResultMetaData createQueryResultMetaData(final String schemaName) {
+ private QueryResultMetaData createQueryResultMetaData(final String databaseName) {
List<RawQueryResultColumnMetaData> columnNames = new LinkedList<>();
- String tableColumnName = String.format("Tables_in_%s", schemaName);
+ String tableColumnName = String.format("Tables_in_%s", databaseName);
columnNames.add(new RawQueryResultColumnMetaData("", tableColumnName, tableColumnName, Types.VARCHAR, "VARCHAR", 255, 0));
columnNames.add(new RawQueryResultColumnMetaData("", "Table_type", "Table_type", Types.VARCHAR, "VARCHAR", 20, 0));
return new RawQueryResultMetaData(columnNames);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java
index 4bf5b162c44..74b36dfbeb7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutor.java
@@ -42,7 +42,7 @@ public final class ShowVersionExecutor implements DatabaseAdminQueryExecutor {
@Override
public void execute(final ConnectionSession connectionSession) {
- mergedResult = new SingleLocalDataMergedResult(Collections.singleton(MySQLServerInfo.getServerVersion(connectionSession.getSchemaName())));
+ mergedResult = new SingleLocalDataMergedResult(Collections.singleton(MySQLServerInfo.getServerVersion(connectionSession.getDatabaseName())));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java
index c4245c37819..c985ab7adce 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java
@@ -71,30 +71,30 @@ public final class UnicastResourceShowExecutor implements DatabaseAdminQueryExec
@Override
public void execute(final ConnectionSession connectionSession) throws SQLException {
- String originSchema = connectionSession.getSchemaName();
- String schemaName = null == originSchema ? getFirstSchemaName() : originSchema;
- if (!ProxyContext.getInstance().getMetaData(schemaName).hasDataSource()) {
+ String originDatabase = connectionSession.getDatabaseName();
+ String databaseName = null == originDatabase ? getFirstDatabaseName() : originDatabase;
+ if (!ProxyContext.getInstance().getMetaData(databaseName).hasDataSource()) {
throw new RuleNotExistedException();
}
try {
- connectionSession.setCurrentSchema(schemaName);
+ connectionSession.setCurrentDatabase(databaseName);
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(),
- sqlStatement, connectionSession.getDefaultSchemaName());
+ sqlStatement, connectionSession.getDefaultDatabaseName());
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection());
responseHeader = databaseCommunicationEngine.execute();
mergedResult = new TransparentMergedResult(createQueryResult());
} finally {
- connectionSession.setCurrentSchema(originSchema);
+ connectionSession.setCurrentDatabase(originDatabase);
databaseCommunicationEngine.close();
}
}
- private String getFirstSchemaName() {
- Collection<String> schemaNames = ProxyContext.getInstance().getAllSchemaNames();
- if (schemaNames.isEmpty()) {
+ private String getFirstDatabaseName() {
+ Collection<String> databaseNames = ProxyContext.getInstance().getAllDatabaseNames();
+ if (databaseNames.isEmpty()) {
throw new NoDatabaseSelectedException();
}
- Optional<String> result = schemaNames.stream().filter(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource()).findFirst();
+ Optional<String> result = databaseNames.stream().filter(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource()).findFirst();
if (!result.isPresent()) {
throw new RuleNotExistedException();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java
index 795cbdadeeb..5de754c6858 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutor.java
@@ -41,12 +41,12 @@ public final class UseDatabaseExecutor implements DatabaseAdminExecutor {
@Override
public void execute(final ConnectionSession connectionSession) {
- String schemaName = SQLUtil.getExactlyValue(useStatement.getSchema());
- if (ProxyContext.getInstance().schemaExists(schemaName) && SQLCheckEngine.check(schemaName, getRules(schemaName), connectionSession.getGrantee())) {
- connectionSession.setCurrentSchema(schemaName);
+ String databaseName = SQLUtil.getExactlyValue(useStatement.getSchema());
+ if (ProxyContext.getInstance().databaseExists(databaseName) && SQLCheckEngine.check(databaseName, getRules(databaseName), connectionSession.getGrantee())) {
+ connectionSession.setCurrentDatabase(databaseName);
return;
}
- throw new UnknownDatabaseException(schemaName);
+ throw new UnknownDatabaseException(databaseName);
}
private Collection<ShardingSphereRule> getRules(final String schemaName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java
index 5dbfe47f26e..b678cfb8233 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationSchemataExecutor.java
@@ -82,8 +82,8 @@ public final class SelectInformationSchemataExecutor extends DefaultDatabaseMeta
}
@Override
- protected List<String> getSchemaNames(final ConnectionSession connectionSession) {
- Collection<String> schemaNames = ProxyContext.getInstance().getAllSchemaNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee())).collect(Collectors.toList());
+ protected List<String> getDatabaseNames(final ConnectionSession connectionSession) {
+ Collection<String> schemaNames = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee())).collect(Collectors.toList());
SCHEMA_WITHOUT_DATA_SOURCE.addAll(schemaNames.stream().filter(each -> !AbstractDatabaseMetadataExecutor.hasDatasource(each)).collect(Collectors.toSet()));
List<String> result = schemaNames.stream().filter(AbstractDatabaseMetadataExecutor::hasDatasource).collect(Collectors.toList());
if (!SCHEMA_WITHOUT_DATA_SOURCE.isEmpty()) {
@@ -93,14 +93,14 @@ public final class SelectInformationSchemataExecutor extends DefaultDatabaseMeta
}
@Override
- protected void rowPostProcessing(final String schemaName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
- ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
+ protected void rowPostProcessing(final String databaseName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
+ ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource();
Set<String> catalogs = resource.getDataSources().keySet().stream().map(each -> resource.getDataSourcesMetaData().getDataSourceMetaData(each).getCatalog()).collect(Collectors.toSet());
schemaNameAlias = aliasMap.getOrDefault(SCHEMA_NAME, "");
String rowValue = rowMap.getOrDefault(schemaNameAlias, "").toString();
queryDatabase = !rowValue.isEmpty();
if (catalogs.contains(rowValue)) {
- rowMap.replace(schemaNameAlias, schemaName);
+ rowMap.replace(schemaNameAlias, databaseName);
} else {
rowMap.clear();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutor.java
index 1778d7a33b7..9d198d6667f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutor.java
@@ -73,10 +73,10 @@ public final class OpenGaussSelectDatabaseExecutor implements DatabaseAdminQuery
}
private OgCatalog constructOgCatalog() {
- Collection<String> allSchemaNames = ProxyContext.getInstance().getAllSchemaNames();
- OgDatabase[] ogDatabases = new OgDatabase[allSchemaNames.size()];
+ Collection<String> allDatabaseNames = ProxyContext.getInstance().getAllDatabaseNames();
+ OgDatabase[] ogDatabases = new OgDatabase[allDatabaseNames.size()];
int i = 0;
- for (String each : allSchemaNames) {
+ for (String each : allDatabaseNames) {
ogDatabases[i++] = new OgDatabase(each, DAT_COMPATIBILITY);
}
return new OgCatalog(ogDatabases);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java
index 47681f065ea..aa73eda69f7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutor.java
@@ -66,7 +66,7 @@ public final class SelectDatabaseExecutor extends DefaultDatabaseMetadataExecuto
}
private void addDefaultRow() {
- LinkedList<String> schemaWithoutDataSource = ProxyContext.getInstance().getAllSchemaNames().stream()
+ LinkedList<String> schemaWithoutDataSource = ProxyContext.getInstance().getAllDatabaseNames().stream()
.filter(each -> !hasDatasource(each)).collect(Collectors.toCollection(LinkedList::new));
schemaWithoutDataSource.forEach(each -> getRows().addLast(getDefaultRowData(each)));
}
@@ -80,21 +80,21 @@ public final class SelectDatabaseExecutor extends DefaultDatabaseMetadataExecuto
}
@Override
- protected List<String> getSchemaNames(final ConnectionSession connectionSession) {
- Collection<String> schemaNames = ProxyContext.getInstance().getAllSchemaNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee())).collect(Collectors.toList());
+ protected List<String> getDatabaseNames(final ConnectionSession connectionSession) {
+ Collection<String> schemaNames = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee())).collect(Collectors.toList());
return schemaNames.stream().filter(AbstractDatabaseMetadataExecutor::hasDatasource).collect(Collectors.toList());
}
@Override
- protected void rowPostProcessing(final String schemaName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
+ protected void rowPostProcessing(final String databaseName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
buildColumnNames(aliasMap);
- ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
+ ShardingSphereResource resource = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource();
Set<String> catalogs = resource.getDataSources().keySet().stream().map(each -> resource.getDataSourcesMetaData().getDataSourceMetaData(each).getCatalog()).collect(Collectors.toSet());
databaseNameAlias = aliasMap.getOrDefault(DATABASE_NAME, aliasMap.getOrDefault(DATNAME, aliasMap.getOrDefault(NAME, "")));
String rowValue = rowMap.getOrDefault(databaseNameAlias, "").toString();
isQueryDatabase = !rowValue.isEmpty();
if (catalogs.contains(rowValue)) {
- rowMap.replace(databaseNameAlias, schemaName);
+ rowMap.replace(databaseNameAlias, databaseName);
} else {
rowMap.clear();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java
index 98353739daf..38ca40f13d4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutor.java
@@ -51,18 +51,18 @@ public final class SelectTableExecutor extends DefaultDatabaseMetadataExecutor {
}
@Override
- protected void initSchemaData(final String schemaName) {
- tableNames = new ArrayList<>(ProxyContext.getInstance().getMetaData(schemaName).getDefaultSchema().getAllTableNames());
+ protected void initDatabaseData(final String databaseName) {
+ tableNames = new ArrayList<>(ProxyContext.getInstance().getMetaData(databaseName).getDefaultSchema().getAllTableNames());
}
@Override
- protected List<String> getSchemaNames(final ConnectionSession connectionSession) {
- Collection<String> schemaNames = ProxyContext.getInstance().getAllSchemaNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee())).collect(Collectors.toList());
+ protected List<String> getDatabaseNames(final ConnectionSession connectionSession) {
+ Collection<String> schemaNames = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(each -> hasAuthority(each, connectionSession.getGrantee())).collect(Collectors.toList());
return schemaNames.stream().filter(AbstractDatabaseMetadataExecutor::hasDatasource).collect(Collectors.toList());
}
@Override
- protected void rowPostProcessing(final String schemaName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
+ protected void rowPostProcessing(final String databaseName, final Map<String, Object> rowMap, final Map<String, String> aliasMap) {
if (actualTableName.isEmpty()) {
actualTableName = aliasMap.getOrDefault(REL_NAME, aliasMap.getOrDefault(TABLE_NAME, aliasMap.getOrDefault(NAME, aliasMap.getOrDefault(REF_NAME, ""))));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java
index 1732ace9bb5..789ef37dd6b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java
@@ -53,38 +53,38 @@ public final class BroadcastDatabaseBackendHandler implements DatabaseBackendHan
@SuppressWarnings("rawtypes")
@Override
public Future<ResponseHeader> executeFuture() {
- List<String> schemaNames = getSchemaNamesWithDataSource().orElseThrow(DatabaseNotExistedException::new);
- String originalSchema = connectionSession.getSchemaName();
- List<Future> futures = new ArrayList<>(schemaNames.size());
- for (String each : schemaNames) {
- connectionSession.setCurrentSchema(each);
+ List<String> databaseNames = getDatabaseNamesWithDataSource().orElseThrow(DatabaseNotExistedException::new);
+ String originalDatabase = connectionSession.getDatabaseName();
+ List<Future> futures = new ArrayList<>(databaseNames.size());
+ for (String each : databaseNames) {
+ connectionSession.setCurrentDatabase(each);
futures.add(databaseCommunicationEngineFactory.<VertxDatabaseCommunicationEngine>newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection()).execute());
}
return CompositeFuture.all(futures)
.compose(unused -> Future.succeededFuture((ResponseHeader) new UpdateResponseHeader(sqlStatementContext.getSqlStatement())))
.eventually(unused -> {
- connectionSession.setCurrentSchema(originalSchema);
+ connectionSession.setCurrentDatabase(originalDatabase);
return Future.succeededFuture();
});
}
@Override
public ResponseHeader execute() throws SQLException {
- List<String> schemaNames = getSchemaNamesWithDataSource().orElseThrow(DatabaseNotExistedException::new);
- String originalSchema = connectionSession.getSchemaName();
+ List<String> databaseNames = getDatabaseNamesWithDataSource().orElseThrow(DatabaseNotExistedException::new);
+ String originalDatabase = connectionSession.getDatabaseName();
try {
- for (String each : schemaNames) {
- connectionSession.setCurrentSchema(each);
+ for (String each : databaseNames) {
+ connectionSession.setCurrentDatabase(each);
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection()).execute();
}
} finally {
- connectionSession.setCurrentSchema(originalSchema);
+ connectionSession.setCurrentDatabase(originalDatabase);
}
return new UpdateResponseHeader(sqlStatementContext.getSqlStatement());
}
- private Optional<List<String>> getSchemaNamesWithDataSource() {
- List<String> result = ProxyContext.getInstance().getAllSchemaNames().stream().filter(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource()).collect(Collectors.toList());
+ private Optional<List<String>> getDatabaseNamesWithDataSource() {
+ List<String> result = ProxyContext.getInstance().getAllDatabaseNames().stream().filter(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource()).collect(Collectors.toList());
return Optional.of(result).filter(each -> !each.isEmpty());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
index 4614fe13222..6c075690f6b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
@@ -70,11 +70,11 @@ public final class SchemaAssignedDatabaseBackendHandler implements DatabaseBacke
private void prepareDatabaseCommunicationEngine() throws RequiredResourceMissedException {
boolean isSystemSchema = SystemSchemaUtil.containsSystemSchema(
- sqlStatementContext.getDatabaseType(), sqlStatementContext.getTablesContext().getSchemaNames(), connectionSession.getSchemaName());
- if (!isSystemSchema && !ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName()).hasDataSource()) {
- throw new RequiredResourceMissedException(connectionSession.getSchemaName());
+ sqlStatementContext.getDatabaseType(), sqlStatementContext.getTablesContext().getSchemaNames(), connectionSession.getDatabaseName());
+ if (!isSystemSchema && !ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()).hasDataSource()) {
+ throw new RequiredResourceMissedException(connectionSession.getDatabaseName());
}
- if (!isSystemSchema && !ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName()).isComplete()) {
+ if (!isSystemSchema && !ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName()).isComplete()) {
throw new RuleNotExistedException();
}
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
index 2cc351781f8..17135463a9f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
@@ -52,41 +52,41 @@ public final class UnicastDatabaseBackendHandler implements DatabaseBackendHandl
@Override
public Future<ResponseHeader> executeFuture() {
- String originSchema = connectionSession.getSchemaName();
- String schemaName = null == originSchema ? getFirstSchemaName() : originSchema;
- if (!ProxyContext.getInstance().getMetaData(schemaName).hasDataSource()) {
+ String originDatabase = connectionSession.getDatabaseName();
+ String databaseName = null == originDatabase ? getFirstDatabaseName() : originDatabase;
+ if (!ProxyContext.getInstance().getMetaData(databaseName).hasDataSource()) {
throw new RuleNotExistedException();
}
- connectionSession.setCurrentSchema(schemaName);
+ connectionSession.setCurrentDatabase(databaseName);
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection());
return ((Future<ResponseHeader>) databaseCommunicationEngine.execute()).eventually(unused -> {
- connectionSession.setCurrentSchema(originSchema);
+ connectionSession.setCurrentDatabase(databaseName);
return Future.succeededFuture();
});
}
@Override
public ResponseHeader execute() throws SQLException {
- String originSchema = connectionSession.getDefaultSchemaName();
- String schemaName = null == originSchema ? getFirstSchemaName() : originSchema;
- if (!ProxyContext.getInstance().getMetaData(schemaName).hasDataSource()) {
+ String originDatabase = connectionSession.getDefaultDatabaseName();
+ String databaseName = null == originDatabase ? getFirstDatabaseName() : originDatabase;
+ if (!ProxyContext.getInstance().getMetaData(databaseName).hasDataSource()) {
throw new RuleNotExistedException();
}
try {
- connectionSession.setCurrentSchema(schemaName);
+ connectionSession.setCurrentDatabase(databaseName);
databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection());
return (ResponseHeader) databaseCommunicationEngine.execute();
} finally {
- connectionSession.setCurrentSchema(originSchema);
+ connectionSession.setCurrentDatabase(databaseName);
}
}
- private String getFirstSchemaName() {
- Collection<String> schemaNames = ProxyContext.getInstance().getAllSchemaNames();
- if (schemaNames.isEmpty()) {
+ private String getFirstDatabaseName() {
+ Collection<String> databaseNames = ProxyContext.getInstance().getAllDatabaseNames();
+ if (databaseNames.isEmpty()) {
throw new NoDatabaseSelectedException();
}
- Optional<String> result = schemaNames.stream().filter(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource()).findFirst();
+ Optional<String> result = databaseNames.stream().filter(each -> ProxyContext.getInstance().getMetaData(each).hasDataSource()).findFirst();
if (!result.isPresent()) {
throw new RuleNotExistedException();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java
index 2ddface0fa2..54727b59bba 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java
@@ -38,12 +38,12 @@ public final class CreateDatabaseBackendHandler implements TextProtocolBackendHa
@Override
public ResponseHeader execute() throws SQLException {
check(sqlStatement);
- ProxyContext.getInstance().getContextManager().addSchema(sqlStatement.getDatabaseName());
+ ProxyContext.getInstance().getContextManager().addDatabase(sqlStatement.getDatabaseName());
return new UpdateResponseHeader(sqlStatement);
}
private void check(final CreateDatabaseStatement sqlStatement) {
- if (!sqlStatement.isContainsNotExistClause() && ProxyContext.getInstance().getAllSchemaNames().contains(sqlStatement.getDatabaseName())) {
+ if (!sqlStatement.isContainsNotExistClause() && ProxyContext.getInstance().getAllDatabaseNames().contains(sqlStatement.getDatabaseName())) {
throw new DBCreateExistsException(sqlStatement.getDatabaseName());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java
index 56058f300dd..e8068051f00 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandler.java
@@ -49,24 +49,24 @@ public final class DropDatabaseBackendHandler implements TextProtocolBackendHand
public ResponseHeader execute() {
check(sqlStatement, connectionSession.getGrantee());
if (isDropCurrentDatabase(sqlStatement.getDatabaseName())) {
- connectionSession.setCurrentSchema(null);
+ connectionSession.setCurrentDatabase(null);
}
- ProxyContext.getInstance().getContextManager().deleteSchema(sqlStatement.getDatabaseName());
+ ProxyContext.getInstance().getContextManager().deleteDatabase(sqlStatement.getDatabaseName());
return new UpdateResponseHeader(sqlStatement);
}
private void check(final DropDatabaseStatement sqlStatement, final Grantee grantee) {
- String schemaName = sqlStatement.getDatabaseName();
- if (!SQLCheckEngine.check(schemaName, getRules(schemaName), grantee)) {
- throw new UnknownDatabaseException(schemaName);
+ String databaseName = sqlStatement.getDatabaseName();
+ if (!SQLCheckEngine.check(databaseName, getRules(databaseName), grantee)) {
+ throw new UnknownDatabaseException(databaseName);
}
- if (!sqlStatement.isContainsExistClause() && !ProxyContext.getInstance().getAllSchemaNames().contains(schemaName)) {
- throw new DBDropNotExistsException(schemaName);
+ if (!sqlStatement.isContainsExistClause() && !ProxyContext.getInstance().getAllDatabaseNames().contains(databaseName)) {
+ throw new DBDropNotExistsException(databaseName);
}
}
private boolean isDropCurrentDatabase(final String databaseName) {
- return !Strings.isNullOrEmpty(connectionSession.getSchemaName()) && connectionSession.getSchemaName().equals(databaseName);
+ return !Strings.isNullOrEmpty(connectionSession.getDatabaseName()) && connectionSession.getDatabaseName().equals(databaseName);
}
private static Collection<ShardingSphereRule> getRules(final String schemaName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
index 91d4fc8295a..e30ceb276c1 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
@@ -58,7 +58,7 @@ public final class DistSQLBackendHandlerFactory {
return RQLBackendHandlerFactory.newInstance((RQLStatement) sqlStatement, connectionSession);
}
if (sqlStatement instanceof RDLStatement) {
- checkLockedSchema(connectionSession);
+ checkLockedDatabase(connectionSession);
return RDLBackendHandlerFactory.newInstance(databaseType, (RDLStatement) sqlStatement, connectionSession);
}
if (sqlStatement instanceof RALStatement) {
@@ -66,19 +66,19 @@ public final class DistSQLBackendHandlerFactory {
|| sqlStatement instanceof UpdatableScalingRALStatement) {
return RALBackendHandlerFactory.newInstance(databaseType, (RALStatement) sqlStatement, connectionSession);
}
- checkLockedSchema(connectionSession);
+ checkLockedDatabase(connectionSession);
return RALBackendHandlerFactory.newInstance(databaseType, (RALStatement) sqlStatement, connectionSession);
}
throw new UnsupportedOperationException(sqlStatement.getClass().getCanonicalName());
}
- private static void checkLockedSchema(final ConnectionSession connectionSession) {
- String schemaName = connectionSession.getSchemaName();
- if (null == schemaName) {
+ private static void checkLockedDatabase(final ConnectionSession connectionSession) {
+ String databaseName = connectionSession.getDatabaseName();
+ if (null == databaseName) {
return;
}
- if (ProxyContext.getInstance().getContextManager().getInstanceContext().getLockContext().isLockedSchema(schemaName)) {
- throw new SchemaLockedException(schemaName);
+ if (ProxyContext.getInstance().getContextManager().getInstanceContext().getLockContext().isLockedSchema(databaseName)) {
+ throw new SchemaLockedException(databaseName);
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java
index ba816a0aef3..f044a7c63af 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/ParseDistSQLBackendHandler.java
@@ -77,8 +77,8 @@ public final class ParseDistSQLBackendHandler extends QueryableRALBackendHandler
}
private static DatabaseType getBackendDatabaseType(final DatabaseType defaultDatabaseType, final ConnectionSession connectionSession) {
- String schemaName = connectionSession.getSchemaName();
- return Strings.isNullOrEmpty(schemaName) || !ProxyContext.getInstance().schemaExists(schemaName)
- ? defaultDatabaseType : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource().getDatabaseType();
+ String databaseName = connectionSession.getDatabaseName();
+ return Strings.isNullOrEmpty(databaseName) || !ProxyContext.getInstance().databaseExists(databaseName)
+ ? defaultDatabaseType : ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getResource().getDatabaseType();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java
index e5c355c49e7..c75e8624b60 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewDistSQLBackendHandler.java
@@ -99,24 +99,24 @@ public final class PreviewDistSQLBackendHandler extends QueryableRALBackendHandl
@Override
protected Collection<List<Object>> getRows(final ContextManager contextManager) throws SQLException {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- String schemaName = getSchemaName();
- String databaseType = DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType());
+ String databaseName = getDatabaseName();
+ String databaseType = DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType());
Optional<SQLParserRule> sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class);
Preconditions.checkState(sqlParserRule.isPresent());
SQLStatement previewedStatement = new ShardingSphereSQLParserEngine(databaseType, sqlParserRule.get().toParserConfiguration()).parse(sqlStatement.getSql(), false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), previewedStatement, schemaName);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), previewedStatement, databaseName);
// TODO optimize SQLStatementSchemaHolder
if (sqlStatementContext instanceof TableAvailable) {
((TableAvailable) sqlStatementContext).getTablesContext().getDatabaseName().ifPresent(SQLStatementSchemaHolder::set);
}
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName());
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName());
if (!metaData.isComplete()) {
throw new RuleNotExistedException();
}
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sqlStatement.getSql(), Collections.emptyList());
ExecutionContext executionContext = kernelProcessor.generateExecutionContext(logicSQL, metaData, metaDataContexts.getProps());
Collection<ExecutionUnit> executionUnits = executionContext.getRouteContext().isFederated()
- ? getFederationExecutionUnits(logicSQL, schemaName, metaDataContexts) : executionContext.getExecutionUnits();
+ ? getFederationExecutionUnits(logicSQL, databaseName, metaDataContexts) : executionContext.getExecutionUnits();
return executionUnits.stream().map(this::buildRow).collect(Collectors.toCollection(LinkedList::new));
}
@@ -129,7 +129,7 @@ public final class PreviewDistSQLBackendHandler extends QueryableRALBackendHandl
boolean isReturnGeneratedKeys = sqlStatement instanceof MySQLInsertStatement;
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = createDriverExecutionPrepareEngine(isReturnGeneratedKeys, metaDataContexts);
FederationContext context = new FederationContext(true, logicSQL, metaDataContexts.getMetaDataMap());
- DatabaseType databaseType = metaDataContexts.getMetaData(getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = metaDataContexts.getMetaData(getDatabaseName()).getResource().getDatabaseType();
FederationExecutor executor = FederationExecutorFactory.newInstance(schemaName, schemaName, metaDataContexts.getOptimizerContext(),
metaDataContexts.getProps(), new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), false));
executor.executeQuery(prepareEngine, createPreviewFederationCallback(sqlStatement, databaseType), context);
@@ -154,15 +154,15 @@ public final class PreviewDistSQLBackendHandler extends QueryableRALBackendHandl
private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriverExecutionPrepareEngine(final boolean isReturnGeneratedKeys, final MetaDataContexts metaData) {
int maxConnectionsSizePerQuery = metaData.getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, (JDBCBackendConnection) connectionSession.getBackendConnection(),
- (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(isReturnGeneratedKeys), metaData.getMetaData(getSchemaName()).getRuleMetaData().getRules());
+ (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(isReturnGeneratedKeys), metaData.getMetaData(getDatabaseName()).getRuleMetaData().getRules());
}
- private String getSchemaName() {
- String result = !Strings.isNullOrEmpty(connectionSession.getSchemaName()) ? connectionSession.getSchemaName() : connectionSession.getDefaultSchemaName();
+ private String getDatabaseName() {
+ String result = !Strings.isNullOrEmpty(connectionSession.getDatabaseName()) ? connectionSession.getDatabaseName() : connectionSession.getDefaultDatabaseName();
if (Strings.isNullOrEmpty(result)) {
throw new NoDatabaseSelectedException();
}
- if (!ProxyContext.getInstance().getAllSchemaNames().contains(result)) {
+ if (!ProxyContext.getInstance().getAllDatabaseNames().contains(result)) {
throw new SchemaNotExistedException(result);
}
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java
index 6987808ad4a..2c7a17ad444 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/executor/ShowShardingHintStatusExecutor.java
@@ -60,7 +60,7 @@ public final class ShowShardingHintStatusExecutor extends AbstractHintQueryExecu
@Override
protected MergedResult createMergedResult() {
Map<String, ShowShardingHintStatusResult> results = new HashMap<>();
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName());
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getDatabaseName());
if (!metaData.isComplete()) {
throw new RuleNotExistedException();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java
index 2fc0dadd91d..16f636fd6de 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesHandler.java
@@ -75,7 +75,7 @@ public final class CountInstanceRulesHandler extends QueryableRALBackendHandler<
@Override
protected Collection<List<Object>> getRows(final ContextManager contextManager) throws SQLException {
Map<String, List<Object>> dataMap = new LinkedHashMap<>();
- ProxyContext.getInstance().getAllSchemaNames().forEach(each ->
+ ProxyContext.getInstance().getAllDatabaseNames().forEach(each ->
addSchemaData(dataMap, ProxyContext.getInstance().getMetaData(each))
);
return dataMap.values();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandler.java
index 0ac2ca03226..71d65a7ec61 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandler.java
@@ -112,10 +112,10 @@ public final class ExportSchemaConfigurationHandler extends QueryableRALBackendH
@Override
protected Collection<List<Object>> getRows(final ContextManager contextManager) {
- String schemaName = getSchemaName();
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(schemaName);
+ String databaseName = getDatabaseName();
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(databaseName);
StringBuilder result = new StringBuilder();
- configItem(ZERO, "schemaName", schemaName, result);
+ configItem(ZERO, "databaseName", databaseName, result);
getDataSourcesConfig(metaData, result);
getRulesConfig(metaData.getRuleMetaData().getConfigurations(), result);
if (!sqlStatement.getFilePath().isPresent()) {
@@ -225,12 +225,12 @@ public final class ExportSchemaConfigurationHandler extends QueryableRALBackendH
return result.toString();
}
- private String getSchemaName() {
- String result = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getSchemaName();
+ private String getDatabaseName() {
+ String result = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getDatabaseName();
if (null == result) {
throw new NoDatabaseSelectedException();
}
- if (!ProxyContext.getInstance().getAllSchemaNames().contains(result)) {
+ if (!ProxyContext.getInstance().getAllDatabaseNames().contains(result)) {
throw new SchemaNotExistedException(result);
}
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
index 04ddfee0b7d..54ca8c5dfc6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowReadwriteSplittingReadResourcesHandler.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.queryabl
import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule;
import org.apache.shardingsphere.infra.storage.StorageNodeDataSource;
import org.apache.shardingsphere.infra.storage.StorageNodeStatus;
@@ -73,17 +73,17 @@ public final class ShowReadwriteSplittingReadResourcesHandler extends QueryableR
@Override
protected Collection<List<Object>> getRows(final ContextManager contextManager) {
- String schemaName = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getSchemaName();
- if (null == schemaName) {
+ String databaseName = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getDatabaseName();
+ if (null == databaseName) {
throw new NoDatabaseSelectedException();
}
- if (!ProxyContext.getInstance().getAllSchemaNames().contains(schemaName)) {
- throw new SchemaNotExistedException(schemaName);
+ if (!ProxyContext.getInstance().getAllDatabaseNames().contains(databaseName)) {
+ throw new SchemaNotExistedException(databaseName);
}
MetaDataContexts metaDataContexts = contextManager.getMetaDataContexts();
- ShardingSphereMetaData metaData = metaDataContexts.getMetaData(schemaName);
+ ShardingSphereMetaData metaData = metaDataContexts.getMetaData(databaseName);
Collection<String> allReadResources = getAllReadResources(metaData);
- Map<String, StorageNodeDataSource> persistentReadResources = getPersistentReadResources(schemaName, metaDataContexts.getMetaDataPersistService().orElse(null));
+ Map<String, StorageNodeDataSource> persistentReadResources = getPersistentReadResources(databaseName, metaDataContexts.getMetaDataPersistService().orElse(null));
return buildRows(allReadResources, persistentReadResources);
}
@@ -105,15 +105,15 @@ public final class ShowReadwriteSplittingReadResourcesHandler extends QueryableR
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v2, LinkedHashMap::new));
}
- private Map<String, StorageNodeDataSource> getPersistentReadResources(final String schemaName, final MetaDataPersistService persistService) {
+ private Map<String, StorageNodeDataSource> getPersistentReadResources(final String databaseName, final MetaDataPersistService persistService) {
if (null == persistService || null == persistService.getRepository() || !(persistService.getRepository() instanceof ClusterPersistRepository)) {
return Collections.emptyMap();
}
Map<String, StorageNodeDataSource> storageNodes = new StorageNodeStatusService((ClusterPersistRepository) persistService.getRepository()).loadStorageNodes();
Map<String, StorageNodeDataSource> result = new HashMap<>();
storageNodes.entrySet().stream().filter(entry -> "member".equalsIgnoreCase(entry.getValue().getRole())).forEach(entry -> {
- QualifiedSchema qualifiedSchema = new QualifiedSchema(entry.getKey());
- if (schemaName.equalsIgnoreCase(qualifiedSchema.getSchemaName())) {
+ QualifiedDatabase qualifiedSchema = new QualifiedDatabase(entry.getKey());
+ if (databaseName.equalsIgnoreCase(qualifiedSchema.getDatabaseName())) {
result.put(qualifiedSchema.getDataSourceName(), entry.getValue());
}
});
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java
index 9e4892710f7..55e615ccfd6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandler.java
@@ -61,30 +61,30 @@ public final class ShowTableMetadataHandler extends QueryableRALBackendHandler<S
@Override
protected Collection<List<Object>> getRows(final ContextManager contextManager) {
- String schemaName = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getSchemaName();
- if (null == schemaName) {
+ String databaseName = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getDatabaseName();
+ if (null == databaseName) {
throw new NoDatabaseSelectedException();
}
- if (!ProxyContext.getInstance().getAllSchemaNames().contains(schemaName)) {
- throw new SchemaNotExistedException(schemaName);
+ if (!ProxyContext.getInstance().getAllDatabaseNames().contains(databaseName)) {
+ throw new SchemaNotExistedException(databaseName);
}
- ShardingSphereSchema schema = ProxyContext.getInstance().getMetaData(schemaName).getDefaultSchema();
+ ShardingSphereSchema schema = ProxyContext.getInstance().getMetaData(databaseName).getDefaultSchema();
return schema.getAllTableNames().stream().filter(each -> sqlStatement.getTableNames().contains(each))
- .map(each -> buildTableRows(schemaName, schema, each)).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedList::new));
+ .map(each -> buildTableRows(databaseName, schema, each)).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedList::new));
}
- private Collection<List<Object>> buildTableRows(final String schemaName, final ShardingSphereSchema schema, final String tableName) {
+ private Collection<List<Object>> buildTableRows(final String databaseName, final ShardingSphereSchema schema, final String tableName) {
Collection<List<Object>> result = new LinkedList<>();
- Collection<List<Object>> columnRows = schema.getAllColumnNames(tableName).stream().map(each -> buildRow(schemaName, tableName, "COLUMN", each))
+ Collection<List<Object>> columnRows = schema.getAllColumnNames(tableName).stream().map(each -> buildRow(databaseName, tableName, "COLUMN", each))
.collect(Collectors.toCollection(LinkedList::new));
Collection<List<Object>> indexRows = schema.getTables().get(tableName).getIndexes().values().stream().map(each -> each.getName())
- .map(each -> buildRow(schemaName, tableName, "INDEX", each)).collect(Collectors.toCollection(LinkedList::new));
+ .map(each -> buildRow(databaseName, tableName, "INDEX", each)).collect(Collectors.toCollection(LinkedList::new));
result.addAll(columnRows);
result.addAll(indexRows);
return result;
}
- private List<Object> buildRow(final String schemaName, final String tableName, final String type, final String name) {
- return new ArrayList<>(Arrays.asList(schemaName, tableName, type, name));
+ private List<Object> buildRow(final String databaseName, final String tableName, final String type, final String name) {
+ return new ArrayList<>(Arrays.asList(databaseName, tableName, type, name));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandler.java
index 7c77b69f5e9..dca9c06aca3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandler.java
@@ -86,20 +86,20 @@ public final class ImportSchemaConfigurationHandler extends UpdatableRALBackendH
private final YamlProxyDataSourceConfigurationSwapper dataSourceConfigSwapper = new YamlProxyDataSourceConfigurationSwapper();
- private void alterResourcesConfig(final String schemaName, final Map<String, YamlProxyDataSourceConfiguration> yamlDataSourceMap) throws DistSQLException {
+ private void alterResourcesConfig(final String databaseName, final Map<String, YamlProxyDataSourceConfiguration> yamlDataSourceMap) throws DistSQLException {
Map<String, DataSourceProperties> toBeUpdatedResourcePropsMap = new LinkedHashMap<>(yamlDataSourceMap.size(), 1);
for (Entry<String, YamlProxyDataSourceConfiguration> each : yamlDataSourceMap.entrySet()) {
- DataSourceProperties dataSourceProps = DataSourcePropertiesCreator.create(HikariDataSource.class.getName(), dataSourceConfigSwapper.swap(each.getValue(), schemaName, each.getKey(),
+ DataSourceProperties dataSourceProps = DataSourcePropertiesCreator.create(HikariDataSource.class.getName(), dataSourceConfigSwapper.swap(each.getValue(), databaseName, each.getKey(),
false));
toBeUpdatedResourcePropsMap.put(each.getKey(), dataSourceProps);
}
try {
validator.validate(toBeUpdatedResourcePropsMap);
- Collection<String> currentResourceNames = new LinkedList<>(ProxyContext.getInstance().getMetaData(schemaName).getResource().getDataSources().keySet());
+ Collection<String> currentResourceNames = new LinkedList<>(ProxyContext.getInstance().getMetaData(databaseName).getResource().getDataSources().keySet());
Collection<String> toBeDroppedResourceNames = currentResourceNames.stream().filter(each -> !toBeUpdatedResourcePropsMap.containsKey(each)).collect(Collectors.toSet());
- ProxyContext.getInstance().getContextManager().addResource(schemaName, toBeUpdatedResourcePropsMap);
+ ProxyContext.getInstance().getContextManager().addResource(databaseName, toBeUpdatedResourcePropsMap);
if (toBeDroppedResourceNames.size() > 0) {
- ProxyContext.getInstance().getContextManager().dropResource(schemaName, toBeDroppedResourceNames);
+ ProxyContext.getInstance().getContextManager().dropResource(databaseName, toBeDroppedResourceNames);
}
} catch (final SQLException ex) {
throw new InvalidResourcesException(toBeUpdatedResourcePropsMap.keySet());
@@ -145,7 +145,7 @@ public final class ImportSchemaConfigurationHandler extends UpdatableRALBackendH
}
private void checkDatabaseName(final String databaseName) {
- if (!ProxyContext.getInstance().getAllSchemaNames().contains(databaseName)) {
+ if (!ProxyContext.getInstance().getAllDatabaseNames().contains(databaseName)) {
throw new SchemaNotExistedException(databaseName);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/RefreshTableMetadataHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/RefreshTableMetadataHandler.java
index 26312a7534d..a3f59b6b7cd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/RefreshTableMetadataHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/RefreshTableMetadataHandler.java
@@ -42,25 +42,25 @@ public final class RefreshTableMetadataHandler extends UpdatableRALBackendHandle
@Override
protected void update(final ContextManager contextManager, final RefreshTableMetadataStatement sqlStatement) throws DistSQLException {
- String schemaName = connectionSession.getSchemaName();
- checkSchema(schemaName);
+ String databaseName = connectionSession.getDatabaseName();
+ checkDatabase(databaseName);
if (sqlStatement.getResourceName().isPresent()) {
- contextManager.reloadMetaData(schemaName, sqlStatement.getTableName().get(), sqlStatement.getResourceName().get());
+ contextManager.reloadMetaData(databaseName, sqlStatement.getTableName().get(), sqlStatement.getResourceName().get());
return;
}
if (sqlStatement.getTableName().isPresent()) {
- contextManager.reloadMetaData(schemaName, sqlStatement.getTableName().get());
+ contextManager.reloadMetaData(databaseName, sqlStatement.getTableName().get());
return;
}
- contextManager.reloadMetaData(schemaName);
+ contextManager.reloadMetaData(databaseName);
}
- private void checkSchema(final String schemaName) {
- if (null == schemaName) {
+ private void checkDatabase(final String databaseName) {
+ if (null == databaseName) {
throw new NoDatabaseSelectedException();
}
- if (!ProxyContext.getInstance().schemaExists(schemaName)) {
- throw new UnknownDatabaseException(schemaName);
+ if (!ProxyContext.getInstance().databaseExists(databaseName)) {
+ throw new UnknownDatabaseException(databaseName);
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetReadwriteSplittingStatusHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetReadwriteSplittingStatusHandler.java
index 40c5b840aff..084efcc80e6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetReadwriteSplittingStatusHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetReadwriteSplittingStatusHandler.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
-import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
+import org.apache.shardingsphere.infra.metadata.schema.QualifiedDatabase;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
import org.apache.shardingsphere.infra.storage.StorageNodeDataSource;
import org.apache.shardingsphere.infra.storage.StorageNodeRole;
@@ -68,25 +68,25 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
@Override
protected void update(final ContextManager contextManager, final SetReadwriteSplittingStatusStatement sqlStatement) throws DistSQLException {
- String schemaName = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getSchemaName();
+ String databaseName = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getDatabaseName();
String toBeUpdatedResource = sqlStatement.getResourceName();
checkModeAndPersistRepository(contextManager);
- checkSchema(schemaName);
- checkReadwriteSplittingRule(contextManager, schemaName);
- Map<String, String> replicaResources = getReplicaResources(contextManager, schemaName);
- Map<String, String> disabledResources = getDisabledResources(contextManager, schemaName);
+ checkDatabase(databaseName);
+ checkReadwriteSplittingRule(contextManager, databaseName);
+ Map<String, String> replicaResources = getReplicaResources(contextManager, databaseName);
+ Map<String, String> disabledResources = getDisabledResources(contextManager, databaseName);
boolean isDisable = DISABLE.equals(sqlStatement.getStatus());
if (isDisable) {
- checkDisable(contextManager, schemaName, disabledResources.keySet(), toBeUpdatedResource, replicaResources);
+ checkDisable(contextManager, databaseName, disabledResources.keySet(), toBeUpdatedResource, replicaResources);
} else {
- checkEnable(contextManager, schemaName, disabledResources, toBeUpdatedResource);
+ checkEnable(contextManager, databaseName, disabledResources, toBeUpdatedResource);
}
Collection<String> groupNames = getGroupNames(toBeUpdatedResource, replicaResources, disabledResources);
- updateStatus(schemaName, groupNames, toBeUpdatedResource, isDisable);
+ updateStatus(databaseName, groupNames, toBeUpdatedResource, isDisable);
}
- private ReadwriteSplittingRuleConfiguration checkReadwriteSplittingRule(final ContextManager contextManager, final String schemaName) {
- Optional<ReadwriteSplittingRuleConfiguration> result = contextManager.getMetaDataContexts().getMetaData(schemaName)
+ private ReadwriteSplittingRuleConfiguration checkReadwriteSplittingRule(final ContextManager contextManager, final String databaseName) {
+ Optional<ReadwriteSplittingRuleConfiguration> result = contextManager.getMetaDataContexts().getMetaData(databaseName)
.getRuleMetaData().findRuleConfiguration(ReadwriteSplittingRuleConfiguration.class).stream().findAny();
if (!result.isPresent()) {
throw new UnsupportedOperationException("The current schema has no read_write splitting rules");
@@ -103,41 +103,41 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
}
}
- private void checkSchema(final String schemaName) {
- if (null == schemaName) {
+ private void checkDatabase(final String databaseName) {
+ if (null == databaseName) {
throw new NoDatabaseSelectedException();
}
- if (!ProxyContext.getInstance().getAllSchemaNames().contains(schemaName)) {
- throw new SchemaNotExistedException(schemaName);
+ if (!ProxyContext.getInstance().getAllDatabaseNames().contains(databaseName)) {
+ throw new SchemaNotExistedException(databaseName);
}
}
- private Map<String, String> getReplicaResources(final ContextManager contextManager, final String schemaName) {
- Map<String, Map<String, String>> readwriteSplittingRules = getExportedReadwriteSplittingRules(contextManager, schemaName);
+ private Map<String, String> getReplicaResources(final ContextManager contextManager, final String databaseName) {
+ Map<String, Map<String, String>> readwriteSplittingRules = getExportedReadwriteSplittingRules(contextManager, databaseName);
Map<String, String> result = new HashMap<>();
readwriteSplittingRules.entrySet().stream().filter(entry -> !entry.getValue().isEmpty()).forEach(entry -> addReplicaResource(result, entry));
return result;
}
- private Map<String, String> getDisabledResources(final ContextManager contextManager, final String schemaName) {
+ private Map<String, String> getDisabledResources(final ContextManager contextManager, final String databaseName) {
Optional<MetaDataPersistService> persistService = contextManager.getMetaDataContexts().getMetaDataPersistService();
Map<String, String> result = new HashMap<>();
persistService.ifPresent(op -> {
- Map<String, String> disableNodes = getDisabledStorageNodes(schemaName, op).stream()
- .collect(Collectors.toMap(QualifiedSchema::getDataSourceName, QualifiedSchema::getGroupName, (value1, value2) -> String.join(",", value1, value2)));
+ Map<String, String> disableNodes = getDisabledStorageNodes(databaseName, op).stream()
+ .collect(Collectors.toMap(QualifiedDatabase::getDataSourceName, QualifiedDatabase::getGroupName, (value1, value2) -> String.join(",", value1, value2)));
result.putAll(disableNodes);
});
return result;
}
- private void checkEnable(final ContextManager contextManager, final String schemaName, final Map<String, String> disabledResources, final String toBeEnabledResource) throws DistSQLException {
- checkResourceExists(contextManager, schemaName, toBeEnabledResource);
+ private void checkEnable(final ContextManager contextManager, final String databaseName, final Map<String, String> disabledResources, final String toBeEnabledResource) throws DistSQLException {
+ checkResourceExists(contextManager, databaseName, toBeEnabledResource);
checkIsNotDisabled(disabledResources.keySet(), toBeEnabledResource);
}
- private void checkResourceExists(final ContextManager contextManager, final String schemaName, final String toBeDisabledResource) throws DistSQLException {
- Collection<String> notExistedResources = contextManager.getMetaDataContexts().getMetaData(schemaName).getResource().getNotExistedResources(Collections.singleton(toBeDisabledResource));
- DistSQLException.predictionThrow(notExistedResources.isEmpty(), () -> new RequiredResourceMissedException(schemaName, Collections.singleton(toBeDisabledResource)));
+ private void checkResourceExists(final ContextManager contextManager, final String databaseName, final String toBeDisabledResource) throws DistSQLException {
+ Collection<String> notExistedResources = contextManager.getMetaDataContexts().getMetaData(databaseName).getResource().getNotExistedResources(Collections.singleton(toBeDisabledResource));
+ DistSQLException.predictionThrow(notExistedResources.isEmpty(), () -> new RequiredResourceMissedException(databaseName, Collections.singleton(toBeDisabledResource)));
}
private void checkIsNotDisabled(final Collection<String> disabledResources, final String toBeEnabledResource) {
@@ -146,9 +146,9 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
}
}
- private void checkDisable(final ContextManager contextManager, final String schemaName, final Collection<String> disabledResources, final String toBeDisabledResource,
+ private void checkDisable(final ContextManager contextManager, final String databaseName, final Collection<String> disabledResources, final String toBeDisabledResource,
final Map<String, String> replicaResources) throws DistSQLException {
- checkResourceExists(contextManager, schemaName, toBeDisabledResource);
+ checkResourceExists(contextManager, databaseName, toBeDisabledResource);
checkIsDisabled(replicaResources, disabledResources, toBeDisabledResource);
checkIsReplicaResource(replicaResources, toBeDisabledResource);
checkIsLastResource(replicaResources, toBeDisabledResource);
@@ -181,23 +181,23 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
return Splitter.on(",").splitToList(groupNames);
}
- private void updateStatus(final String schemaName, final Collection<String> groupNames, final String toBeDisableResource, final boolean isDisable) {
+ private void updateStatus(final String databaseName, final Collection<String> groupNames, final String toBeDisableResource, final boolean isDisable) {
groupNames.forEach(each -> {
StorageNodeDataSource storageNodeDataSource = new StorageNodeDataSource(StorageNodeRole.MEMBER, isDisable ? StorageNodeStatus.DISABLED : StorageNodeStatus.ENABLED);
- ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(schemaName, each, toBeDisableResource, storageNodeDataSource));
+ ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(databaseName, each, toBeDisableResource, storageNodeDataSource));
});
}
- private Collection<QualifiedSchema> getDisabledStorageNodes(final String schemaName, final MetaDataPersistService persistService) {
+ private Collection<QualifiedDatabase> getDisabledStorageNodes(final String databaseName, final MetaDataPersistService persistService) {
Map<String, StorageNodeDataSource> storageNodes = new StorageNodeStatusService((ClusterPersistRepository) persistService.getRepository()).loadStorageNodes();
return storageNodes.entrySet().stream().filter(each -> StorageNodeStatus.DISABLED.name().equalsIgnoreCase(each.getValue().getStatus()))
- .map(each -> new QualifiedSchema(each.getKey())).filter(each -> schemaName.equalsIgnoreCase(each.getSchemaName()))
+ .map(each -> new QualifiedDatabase(each.getKey())).filter(each -> databaseName.equalsIgnoreCase(each.getDatabaseName()))
.collect(Collectors.toList());
}
- private Map<String, Map<String, String>> getExportedReadwriteSplittingRules(final ContextManager contextManager, final String schemaName) {
+ private Map<String, Map<String, String>> getExportedReadwriteSplittingRules(final ContextManager contextManager, final String databaseName) {
Map<String, Map<String, String>> result = new HashMap<>();
- contextManager.getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().findRules(ReadwriteSplittingRule.class).stream().findAny()
+ contextManager.getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().findRules(ReadwriteSplittingRule.class).stream().findAny()
.filter(each -> each.containExportableKey(Arrays.asList(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE, ExportableConstants.EXPORTABLE_KEY_ENABLED_DATA_SOURCE)))
.map(each -> each.export(Arrays.asList(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE, ExportableConstants.EXPORTABLE_KEY_ENABLED_DATA_SOURCE)))
.ifPresent(each -> {
@@ -208,7 +208,7 @@ public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBacken
}
private Collection<String> getOnlyOneResourceRules(final Map<String, String> replicaResources) {
- return replicaResources.values().stream().map(schemaName -> Arrays.stream(schemaName.split(",")).collect(Collectors.toMap(each -> each, each -> 1)).entrySet())
+ return replicaResources.values().stream().map(databaseName -> Arrays.stream(databaseName.split(",")).collect(Collectors.toMap(each -> each, each -> 1)).entrySet())
.flatMap(Collection::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Integer::sum)).entrySet().stream()
.filter(entry -> entry.getValue() <= 1).map(Entry::getKey).collect(Collectors.toSet());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
index 794aedc7c02..0857f7304ec 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
@@ -55,12 +55,12 @@ public final class AddResourceBackendHandler extends SchemaRequiredBackendHandle
}
@Override
- public ResponseHeader execute(final String schemaName, final AddResourceStatement sqlStatement) throws DistSQLException {
- checkSQLStatement(schemaName, sqlStatement);
+ public ResponseHeader execute(final String databaseName, final AddResourceStatement sqlStatement) throws DistSQLException {
+ checkSQLStatement(databaseName, sqlStatement);
Map<String, DataSourceProperties> dataSourcePropsMap = ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources());
validator.validate(dataSourcePropsMap);
try {
- ProxyContext.getInstance().getContextManager().addResource(schemaName, dataSourcePropsMap);
+ ProxyContext.getInstance().getContextManager().addResource(databaseName, dataSourcePropsMap);
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
@@ -70,11 +70,11 @@ public final class AddResourceBackendHandler extends SchemaRequiredBackendHandle
return new UpdateResponseHeader(sqlStatement);
}
- private void checkSQLStatement(final String schemaName, final AddResourceStatement sqlStatement) throws DistSQLException {
+ private void checkSQLStatement(final String databaseName, final AddResourceStatement sqlStatement) throws DistSQLException {
Collection<String> dataSourceNames = new ArrayList<>(sqlStatement.getDataSources().size());
Collection<String> duplicateDataSourceNames = new HashSet<>(sqlStatement.getDataSources().size(), 1);
for (DataSourceSegment each : sqlStatement.getDataSources()) {
- if (dataSourceNames.contains(each.getName()) || ProxyContext.getInstance().getMetaData(schemaName).getResource().getDataSources().containsKey(each.getName())) {
+ if (dataSourceNames.contains(each.getName()) || ProxyContext.getInstance().getMetaData(databaseName).getResource().getDataSources().containsKey(each.getName())) {
duplicateDataSourceNames.add(each.getName());
}
dataSourceNames.add(each.getName());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
index a56840a5c95..749f02148e6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
@@ -60,12 +60,12 @@ public final class AlterResourceBackendHandler extends SchemaRequiredBackendHand
}
@Override
- public ResponseHeader execute(final String schemaName, final AlterResourceStatement sqlStatement) throws DistSQLException {
- checkSQLStatement(schemaName, sqlStatement);
+ public ResponseHeader execute(final String databaseName, final AlterResourceStatement sqlStatement) throws DistSQLException {
+ checkSQLStatement(databaseName, sqlStatement);
Map<String, DataSourceProperties> dataSourcePropsMap = ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources());
validator.validate(dataSourcePropsMap);
try {
- ProxyContext.getInstance().getContextManager().alterResource(schemaName, dataSourcePropsMap);
+ ProxyContext.getInstance().getContextManager().alterResource(databaseName, dataSourcePropsMap);
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
index f07f281b90e..6c117909340 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
@@ -149,7 +149,7 @@ public final class RuleDefinitionBackendHandler<T extends RuleDefinitionStatemen
final RuleDefinitionAlterPreprocessor preprocessor) {
Optional<MetaDataPersistService> metaDataPersistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService();
if (metaDataPersistService.isPresent()) {
- Optional<String> newVersion = metaDataPersistService.get().getSchemaVersionPersistService().createNewVersion(shardingSphereMetaData.getName());
+ Optional<String> newVersion = metaDataPersistService.get().getDatabaseVersionPersistService().createNewVersion(shardingSphereMetaData.getName());
if (!newVersion.isPresent()) {
throw new RuntimeException(String.format("Unable to get a new version for schema: %s", shardingSphereMetaData.getName()));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
index 2a29cf82461..663074e520e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
@@ -60,13 +60,13 @@ public final class DatabaseCommunicationEngineFactoryTest {
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
- return Collections.singletonMap("schema", result);
+ return Collections.singletonMap("db", result);
}
@Test
public void assertNewTextProtocolInstance() {
JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class, RETURNS_DEEP_STUBS);
- when(backendConnection.getConnectionSession().getSchemaName()).thenReturn("schema");
+ when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("db");
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
DatabaseCommunicationEngine engine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext, "schemaName", backendConnection);
@@ -76,7 +76,7 @@ public final class DatabaseCommunicationEngineFactoryTest {
@Test
public void assertNewBinaryProtocolInstance() {
JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class, RETURNS_DEEP_STUBS);
- when(backendConnection.getConnectionSession().getSchemaName()).thenReturn("schema");
+ when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("db");
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
DatabaseCommunicationEngine engine
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
index 7a68ce83e03..f3e67261472 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
@@ -92,7 +92,7 @@ public final class JDBCDatabaseCommunicationEngineTest {
@Before
public void setUp() {
- when(backendConnection.getConnectionSession().getSchemaName()).thenReturn("schema");
+ when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("db");
MetaDataContexts metaDataContexts = new MetaDataContexts(
mock(MetaDataPersistService.class), mockMetaDataMap(), mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class),
mock(OptimizerContext.class, RETURNS_DEEP_STUBS), new ConfigurationProperties(new Properties()));
@@ -105,7 +105,7 @@ public final class JDBCDatabaseCommunicationEngineTest {
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
when(result.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
- return Collections.singletonMap("schema", result);
+ return Collections.singletonMap("db", result);
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
index 53794f31133..90a0adee4f4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
@@ -92,12 +92,12 @@ public final class JDBCBackendConnectionTest {
public void setUp() throws ReflectiveOperationException {
setContextManager();
setBackendDataSource();
- when(connectionSession.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(connectionSession.getDatabaseName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
backendConnection = spy(new JDBCBackendConnection(connectionSession));
when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
when(connectionSession.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.LOCAL));
JDBCBackendStatement backendStatement = new JDBCBackendStatement();
- backendStatement.setSchemaName(connectionSession.getSchemaName());
+ backendStatement.setSchemaName(connectionSession.getDatabaseName());
when(connectionSession.getStatementManager()).thenReturn(backendStatement);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManagerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManagerTest.java
index 65c3df3e81a..937e482999e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManagerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManagerTest.java
@@ -65,7 +65,7 @@ public final class JDBCBackendTransactionManagerTest {
@Before
public void setUp() {
setTransactionContexts();
- when(connectionSession.getSchemaName()).thenReturn("schema");
+ when(connectionSession.getDatabaseName()).thenReturn("db");
when(connectionSession.getTransactionStatus()).thenReturn(transactionStatus);
when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
}
@@ -83,7 +83,7 @@ public final class JDBCBackendTransactionManagerTest {
private TransactionContexts mockTransactionContexts() {
TransactionContexts result = mock(TransactionContexts.class, RETURNS_DEEP_STUBS);
ShardingSphereTransactionManagerEngine transactionManagerEngine = mock(ShardingSphereTransactionManagerEngine.class);
- when(result.getEngines().get("schema")).thenReturn(transactionManagerEngine);
+ when(result.getEngines().get("db")).thenReturn(transactionManagerEngine);
when(transactionManagerEngine.getTransactionManager(TransactionType.XA)).thenReturn(shardingSphereTransactionManager);
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
index 9cffda8544e..cc5971abb70 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
@@ -48,7 +48,7 @@ import static org.mockito.Mockito.when;
public final class ProxyContextTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String SCHEMA_PATTERN = "db_%s";
@Test
public void assertInit() {
@@ -65,7 +65,7 @@ public final class ProxyContextTest {
}
@Test
- public void assertSchemaExists() throws NoSuchFieldException, IllegalAccessException {
+ public void assertDatabaseExists() throws NoSuchFieldException, IllegalAccessException {
Map<String, ShardingSphereMetaData> metaDataMap = mockMetaDataMap();
Field contextManagerField = ProxyContext.getInstance().getClass().getDeclaredField("contextManager");
contextManagerField.setAccessible(true);
@@ -74,22 +74,22 @@ public final class ProxyContextTest {
metaDataMap, mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- assertTrue(ProxyContext.getInstance().schemaExists("schema"));
- assertFalse(ProxyContext.getInstance().schemaExists("schema_2"));
+ assertTrue(ProxyContext.getInstance().databaseExists("db"));
+ assertFalse(ProxyContext.getInstance().databaseExists("db_1"));
}
@Test(expected = NoDatabaseSelectedException.class)
- public void assertGetSchemaWithNull() {
+ public void assertGetDatabaseWithNull() {
assertNull(ProxyContext.getInstance().getMetaData(null));
}
@Test(expected = NoDatabaseSelectedException.class)
- public void assertGetSchemaWithEmptyString() {
+ public void assertGetDatabaseWithEmptyString() {
assertNull(ProxyContext.getInstance().getMetaData(""));
}
@Test(expected = NoDatabaseSelectedException.class)
- public void assertGetSchemaWhenNotExisted() throws NoSuchFieldException, IllegalAccessException {
+ public void assertGetDatabaseWhenNotExisted() throws NoSuchFieldException, IllegalAccessException {
Map<String, ShardingSphereMetaData> metaDataMap = mockMetaDataMap();
Field contextManagerField = ProxyContext.getInstance().getClass().getDeclaredField("contextManager");
contextManagerField.setAccessible(true);
@@ -98,11 +98,11 @@ public final class ProxyContextTest {
metaDataMap, mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- ProxyContext.getInstance().getMetaData("schema1");
+ ProxyContext.getInstance().getMetaData("db1");
}
@Test
- public void assertGetSchema() throws NoSuchFieldException, IllegalAccessException {
+ public void assertGetDatabase() throws NoSuchFieldException, IllegalAccessException {
Map<String, ShardingSphereMetaData> metaDataMap = mockMetaDataMap();
Field contextManagerField = ProxyContext.getInstance().getClass().getDeclaredField("contextManager");
contextManagerField.setAccessible(true);
@@ -111,11 +111,11 @@ public final class ProxyContextTest {
metaDataMap, mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- assertThat(metaDataMap.get("schema"), is(ProxyContext.getInstance().getMetaData("schema")));
+ assertThat(metaDataMap.get("db"), is(ProxyContext.getInstance().getMetaData("db")));
}
@Test
- public void assertGetAllSchemaNames() throws NoSuchFieldException, IllegalAccessException {
+ public void assertGetAllDatabaseNames() throws NoSuchFieldException, IllegalAccessException {
Map<String, ShardingSphereMetaData> metaDataMap = createMetaDataMap();
Field contextManagerField = ProxyContext.getInstance().getClass().getDeclaredField("contextManager");
contextManagerField.setAccessible(true);
@@ -124,7 +124,7 @@ public final class ProxyContextTest {
metaDataMap, mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- assertThat(new LinkedHashSet<>(ProxyContext.getInstance().getAllSchemaNames()), is(metaDataMap.keySet()));
+ assertThat(new LinkedHashSet<>(ProxyContext.getInstance().getAllDatabaseNames()), is(metaDataMap.keySet()));
}
private Map<String, ShardingSphereMetaData> createMetaDataMap() {
@@ -138,6 +138,6 @@ public final class ProxyContextTest {
private Map<String, ShardingSphereMetaData> mockMetaDataMap() {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
- return Collections.singletonMap("schema", metaData);
+ return Collections.singletonMap("db", metaData);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
index ffa16f773d9..0bc38d18343 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
@@ -69,13 +69,13 @@ public final class ConnectionSessionTest {
@Test
public void assertSetCurrentSchema() {
- connectionSession.setCurrentSchema("currentSchema");
- assertThat(connectionSession.getSchemaName(), is("currentSchema"));
+ connectionSession.setCurrentDatabase("currentDatabase");
+ assertThat(connectionSession.getDatabaseName(), is("currentDatabase"));
}
@Test(expected = ShardingSphereException.class)
public void assertFailedSwitchTransactionTypeWhileBegin() throws SQLException {
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(backendConnection);
transactionManager.begin();
connectionSession.getTransactionStatus().setTransactionType(TransactionType.XA);
@@ -83,10 +83,10 @@ public final class ConnectionSessionTest {
@Test(expected = ShardingSphereException.class)
public void assertFailedSwitchSchemaWhileBegin() throws SQLException {
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
JDBCBackendTransactionManager transactionManager = new JDBCBackendTransactionManager(backendConnection);
transactionManager.begin();
- connectionSession.setCurrentSchema("newSchema");
+ connectionSession.setCurrentDatabase("newDB");
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
index dcb25457db0..6a8ddf133c7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
@@ -77,14 +77,14 @@ public final class TextProtocolBackendHandlerFactoryTest {
@Before
public void setUp() {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
- when(connectionSession.getDefaultSchemaName()).thenReturn("schema");
+ when(connectionSession.getDefaultDatabaseName()).thenReturn("db");
when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
mockGlobalRuleMetaData(metaDataContexts);
ShardingSphereMetaData shardingSphereMetaData = mockShardingSphereMetaData();
- when(metaDataContexts.getAllSchemaNames().contains("schema")).thenReturn(true);
- when(metaDataContexts.getMetaDataMap().get("schema")).thenReturn(shardingSphereMetaData);
+ when(metaDataContexts.getAllDatabaseNames().contains("db")).thenReturn(true);
+ when(metaDataContexts.getMetaDataMap().get("db")).thenReturn(shardingSphereMetaData);
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
when(metaDataContexts.getProps()).thenReturn(new ConfigurationProperties(new Properties()));
@@ -190,7 +190,7 @@ public final class TextProtocolBackendHandlerFactoryTest {
public void assertNewInstanceWithSet() throws SQLException {
String sql = "set @num=1";
ProxyContext instance = ProxyContext.getInstance();
- when(instance.getAllSchemaNames()).thenReturn(Collections.singletonList("schema"));
+ when(instance.getAllDatabaseNames()).thenReturn(Collections.singletonList("schema"));
when(instance.getMetaData("schema").hasDataSource()).thenReturn(true);
TextProtocolBackendHandler actual = TextProtocolBackendHandlerFactory.newInstance(databaseType, sql, Optional::empty, connectionSession);
assertThat(actual, instanceOf(BroadcastDatabaseBackendHandler.class));
@@ -223,8 +223,8 @@ public final class TextProtocolBackendHandlerFactoryTest {
public void assertNewInstanceWithQuery() throws SQLException {
String sql = "select * from t_order limit 1";
ProxyContext instance = ProxyContext.getInstance();
- when(instance.getAllSchemaNames()).thenReturn(Collections.singletonList("schema"));
- when(instance.getMetaData("schema").hasDataSource()).thenReturn(true);
+ when(instance.getAllDatabaseNames()).thenReturn(Collections.singletonList("db"));
+ when(instance.getMetaData("db").hasDataSource()).thenReturn(true);
TextProtocolBackendHandler actual = TextProtocolBackendHandlerFactory.newInstance(databaseType, sql, Optional::empty, connectionSession);
assertThat(actual, instanceOf(SchemaAssignedDatabaseBackendHandler.class));
sql = "select * from information_schema.schemata limit 1";
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java
index 470eff057b7..683c7a7fa7f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java
@@ -74,7 +74,7 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
- when(connectionSession.getSchemaName()).thenReturn("schema");
+ when(connectionSession.getDatabaseName()).thenReturn("db");
when(metaDataContexts.getGlobalRuleMetaData().getRules()).thenReturn(Collections.emptyList());
}
@@ -106,7 +106,7 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
}
private void assertExecuteDropDatabaseContext(final DropDatabaseStatement sqlStatement) throws SQLException {
- sqlStatement.setDatabaseName("schema");
+ sqlStatement.setDatabaseName("db");
setGovernanceMetaDataContexts(true);
ResponseHeader response = DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
@@ -123,7 +123,7 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
}
public void assertExecuteCreateDatabaseContextWithException(final CreateDatabaseStatement sqlStatement) throws SQLException {
- sqlStatement.setDatabaseName("schema");
+ sqlStatement.setDatabaseName("db");
setGovernanceMetaDataContexts(true);
try {
DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connectionSession);
@@ -136,7 +136,7 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
- return Collections.singletonMap("schema", metaData);
+ return Collections.singletonMap("db", metaData);
}
private void setGovernanceMetaDataContexts(final boolean isGovernance) {
@@ -147,8 +147,8 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
private MetaDataContexts mockMetaDataContexts() {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- when(metaDataContexts.getMetaData("schema").getResource().getDataSources()).thenReturn(Collections.emptyMap());
- when(metaDataContexts.getMetaData("schema").getResource().getNotExistedResources(any())).thenReturn(Collections.emptyList());
+ when(metaDataContexts.getMetaData("db").getResource().getDataSources()).thenReturn(Collections.emptyMap());
+ when(metaDataContexts.getMetaData("db").getResource().getNotExistedResources(any())).thenReturn(Collections.emptyList());
return metaDataContexts;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java
index 1d181c75144..f4ceb07db95 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowCreateDatabaseExecutorTest.java
@@ -47,7 +47,7 @@ import static org.mockito.Mockito.when;
public final class ShowCreateDatabaseExecutorTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
@@ -66,7 +66,7 @@ public final class ShowCreateDatabaseExecutorTest {
for (int i = 0; i < 10; i++) {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
@@ -74,13 +74,13 @@ public final class ShowCreateDatabaseExecutorTest {
@Test
public void assertExecute() throws SQLException {
MySQLShowCreateDatabaseStatement statement = new MySQLShowCreateDatabaseStatement();
- statement.setSchemaName("schema_0");
+ statement.setSchemaName("db_0");
ShowCreateDatabaseExecutor showCreateDatabaseExecutor = new ShowCreateDatabaseExecutor(statement);
showCreateDatabaseExecutor.execute(mockConnectionSession());
assertThat(showCreateDatabaseExecutor.getQueryResultMetaData().getColumnCount(), is(2));
int count = 0;
while (showCreateDatabaseExecutor.getMergedResult().next()) {
- assertThat(showCreateDatabaseExecutor.getMergedResult().getValue(1, Object.class), is(String.format(SCHEMA_PATTERN, count)));
+ assertThat(showCreateDatabaseExecutor.getMergedResult().getValue(1, Object.class), is(String.format(DATABASE_PATTERN, count)));
count++;
}
}
@@ -88,7 +88,7 @@ public final class ShowCreateDatabaseExecutorTest {
private ConnectionSession mockConnectionSession() {
ConnectionSession result = mock(ConnectionSession.class);
when(result.getGrantee()).thenReturn(new Grantee("root", ""));
- when(result.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(result.getDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
return result;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowFunctionStatusExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowFunctionStatusExecutorTest.java
index aac0ffd261e..f2f92463e6c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowFunctionStatusExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowFunctionStatusExecutorTest.java
@@ -47,7 +47,7 @@ import static org.mockito.Mockito.when;
public final class ShowFunctionStatusExecutorTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
private ShowFunctionStatusExecutor showFunctionStatusExecutor;
@@ -70,7 +70,7 @@ public final class ShowFunctionStatusExecutorTest {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.isComplete()).thenReturn(false);
when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
@@ -84,7 +84,7 @@ public final class ShowFunctionStatusExecutorTest {
private ConnectionSession mockConnectionSession() {
ConnectionSession result = mock(ConnectionSession.class);
when(result.getGrantee()).thenReturn(new Grantee("root", ""));
- when(result.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(result.getDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
return result;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcedureStatusExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcedureStatusExecutorTest.java
index 08b05538c36..ce5d996fe91 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcedureStatusExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcedureStatusExecutorTest.java
@@ -47,7 +47,7 @@ import static org.mockito.Mockito.when;
public final class ShowProcedureStatusExecutorTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
private ShowProcedureStatusExecutor showProcedureStatusExecutor;
@@ -70,7 +70,7 @@ public final class ShowProcedureStatusExecutorTest {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.isComplete()).thenReturn(false);
when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
@@ -84,7 +84,7 @@ public final class ShowProcedureStatusExecutorTest {
private ConnectionSession mockConnectionSession() {
ConnectionSession result = mock(ConnectionSession.class);
when(result.getGrantee()).thenReturn(new Grantee("root", ""));
- when(result.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(result.getDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
return result;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
index 2a4d1de4362..a92d1320985 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowTablesExecutorTest.java
@@ -55,7 +55,7 @@ import static org.mockito.Mockito.when;
public final class ShowTablesExecutorTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
@@ -80,7 +80,7 @@ public final class ShowTablesExecutorTest {
when(metaData.getDefaultSchema()).thenReturn(schema);
when(metaData.isComplete()).thenReturn(true);
when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
- return Collections.singletonMap(String.format(SCHEMA_PATTERN, 0), metaData);
+ return Collections.singletonMap(String.format(DATABASE_PATTERN, 0), metaData);
}
@Test
@@ -162,7 +162,7 @@ public final class ShowTablesExecutorTest {
private ConnectionSession mockConnectionSession() {
ConnectionSession result = mock(ConnectionSession.class);
when(result.getGrantee()).thenReturn(new Grantee("root", ""));
- when(result.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(result.getDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
return result;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java
index 926fd7c066d..2d75f128644 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java
@@ -35,15 +35,15 @@ public final class ShowVersionExecutorTest {
@Test
public void assertExecute() throws SQLException {
- String schemaName = "test";
- MySQLServerInfo.setServerVersion(schemaName, "8.0.26");
+ String databaseName = "test";
+ MySQLServerInfo.setServerVersion(databaseName, "8.0.26");
ShowVersionExecutor executor = new ShowVersionExecutor();
ConnectionSession connectionSession = mock(ConnectionSession.class);
- when(connectionSession.getSchemaName()).thenReturn(schemaName);
+ when(connectionSession.getDatabaseName()).thenReturn(databaseName);
executor.execute(connectionSession);
assertThat(executor.getQueryResultMetaData().getColumnCount(), is(1));
while (executor.getMergedResult().next()) {
- assertThat(executor.getMergedResult().getValue(1, Object.class), is(MySQLServerInfo.getServerVersion(schemaName)));
+ assertThat(executor.getMergedResult().getValue(1, Object.class), is(MySQLServerInfo.getServerVersion(databaseName)));
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
index 45e53953589..6456bfa4a50 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UseDatabaseExecutorTest.java
@@ -53,7 +53,7 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class UseDatabaseExecutorTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
@Mock
private ConnectionSession connectionSession;
@@ -74,7 +74,7 @@ public final class UseDatabaseExecutorTest {
for (int i = 0; i < 10; i++) {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
@@ -82,9 +82,9 @@ public final class UseDatabaseExecutorTest {
@Test
public void assertExecuteUseStatementBackendHandler() {
MySQLUseStatement useStatement = mock(MySQLUseStatement.class);
- when(useStatement.getSchema()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(useStatement.getSchema()).thenReturn(String.format(DATABASE_PATTERN, 0));
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllSchemaNames().contains(any())).thenReturn(true);
+ when(contextManager.getMetaDataContexts().getAllDatabaseNames().contains(any())).thenReturn(true);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().getRules()).thenReturn(Collections.emptyList());
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getRuleMetaData().getRules()).thenReturn(new LinkedList<>());
@@ -92,13 +92,13 @@ public final class UseDatabaseExecutorTest {
ProxyContext.getInstance().init(contextManager);
UseDatabaseExecutor useSchemaBackendHandler = new UseDatabaseExecutor(useStatement);
useSchemaBackendHandler.execute(connectionSession);
- verify(connectionSession).setCurrentSchema(anyString());
+ verify(connectionSession).setCurrentDatabase(anyString());
}
@Test(expected = UnknownDatabaseException.class)
public void assertExecuteUseStatementBackendHandlerWhenSchemaNotExist() {
MySQLUseStatement useStatement = mock(MySQLUseStatement.class);
- when(useStatement.getSchema()).thenReturn(String.format(SCHEMA_PATTERN, 10));
+ when(useStatement.getSchema()).thenReturn(String.format(DATABASE_PATTERN, 10));
UseDatabaseExecutor useSchemaBackendHandler = new UseDatabaseExecutor(useStatement);
useSchemaBackendHandler.execute(connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/fixture/AuthorityCheckerFixture.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/fixture/AuthorityCheckerFixture.java
index ee469af442b..fd0e0006976 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/fixture/AuthorityCheckerFixture.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/fixture/AuthorityCheckerFixture.java
@@ -34,13 +34,13 @@ import java.util.function.BiPredicate;
public final class AuthorityCheckerFixture implements SQLChecker<AuthorityRule> {
@Override
- public boolean check(final String schemaName, final Grantee grantee, final AuthorityRule authorityRule) {
- return !"test".equals(schemaName);
+ public boolean check(final String databaseName, final Grantee grantee, final AuthorityRule authorityRule) {
+ return !"test".equals(databaseName);
}
@Override
public SQLCheckResult check(final SQLStatement sqlStatement, final List<Object> parameters, final Grantee grantee,
- final String currentSchema, final Map<String, ShardingSphereMetaData> metaDataMap, final AuthorityRule authorityRule) {
+ final String currentDatabase, final Map<String, ShardingSphereMetaData> metaDataMap, final AuthorityRule authorityRule) {
return new SQLCheckResult(true, "");
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutorTest.java
index ef3018e3264..e2fcee4ea54 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussSelectDatabaseExecutorTest.java
@@ -47,7 +47,7 @@ public final class OpenGaussSelectDatabaseExecutorTest {
}
private void assertExecute0() throws SQLException {
- when(ProxyContext.getInstance().getAllSchemaNames()).thenReturn(Arrays.asList("foo", "bar", "sharding_db", "other_db"));
+ when(ProxyContext.getInstance().getAllDatabaseNames()).thenReturn(Arrays.asList("foo", "bar", "sharding_db", "other_db"));
OpenGaussSelectDatabaseExecutor executor = new OpenGaussSelectDatabaseExecutor(SQL);
executor.execute(null);
QueryResultMetaData actualMetaData = executor.getQueryResultMetaData();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
index 91f0a7824a3..b642fcf2b31 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
@@ -61,7 +61,7 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class BroadcastDatabaseBackendHandlerTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
@Mock
private ConnectionSession connectionSession;
@@ -81,7 +81,7 @@ public final class BroadcastDatabaseBackendHandlerTest {
mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- when(connectionSession.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(connectionSession.getDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
}
@Test
@@ -102,7 +102,7 @@ public final class BroadcastDatabaseBackendHandlerTest {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.hasDataSource()).thenReturn(true);
when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
index 556252a0733..8e720f83919 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
@@ -64,7 +64,7 @@ public final class SchemaAssignedDatabaseBackendHandlerTest {
private static final String EXECUTE_SQL = "USE test";
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
private SchemaAssignedDatabaseBackendHandler schemaAssignedDatabaseBackendHandler;
@@ -86,7 +86,7 @@ public final class SchemaAssignedDatabaseBackendHandlerTest {
mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- when(connectionSession.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(connectionSession.getDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
mockDatabaseCommunicationEngine(new UpdateResponseHeader(mock(SQLStatement.class)));
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType());
@@ -102,7 +102,7 @@ public final class SchemaAssignedDatabaseBackendHandlerTest {
when(metaData.isComplete()).thenReturn(true);
when(metaData.hasDataSource()).thenReturn(true);
when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
index 289f92a6624..feacc72bf04 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
@@ -62,7 +62,7 @@ public final class UnicastDatabaseBackendHandlerTest {
private static final String EXECUTE_SQL = "SELECT 1 FROM user WHERE id = 1";
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
private UnicastDatabaseBackendHandler unicastDatabaseBackendHandler;
@@ -84,7 +84,7 @@ public final class UnicastDatabaseBackendHandlerTest {
mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), mock(OptimizerContext.class), new ConfigurationProperties(new Properties()));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- when(connectionSession.getDefaultSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ when(connectionSession.getDefaultDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
mockDatabaseCommunicationEngine(new UpdateResponseHeader(mock(SQLStatement.class)));
unicastDatabaseBackendHandler = new UnicastDatabaseBackendHandler(mock(SQLStatementContext.class), EXECUTE_SQL, connectionSession);
setBackendHandlerFactory(unicastDatabaseBackendHandler);
@@ -96,7 +96,7 @@ public final class UnicastDatabaseBackendHandlerTest {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.hasDataSource()).thenReturn(true);
when(metaData.getResource().getDatabaseType()).thenReturn(new H2DatabaseType());
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
index 472adc6f911..4b9b5213088 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
@@ -53,7 +53,7 @@ public final class CreateDatabaseBackendHandlerTest {
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
handler = new CreateDatabaseBackendHandler(statement);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
}
@SneakyThrows
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
index 7d2da26f975..bdc36ae890d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
@@ -64,7 +64,7 @@ public final class DropDatabaseBackendHandlerTest {
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
handler = new DropDatabaseBackendHandler(sqlStatement, connectionSession);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Arrays.asList("test_db", "other_db"));
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Arrays.asList("test_db", "other_db"));
when(metaDataContexts.getGlobalRuleMetaData().getRules()).thenReturn(Collections.emptyList());
when(metaDataContexts.getMetaData(any()).getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
}
@@ -86,27 +86,27 @@ public final class DropDatabaseBackendHandlerTest {
public void assertExecuteDropWithoutCurrentDatabase() {
when(sqlStatement.getDatabaseName()).thenReturn("test_db");
ResponseHeader responseHeader = handler.execute();
- verify(connectionSession, times(0)).setCurrentSchema(null);
+ verify(connectionSession, times(0)).setCurrentDatabase(null);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
@Test
public void assertExecuteDropCurrentDatabase() {
- when(connectionSession.getSchemaName()).thenReturn("test_db");
+ when(connectionSession.getDatabaseName()).thenReturn("test_db");
when(sqlStatement.getDatabaseName()).thenReturn("test_db");
ResponseHeader responseHeader = handler.execute();
- verify(connectionSession).setCurrentSchema(null);
+ verify(connectionSession).setCurrentDatabase(null);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
@Test
public void assertExecuteDropOtherDatabase() {
- when(connectionSession.getSchemaName()).thenReturn("test_db");
+ when(connectionSession.getDatabaseName()).thenReturn("test_db");
when(sqlStatement.getDatabaseName()).thenReturn("other_db");
ResponseHeader responseHeader = handler.execute();
- verify(connectionSession, times(0)).setCurrentSchema(null);
+ verify(connectionSession, times(0)).setCurrentDatabase(null);
assertNotNull(responseHeader);
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
index ea2d17feb75..bc70b22ad2c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
@@ -95,13 +95,13 @@ public final class DistSQLBackendHandlerFactoryTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- when(connectionSession.getSchemaName()).thenReturn("schema");
+ when(connectionSession.getDatabaseName()).thenReturn("db");
}
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
- return Collections.singletonMap("schema", metaData);
+ return Collections.singletonMap("db", metaData);
}
@Test
@@ -114,7 +114,7 @@ public final class DistSQLBackendHandlerFactoryTest {
@Test
public void assertExecuteShardingTableRuleContext() throws SQLException {
setContextManager(true);
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData("schema");
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData("db");
when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CreateShardingTableRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
@@ -273,10 +273,10 @@ public final class DistSQLBackendHandlerFactoryTest {
private MetaDataContexts mockMetaDataContexts() {
MetaDataContexts result = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
- when(result.getAllSchemaNames()).thenReturn(Collections.singletonList("schema"));
- when(result.getMetaData("schema").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
- when(result.getMetaData("schema").getResource().getDataSources()).thenReturn(Collections.emptyMap());
- when(result.getMetaData("schema").getResource().getNotExistedResources(any())).thenReturn(Collections.emptyList());
+ when(result.getAllDatabaseNames()).thenReturn(Collections.singletonList("db"));
+ when(result.getMetaData("db").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
+ when(result.getMetaData("db").getResource().getDataSources()).thenReturn(Collections.emptyMap());
+ when(result.getMetaData("db").getResource().getNotExistedResources(any())).thenReturn(Collections.emptyList());
return result;
}
@@ -284,7 +284,7 @@ public final class DistSQLBackendHandlerFactoryTest {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class);
ShardingSphereRuleMetaData ruleMetaData = mock(ShardingSphereRuleMetaData.class);
- when(metaDataContexts.getMetaData("schema")).thenReturn(shardingSphereMetaData);
+ when(metaDataContexts.getMetaData("db")).thenReturn(shardingSphereMetaData);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
when(shardingSphereMetaData.getResource()).thenReturn(mock(ShardingSphereResource.class));
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(mock(ShadowRuleConfiguration.class)));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java
index d0ea2f78824..dc33d5a2226 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/fixture/TestDatabaseDiscoveryType.java
@@ -26,16 +26,16 @@ import java.util.Map;
public final class TestDatabaseDiscoveryType implements DatabaseDiscoveryType {
@Override
- public void checkDatabaseDiscoveryConfiguration(final String schemaName, final Map<String, DataSource> dataSourceMap) {
+ public void checkDatabaseDiscoveryConfiguration(final String databaseName, final Map<String, DataSource> dataSourceMap) {
}
@Override
- public void updatePrimaryDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap,
+ public void updatePrimaryDataSource(final String databaseName, final Map<String, DataSource> dataSourceMap,
final Collection<String> disabledDataSourceNames, final String groupName) {
}
@Override
- public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String databaseName, final Map<String, DataSource> dataSourceMap, final String groupName) {
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java
index 1b50d30ddfc..40674aead28 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/CountInstanceRulesTest.java
@@ -79,9 +79,9 @@ public final class CountInstanceRulesTest {
when(ruleMetaData.getConfigurations()).thenReturn(ruleConfiguration);
when(shardingSphereMetaData1.getRuleMetaData()).thenReturn(ruleMetaData);
when(shardingSphereMetaData2.getRuleMetaData()).thenReturn(ruleMetaData);
- when(contextManager.getMetaDataContexts().getAllSchemaNames()).thenReturn(Arrays.asList("schema_1", "schema_2"));
- when(contextManager.getMetaDataContexts().getMetaData("schema_1")).thenReturn(shardingSphereMetaData1);
- when(contextManager.getMetaDataContexts().getMetaData("schema_2")).thenReturn(shardingSphereMetaData2);
+ when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Arrays.asList("db_1", "db_2"));
+ when(contextManager.getMetaDataContexts().getMetaData("db_1")).thenReturn(shardingSphereMetaData1);
+ when(contextManager.getMetaDataContexts().getMetaData("db_2")).thenReturn(shardingSphereMetaData2);
ProxyContext.getInstance().init(contextManager);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandlerTest.java
index 5ebcc30dca4..2e5f6b20358 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportSchemaConfigurationHandlerTest.java
@@ -61,7 +61,7 @@ public final class ExportSchemaConfigurationHandlerTest {
@Before
public void init() {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllSchemaNames()).thenReturn(Collections.singletonList("sharding_db"));
+ when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList("sharding_db"));
ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(shardingSphereMetaData.getDefaultSchema()).thenReturn(new ShardingSphereSchema(createTableMap()));
when(shardingSphereMetaData.getResource().getDataSources()).thenReturn(createDataSourceMap());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java
index 0671839dec6..35fbc77eec4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowTableMetadataHandlerTest.java
@@ -49,24 +49,24 @@ public final class ShowTableMetadataHandlerTest {
@Test
public void assertExecutor() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllSchemaNames()).thenReturn(Collections.singletonList("schema_name"));
+ when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList("db_name"));
ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(shardingSphereMetaData.getDefaultSchema()).thenReturn(new ShardingSphereSchema(createTableMap()));
- when(contextManager.getMetaDataContexts().getMetaData("schema_name")).thenReturn(shardingSphereMetaData);
+ when(contextManager.getMetaDataContexts().getMetaData("db_name")).thenReturn(shardingSphereMetaData);
ProxyContext.getInstance().init(contextManager);
ShowTableMetadataHandler handler = new ShowTableMetadataHandler().init(getParameter(createSqlStatement(), mockConnectionSession()));
handler.execute();
handler.next();
ArrayList<Object> data = new ArrayList<>(handler.getRowData());
assertThat(data.size(), is(4));
- assertThat(data.get(0), is("schema_name"));
+ assertThat(data.get(0), is("db_name"));
assertThat(data.get(1), is("t_order"));
assertThat(data.get(2), is("COLUMN"));
assertThat(data.get(3), is("order_id"));
handler.next();
data = new ArrayList<>(handler.getRowData());
assertThat(data.size(), is(4));
- assertThat(data.get(0), is("schema_name"));
+ assertThat(data.get(0), is("db_name"));
assertThat(data.get(1), is("t_order"));
assertThat(data.get(2), is("INDEX"));
assertThat(data.get(3), is("primary"));
@@ -81,7 +81,7 @@ public final class ShowTableMetadataHandlerTest {
}
private ShowTableMetadataStatement createSqlStatement() {
- return new ShowTableMetadataStatement(Collections.singleton("t_order"), new SchemaSegment(0, 0, new IdentifierValue("schema_name")));
+ return new ShowTableMetadataStatement(Collections.singleton("t_order"), new SchemaSegment(0, 0, new IdentifierValue("db_name")));
}
private ConnectionSession mockConnectionSession() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableBackendHandlerTest.java
index 914af817384..bcda9a6364c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ShowVariableBackendHandlerTest.java
@@ -64,7 +64,7 @@ public final class ShowVariableBackendHandlerTest {
@Test
public void assertShowTransactionType() throws SQLException {
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
ShowVariableHandler backendHandler = new ShowVariableHandler()
.init(new HandlerParameter<ShowVariableStatement>().setStatement(new ShowVariableStatement("transaction_type")).setConnectionSession(connectionSession));
ResponseHeader actual = backendHandler.execute();
@@ -78,7 +78,7 @@ public final class ShowVariableBackendHandlerTest {
@Test
public void assertShowCachedConnections() throws SQLException {
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
ShowVariableHandler backendHandler = new ShowVariableHandler()
.init(new HandlerParameter<ShowVariableStatement>().setStatement(new ShowVariableStatement("cached_connections")).setConnectionSession(connectionSession));
ResponseHeader actual = backendHandler.execute();
@@ -92,7 +92,7 @@ public final class ShowVariableBackendHandlerTest {
@Test(expected = UnsupportedVariableException.class)
public void assertShowCachedConnectionFailed() throws SQLException {
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
ShowVariableHandler backendHandler = new ShowVariableHandler()
.init(new HandlerParameter<ShowVariableStatement>().setStatement(new ShowVariableStatement("cached_connectionss")).setConnectionSession(connectionSession));
backendHandler.execute();
@@ -101,7 +101,7 @@ public final class ShowVariableBackendHandlerTest {
@Test
public void assertShowAgentPluginsEnabled() throws SQLException {
SystemPropertyUtil.setSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.TRUE.toString());
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
ShowVariableHandler backendHandler = new ShowVariableHandler()
.init(new HandlerParameter<ShowVariableStatement>().setStatement(new ShowVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name())).setConnectionSession(connectionSession));
ResponseHeader actual = backendHandler.execute();
@@ -115,7 +115,7 @@ public final class ShowVariableBackendHandlerTest {
@Test
public void assertShowPropsVariable() throws SQLException {
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
ContextManager contextManager = mock(ContextManager.class);
ProxyContext.getInstance().init(contextManager);
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class);
@@ -137,7 +137,7 @@ public final class ShowVariableBackendHandlerTest {
@Test
public void assertShowAllVariables() throws SQLException {
- connectionSession.setCurrentSchema("schema");
+ connectionSession.setCurrentDatabase("db");
ContextManager contextManager = mock(ContextManager.class);
ProxyContext.getInstance().init(contextManager);
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandlerTest.java
index 2352a27e4f9..328e6359532 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportSchemaConfigurationHandlerTest.java
@@ -100,7 +100,7 @@ public final class ImportSchemaConfigurationHandlerTest {
validatorField.setAccessible(true);
validatorField.set(importSchemaConfigurationHandler, validator);
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllSchemaNames()).thenReturn(Collections.singletonList(feature));
+ when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList(feature));
ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(shardingSphereMetaData.getDefaultSchema()).thenReturn(new ShardingSphereSchema(createTableMap()));
when(shardingSphereMetaData.getResource().getDataSources()).thenReturn(createDataSourceMap());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetVariableBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetVariableBackendHandlerTest.java
index 2f5bfb44aaf..f14e5111478 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetVariableBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetVariableBackendHandlerTest.java
@@ -59,7 +59,7 @@ import static org.mockito.Mockito.when;
public final class SetVariableBackendHandlerTest {
- private static final String SCHEMA_PATTERN = "schema_%s";
+ private static final String DATABASE_PATTERN = "db_%s";
private ContextManager contextManagerBefore;
@@ -86,14 +86,14 @@ public final class SetVariableBackendHandlerTest {
when(metaData.getResource()).thenReturn(new ShardingSphereResource(Collections.emptyMap(), null, null, new MySQLDatabaseType()));
when(metaData.getRuleMetaData()).thenReturn(new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.emptyList()));
when(metaData.getDefaultSchema()).thenReturn(schema);
- result.put(String.format(SCHEMA_PATTERN, i), metaData);
+ result.put(String.format(DATABASE_PATTERN, i), metaData);
}
return result;
}
@Test
public void assertSwitchTransactionTypeXA() throws SQLException {
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0));
SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "XA"), connectionSession));
ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
@@ -102,7 +102,7 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeBASE() throws SQLException {
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0));
SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "BASE"), connectionSession));
ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
@@ -111,7 +111,7 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeLOCAL() throws SQLException {
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0));
SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "LOCAL"), connectionSession));
ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
@@ -120,7 +120,7 @@ public final class SetVariableBackendHandlerTest {
@Test(expected = UnsupportedVariableException.class)
public void assertSwitchTransactionTypeFailed() throws SQLException {
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0));
SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "XXX"), connectionSession));
handler.execute();
}
@@ -133,7 +133,7 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSetAgentPluginsEnabledTrue() throws SQLException {
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0));
SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.TRUE.toString()), null));
ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
@@ -142,7 +142,7 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSetAgentPluginsEnabledFalse() throws SQLException {
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0));
SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "FALSE"), null));
ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
@@ -151,7 +151,7 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSetAgentPluginsEnabledFalseWithUnknownValue() throws SQLException {
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0));
SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "xxx"), connectionSession));
ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
index 63cc458c596..d379ac3a0ed 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
@@ -86,11 +86,11 @@ public final class AddResourceBackendHandlerTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test_schema"));
- when(metaDataContexts.getMetaData("test_schema")).thenReturn(metaData);
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData("test_db")).thenReturn(metaData);
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.emptyMap());
- ResponseHeader responseHeader = addResourceBackendHandler.execute("test_schema", createAddResourceStatement());
+ ResponseHeader responseHeader = addResourceBackendHandler.execute("test_db", createAddResourceStatement());
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
@@ -99,11 +99,11 @@ public final class AddResourceBackendHandlerTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test_schema"));
- when(metaDataContexts.getMetaData("test_schema")).thenReturn(metaData);
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData("test_db")).thenReturn(metaData);
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.emptyMap());
- addResourceBackendHandler.execute("test_schema", createAlterResourceStatementWithDuplicateResourceNames());
+ addResourceBackendHandler.execute("test_db", createAlterResourceStatementWithDuplicateResourceNames());
}
private AddResourceStatement createAddResourceStatement() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
index 177268105d3..bfc8d52e725 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
@@ -93,17 +93,17 @@ public final class AlterResourceBackendHandlerTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test_schema"));
- when(metaDataContexts.getMetaData("test_schema")).thenReturn(metaData);
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData("test_db")).thenReturn(metaData);
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", mockHikariDataSource("ds_0")));
- ResponseHeader responseHeader = alterResourceBackendHandler.execute("test_schema", createAlterResourceStatement("ds_0"));
+ ResponseHeader responseHeader = alterResourceBackendHandler.execute("test_db", createAlterResourceStatement("ds_0"));
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
@Test(expected = DuplicateResourceException.class)
public void assertExecuteWithDuplicateResourceNames() throws DistSQLException {
- alterResourceBackendHandler.execute("test_schema", createAlterResourceStatementWithDuplicateResourceNames());
+ alterResourceBackendHandler.execute("test_db", createAlterResourceStatementWithDuplicateResourceNames());
}
@Test(expected = RequiredResourceMissedException.class)
@@ -111,11 +111,11 @@ public final class AlterResourceBackendHandlerTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test_schema"));
- when(metaDataContexts.getMetaData("test_schema")).thenReturn(metaData);
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData("test_db")).thenReturn(metaData);
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", dataSource));
- alterResourceBackendHandler.execute("test_schema", createAlterResourceStatement("not_existed"));
+ alterResourceBackendHandler.execute("test_db", createAlterResourceStatement("not_existed"));
}
@Test(expected = InvalidResourcesException.class)
@@ -123,11 +123,11 @@ public final class AlterResourceBackendHandlerTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test_schema"));
- when(metaDataContexts.getMetaData("test_schema")).thenReturn(metaData);
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test_db"));
+ when(metaDataContexts.getMetaData("test_db")).thenReturn(metaData);
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", mockHikariDataSource("ds_1")));
- ResponseHeader responseHeader = alterResourceBackendHandler.execute("test_schema", createAlterResourceStatement("ds_0"));
+ ResponseHeader responseHeader = alterResourceBackendHandler.execute("test_db", createAlterResourceStatement("ds_0"));
assertTrue(responseHeader instanceof UpdateResponseHeader);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
index 6ac18c853f5..9836d6503b9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
@@ -86,7 +86,7 @@ public final class DropResourceBackendHandlerTest {
@Before
public void setUp() throws Exception {
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test"));
when(metaDataContexts.getMetaData("test")).thenReturn(metaData);
when(metaData.getRuleMetaData()).thenReturn(ruleMetaData);
when(metaData.getResource()).thenReturn(resource);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
index 99ede927a9d..fecb2eb93e8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
@@ -49,7 +49,7 @@ public final class RQLBackendHandlerTest {
@Before
public void setUp() {
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class);
- when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
+ when(metaDataContexts.getAllDatabaseNames()).thenReturn(Collections.singleton("test"));
ShardingSphereRuleMetaData ruleMetaData = mock(ShardingSphereRuleMetaData.class);
ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
index 8b1ad857c8f..cd32b03d785 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
@@ -53,7 +53,7 @@ public final class RuleDefinitionBackendHandlerTest {
private ContextManager mockContextManager() {
ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(result.getMetaDataContexts().getAllSchemaNames()).thenReturn(Collections.singleton("test"));
+ when(result.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singleton("test"));
when(result.getMetaDataContexts().getMetaData("test").getRuleMetaData()).thenReturn(mock(ShardingSphereRuleMetaData.class));
return result;
}
@@ -61,7 +61,7 @@ public final class RuleDefinitionBackendHandlerTest {
@Test
public void assertExecute() throws SQLException {
ConnectionSession connectionSession = new ConnectionSession(mock(MySQLDatabaseType.class), TransactionType.LOCAL, new DefaultAttributeMap());
- connectionSession.setCurrentSchema("test");
+ connectionSession.setCurrentDatabase("test");
ResponseHeader response = new RuleDefinitionBackendHandler<>(new CreateFixtureRuleStatement(), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
assertThat(connectionSession.getTransactionStatus().getTransactionType(), is(TransactionType.LOCAL));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
index cc2bd74fa22..c39337ad934 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
@@ -44,7 +44,7 @@ public final class ShardingSphereProxyVersion {
*/
public static void setVersion(final ContextManager contextManager) {
CommonConstants.PROXY_VERSION.set(ShardingSphereProxyVersion.getProxyVersion());
- contextManager.getMetaDataContexts().getAllSchemaNames()
+ contextManager.getMetaDataContexts().getAllDatabaseNames()
.forEach(each -> setDatabaseVersion(each, contextManager.getDataSourceMap(each)));
}
@@ -58,15 +58,15 @@ public final class ShardingSphereProxyVersion {
return result;
}
- private static void setDatabaseVersion(final String schemaName, final Map<String, DataSource> dataSources) {
+ private static void setDatabaseVersion(final String databaseName, final Map<String, DataSource> dataSources) {
Optional<DataSource> dataSource = dataSources.values().stream().findFirst();
if (!dataSource.isPresent()) {
return;
}
DatabaseServerInfo databaseServerInfo = new DatabaseServerInfo(dataSource.get());
- log.info("{}, schema name is `{}`", databaseServerInfo.toString(), schemaName);
+ log.info("{}, database name is `{}`", databaseServerInfo, databaseName);
DatabaseProtocolFrontendEngineFactory
.newInstance(DatabaseTypeRegistry.getTrunkDatabaseType(databaseServerInfo.getDatabaseName()))
- .setDatabaseVersion(schemaName, databaseServerInfo.getDatabaseVersion());
+ .setDatabaseVersion(databaseName, databaseServerInfo.getDatabaseVersion());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index d0dbc6145e8..92e22a30cdd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -143,7 +143,7 @@ public final class CommandExecutorTask implements Runnable {
}
private void fillLogMDC() {
- MDC.put(LogMDCConstants.SCHEMA_KEY, connectionSession.getSchemaName());
+ MDC.put(LogMDCConstants.SCHEMA_KEY, connectionSession.getDatabaseName());
MDC.put(LogMDCConstants.USER_KEY, connectionSession.getGrantee().toString());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
index eb9673f06da..06dad0f5bcc 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
@@ -83,7 +83,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
AuthenticationResult authResult = databaseProtocolFrontendEngine.getAuthenticationEngine().authenticate(context, payload);
if (authResult.isFinished()) {
connectionSession.setGrantee(new Grantee(authResult.getUsername(), authResult.getHostname()));
- connectionSession.setCurrentSchema(authResult.getDatabase());
+ connectionSession.setCurrentDatabase(authResult.getDatabase());
}
return authResult.isFinished();
// CHECKSTYLE:OFF
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java
index 52e65c0b1fc..79230b12d47 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandlerTest.java
@@ -95,7 +95,7 @@ public final class FrontendChannelInboundHandlerTest {
when(authenticationEngine.authenticate(any(ChannelHandlerContext.class), any(PacketPayload.class))).thenReturn(authenticationResult);
channel.writeInbound(Unpooled.EMPTY_BUFFER);
assertThat(connectionSession.getGrantee(), is(new Grantee("username", "hostname")));
- assertThat(connectionSession.getSchemaName(), is("database"));
+ assertThat(connectionSession.getDatabaseName(), is("database"));
}
@SuppressWarnings({"rawtypes", "unchecked"})
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java
index 08699f5ad7b..0e321cc91a7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java
@@ -66,7 +66,7 @@ public final class FrontDatabaseProtocolTypeFactoryTest {
assertFalse(metaDataContexts.getMetaDataMap().isEmpty());
String configuredDatabaseType = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE);
assertTrue(configuredDatabaseType.isEmpty());
- assertTrue(metaDataContexts.getAllSchemaNames().contains(DefaultSchema.LOGIC_NAME));
+ assertTrue(metaDataContexts.getAllDatabaseNames().contains(DefaultSchema.LOGIC_NAME));
DatabaseType databaseType = FrontDatabaseProtocolTypeFactory.getDatabaseType();
assertThat(databaseType, instanceOf(DatabaseType.class));
assertThat(databaseType.getName(), is("MySQL"));
@@ -82,7 +82,7 @@ public final class FrontDatabaseProtocolTypeFactoryTest {
assertFalse(metaDataContexts.getMetaDataMap().isEmpty());
String configuredDatabaseType = metaDataContexts.getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE);
assertThat(configuredDatabaseType, is("PostgreSQL"));
- assertTrue(metaDataContexts.getAllSchemaNames().contains(DefaultSchema.LOGIC_NAME));
+ assertTrue(metaDataContexts.getAllDatabaseNames().contains(DefaultSchema.LOGIC_NAME));
DatabaseType databaseType = FrontDatabaseProtocolTypeFactory.getDatabaseType();
assertThat(databaseType, instanceOf(DatabaseType.class));
assertThat(databaseType.getName(), is("PostgreSQL"));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java
index 43b4626ff37..4b0a362893c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java
@@ -91,7 +91,7 @@ public final class MySQLAuthenticationEngine implements AuthenticationEngine {
MySQLCharacterSet mySQLCharacterSet = MySQLCharacterSet.findById(packet.getCharacterSet());
context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(mySQLCharacterSet.getCharset());
context.channel().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).set(mySQLCharacterSet);
- if (!Strings.isNullOrEmpty(packet.getDatabase()) && !ProxyContext.getInstance().schemaExists(packet.getDatabase())) {
+ if (!Strings.isNullOrEmpty(packet.getDatabase()) && !ProxyContext.getInstance().databaseExists(packet.getDatabase())) {
context.writeAndFlush(new MySQLErrPacket(++sequenceId, MySQLServerErrorCode.ER_BAD_DB_ERROR, packet.getDatabase()));
return AuthenticationResultBuilder.continued();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
index 416b224fedf..6ff8858ded5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
@@ -45,17 +45,17 @@ public final class MySQLComInitDbExecutor implements CommandExecutor {
@Override
public Collection<DatabasePacket<?>> execute() {
- String schemaName = SQLUtil.getExactlyValue(packet.getSchema());
- if (ProxyContext.getInstance().schemaExists(schemaName) && SQLCheckEngine.check(schemaName, getRules(schemaName), connectionSession.getGrantee())) {
- connectionSession.setCurrentSchema(packet.getSchema());
+ String databaseName = SQLUtil.getExactlyValue(packet.getSchema());
+ if (ProxyContext.getInstance().databaseExists(databaseName) && SQLCheckEngine.check(databaseName, getRules(databaseName), connectionSession.getGrantee())) {
+ connectionSession.setCurrentDatabase(packet.getSchema());
return Collections.singletonList(new MySQLOKPacket(1));
}
throw new UnknownDatabaseException(packet.getSchema());
}
- private Collection<ShardingSphereRule> getRules(final String schemaName) {
+ private Collection<ShardingSphereRule> getRules(final String databaseName) {
Collection<ShardingSphereRule> result;
- result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules());
+ result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules());
result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules());
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
index e8ab3ec4161..146f211c91f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
@@ -80,20 +80,20 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
private int currentSequenceId;
public MySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket packet, final ConnectionSession connectionSession) throws SQLException {
- String schemaName = connectionSession.getSchemaName();
+ String databaseName = connectionSession.getDatabaseName();
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
Optional<SQLParserRule> sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class);
Preconditions.checkState(sqlParserRule.isPresent());
ShardingSphereSQLParserEngine sqlStatementParserEngine = new ShardingSphereSQLParserEngine(DatabaseTypeRegistry.getTrunkDatabaseTypeName(
- metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
+ metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
SQLStatement sqlStatement = sqlStatementParserEngine.parse(packet.getSql(), true);
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), packet.getParameters(),
- sqlStatement, connectionSession.getDefaultSchemaName());
+ sqlStatement, connectionSession.getDefaultDatabaseName());
// TODO optimize SQLStatementSchemaHolder
if (sqlStatementContext instanceof TableAvailable) {
((TableAvailable) sqlStatementContext).getTablesContext().getDatabaseName().ifPresent(SQLStatementSchemaHolder::set);
}
- SQLCheckEngine.check(sqlStatement, Collections.emptyList(), getRules(schemaName), schemaName, metaDataContexts.getMetaDataMap(), connectionSession.getGrantee());
+ SQLCheckEngine.check(sqlStatement, Collections.emptyList(), getRules(databaseName), databaseName, metaDataContexts.getMetaDataMap(), connectionSession.getGrantee());
characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
// TODO Refactor the following branch
if (sqlStatement instanceof TCLStatement) {
@@ -107,9 +107,9 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
connectionSession.getBackendConnection());
}
- private static Collection<ShardingSphereRule> getRules(final String schemaName) {
+ private static Collection<ShardingSphereRule> getRules(final String databaseName) {
Collection<ShardingSphereRule> result;
- result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules());
+ result = new LinkedList<>(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules());
result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules());
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
index 95effc9fd91..d64d907cae8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
@@ -72,7 +72,7 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
Optional<SQLParserRule> sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class);
Preconditions.checkState(sqlParserRule.isPresent());
ShardingSphereSQLParserEngine sqlStatementParserEngine = new ShardingSphereSQLParserEngine(DatabaseTypeRegistry.getTrunkDatabaseTypeName(
- metaDataContexts.getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
+ metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
SQLStatement sqlStatement = sqlStatementParserEngine.parse(packet.getSql(), true);
if (!MySQLComStmtPrepareChecker.isStatementAllowed(sqlStatement)) {
throw new UnsupportedPreparedStatementException();
@@ -95,8 +95,8 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
private int getProjectionCount(final SQLStatement sqlStatement) {
if (sqlStatement instanceof SelectStatement) {
Map<String, ShardingSphereMetaData> metaDataMap = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap();
- String schemaName = connectionSession.getSchemaName();
- SelectStatementContext sqlStatementContext = (SelectStatementContext) SQLStatementContextFactory.newInstance(metaDataMap, sqlStatement, schemaName);
+ String databaseName = connectionSession.getDatabaseName();
+ SelectStatementContext sqlStatementContext = (SelectStatementContext) SQLStatementContextFactory.newInstance(metaDataMap, sqlStatement, databaseName);
return sqlStatementContext.getProjectionsContext().getExpandProjections().size();
}
return 0;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
index 90540db222d..214ce78abbe 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
@@ -52,7 +52,7 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
private final MySQLComFieldListPacket packet;
- private final String schemaName;
+ private final String databaseName;
private final JDBCDatabaseCommunicationEngine databaseCommunicationEngine;
@@ -62,15 +62,15 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
public MySQLComFieldListPacketExecutor(final MySQLComFieldListPacket packet, final ConnectionSession connectionSession) {
this.packet = packet;
- schemaName = connectionSession.getDefaultSchemaName();
- String sql = String.format(SQL, packet.getTable(), schemaName);
+ databaseName = connectionSession.getDefaultDatabaseName();
+ String sql = String.format(SQL, packet.getTable(), databaseName);
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
Optional<SQLParserRule> sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class);
Preconditions.checkState(sqlParserRule.isPresent());
ShardingSphereSQLParserEngine sqlStatementParserEngine = new ShardingSphereSQLParserEngine(
- DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
+ DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
SQLStatement sqlStatement = sqlStatementParserEngine.parse(sql, false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), sqlStatement, schemaName);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), sqlStatement, databaseName);
JDBCBackendConnection backendConnection = (JDBCBackendConnection) connectionSession.getBackendConnection();
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext, sql, backendConnection);
characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
@@ -87,7 +87,7 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
while (databaseCommunicationEngine.next()) {
String columnName = databaseCommunicationEngine.getQueryResponseRow().getCells().iterator().next().getData().toString();
result.add(new MySQLColumnDefinition41Packet(
- ++currentSequenceId, characterSet, schemaName, packet.getTable(), packet.getTable(), columnName, columnName, 100, MySQLBinaryColumnType.MYSQL_TYPE_VARCHAR, 0, true));
+ ++currentSequenceId, characterSet, databaseName, packet.getTable(), packet.getTable(), columnName, columnName, 100, MySQLBinaryColumnType.MYSQL_TYPE_VARCHAR, 0, true));
}
result.add(new MySQLEofPacket(++currentSequenceId));
return result;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
index 71fcebe28ac..41edd3184f3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
@@ -109,7 +109,7 @@ public final class MySQLMultiStatementsHandler implements TextProtocolBackendHan
private ShardingSphereSQLParserEngine getSQLParserEngine() {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- return new ShardingSphereSQLParserEngine(DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType()),
+ return new ShardingSphereSQLParserEngine(DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getResource().getDatabaseType()),
metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class).orElseThrow(() -> new IllegalStateException("SQLParserRule not found")).toParserConfiguration());
}
@@ -120,19 +120,19 @@ public final class MySQLMultiStatementsHandler implements TextProtocolBackendHan
private LogicSQL createLogicSQL(final String sql, final SQLStatement sqlStatement) {
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(
- metaDataContexts.getMetaDataMap(), Collections.emptyList(), sqlStatement, connectionSession.getSchemaName());
+ metaDataContexts.getMetaDataMap(), Collections.emptyList(), sqlStatement, connectionSession.getDatabaseName());
return new LogicSQL(sqlStatementContext, sql, Collections.emptyList());
}
private ExecutionContext createExecutionContext(final LogicSQL logicSQL) {
SQLCheckEngine.check(logicSQL.getSqlStatementContext().getSqlStatement(), logicSQL.getParameters(),
- metaDataContexts.getMetaData(connectionSession.getSchemaName()).getRuleMetaData().getRules(), connectionSession.getSchemaName(), metaDataContexts.getMetaDataMap(), null);
- return kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getMetaData(connectionSession.getSchemaName()), metaDataContexts.getProps());
+ metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getRuleMetaData().getRules(), connectionSession.getDatabaseName(), metaDataContexts.getMetaDataMap(), null);
+ return kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getMetaData(connectionSession.getDatabaseName()), metaDataContexts.getProps());
}
@Override
public ResponseHeader execute() throws SQLException {
- Collection<ShardingSphereRule> rules = metaDataContexts.getMetaData(connectionSession.getSchemaName()).getRuleMetaData().getRules();
+ Collection<ShardingSphereRule> rules = metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getRuleMetaData().getRules();
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = new DriverExecutionPrepareEngine<>(
JDBCDriverType.STATEMENT, metaDataContexts.getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY),
(JDBCBackendConnection) connectionSession.getBackendConnection(), (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(false), rules);
@@ -162,7 +162,7 @@ public final class MySQLMultiStatementsHandler implements TextProtocolBackendHan
private UpdateResponseHeader executeBatchedStatements(final ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext) throws SQLException {
boolean isExceptionThrown = SQLExecutorExceptionHandler.isExceptionThrown();
- DatabaseType databaseType = metaDataContexts.getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getResource().getDatabaseType();
JDBCExecutorCallback<int[]> callback = new BatchedJDBCExecutorCallback(databaseType, sqlStatementSample, isExceptionThrown);
List<int[]> executeResults = jdbcExecutor.execute(executionGroupContext, callback);
int updated = 0;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
index 68070db7f87..780dbb6364f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
@@ -88,8 +88,8 @@ public final class MySQLCommandExecutorFactoryTest {
@Before
public void setUp() throws ReflectiveOperationException {
- when(connectionSession.getSchemaName()).thenReturn("logic_db");
- when(connectionSession.getDefaultSchemaName()).thenReturn("logic_db");
+ when(connectionSession.getDatabaseName()).thenReturn("logic_db");
+ when(connectionSession.getDefaultDatabaseName()).thenReturn("logic_db");
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get()).thenReturn(MySQLCharacterSet.UTF8MB4_GENERAL_CI);
when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
index c5a2cc234ac..f7d2d84776b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
@@ -103,8 +103,8 @@ public final class MySQLComStmtExecuteExecutorTest {
@Test
public void assertIsQueryResponse() throws NoSuchFieldException, SQLException {
- when(connectionSession.getSchemaName()).thenReturn("logic_db");
- when(connectionSession.getDefaultSchemaName()).thenReturn("logic_db");
+ when(connectionSession.getDatabaseName()).thenReturn("logic_db");
+ when(connectionSession.getDefaultDatabaseName()).thenReturn("logic_db");
MySQLComStmtExecutePacket packet = mock(MySQLComStmtExecutePacket.class);
when(packet.getSql()).thenReturn("SELECT 1");
MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(packet, connectionSession);
@@ -116,8 +116,8 @@ public final class MySQLComStmtExecuteExecutorTest {
@Test
public void assertIsUpdateResponse() throws NoSuchFieldException, SQLException {
- when(connectionSession.getSchemaName()).thenReturn("logic_db");
- when(connectionSession.getDefaultSchemaName()).thenReturn("logic_db");
+ when(connectionSession.getDatabaseName()).thenReturn("logic_db");
+ when(connectionSession.getDefaultDatabaseName()).thenReturn("logic_db");
MySQLComStmtExecutePacket packet = mock(MySQLComStmtExecutePacket.class);
when(packet.getSql()).thenReturn("SELECT 1");
MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(packet, connectionSession);
@@ -129,8 +129,8 @@ public final class MySQLComStmtExecuteExecutorTest {
@Test
public void assertExecutePreparedCommit() throws SQLException, NoSuchFieldException {
- when(connectionSession.getSchemaName()).thenReturn("logic_db");
- when(connectionSession.getDefaultSchemaName()).thenReturn("logic_db");
+ when(connectionSession.getDatabaseName()).thenReturn("logic_db");
+ when(connectionSession.getDefaultDatabaseName()).thenReturn("logic_db");
MySQLComStmtExecutePacket packet = mock(MySQLComStmtExecutePacket.class);
when(packet.getSql()).thenReturn("commit");
MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(packet, connectionSession);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
index 7fa795b6ff6..7008b70b8f0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
@@ -100,12 +100,12 @@ public final class MySQLComQueryPacketExecutorTest {
public void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFieldException {
when(connectionSession.getAttributeMap().hasAttr(MySQLConstants.MYSQL_OPTION_MULTI_STATEMENTS)).thenReturn(true);
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_OPTION_MULTI_STATEMENTS).get()).thenReturn(0);
- when(connectionSession.getSchemaName()).thenReturn("schema_name");
+ when(connectionSession.getDatabaseName()).thenReturn("db_name");
when(packet.getSql()).thenReturn("update t set v=v+1 where id=1;update t set v=v+1 where id=2;update t set v=v+1 where id=3");
try (MockedStatic<ProxyContext> mockedStatic = mockStatic(ProxyContext.class)) {
ProxyContext mockedProxyContext = mock(ProxyContext.class, RETURNS_DEEP_STUBS);
mockedStatic.when(ProxyContext::getInstance).thenReturn(mockedProxyContext);
- when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData("schema_name").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
+ when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData("db_name").getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(SQLParserRule.class))
.thenReturn(Optional.of(new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build())));
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Integer>getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE)).thenReturn(1);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
index aba48070df5..baa12937632 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
@@ -73,7 +73,7 @@ public final class MySQLMultiStatementsHandlerTest {
@Test
public void assertExecute() throws SQLException {
final String sql = "update t set v=v+1 where id=1;update t set v=v+1 where id=2;update t set v=v+1 where id=3";
- when(connectionSession.getSchemaName()).thenReturn("");
+ when(connectionSession.getDatabaseName()).thenReturn("");
when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
when(connectionSession.getStatementManager()).thenReturn(backendStatement);
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
index 78aedbe6f09..a648f12af05 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationHandler.java
@@ -74,7 +74,7 @@ public final class OpenGaussAuthenticationHandler {
final PostgreSQLPasswordMessagePacket passwordMessagePacket) {
String clientDigest = passwordMessagePacket.getDigest();
Grantee grantee = new Grantee(username, "%");
- if (!Strings.isNullOrEmpty(databaseName) && !ProxyContext.getInstance().schemaExists(databaseName)) {
+ if (!Strings.isNullOrEmpty(databaseName) && !ProxyContext.getInstance().databaseExists(databaseName)) {
return new PostgreSQLLoginResult(PostgreSQLErrorCode.INVALID_CATALOG_NAME, String.format("database \"%s\" does not exist", databaseName));
}
if (!SQLCheckEngine.check(grantee, getRules(databaseName))) {
@@ -90,7 +90,7 @@ public final class OpenGaussAuthenticationHandler {
private static Collection<ShardingSphereRule> getRules(final String databaseName) {
Collection<ShardingSphereRule> result = new LinkedList<>();
- if (!Strings.isNullOrEmpty(databaseName) && ProxyContext.getInstance().schemaExists(databaseName)) {
+ if (!Strings.isNullOrEmpty(databaseName) && ProxyContext.getInstance().databaseExists(databaseName)) {
result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules());
}
result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
index 68ecf464a10..59618c4cad6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationHandler.java
@@ -48,7 +48,7 @@ public final class PostgreSQLAuthenticationHandler {
public PostgreSQLLoginResult login(final String username, final String databaseName, final byte[] md5Salt, final PostgreSQLPasswordMessagePacket passwordMessagePacket) {
String digest = passwordMessagePacket.getDigest();
Grantee grantee = new Grantee(username, "%");
- if (!Strings.isNullOrEmpty(databaseName) && !ProxyContext.getInstance().schemaExists(databaseName)) {
+ if (!Strings.isNullOrEmpty(databaseName) && !ProxyContext.getInstance().databaseExists(databaseName)) {
return new PostgreSQLLoginResult(PostgreSQLErrorCode.INVALID_CATALOG_NAME, String.format("database \"%s\" does not exist", databaseName));
}
if (!SQLCheckEngine.check(grantee, getRules(databaseName))) {
@@ -65,7 +65,7 @@ public final class PostgreSQLAuthenticationHandler {
private Collection<ShardingSphereRule> getRules(final String databaseName) {
Collection<ShardingSphereRule> result = new LinkedList<>();
- if (!Strings.isNullOrEmpty(databaseName) && ProxyContext.getInstance().schemaExists(databaseName)) {
+ if (!Strings.isNullOrEmpty(databaseName) && ProxyContext.getInstance().databaseExists(databaseName)) {
result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseName).getRuleMetaData().getRules());
}
result.addAll(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java
index 43d11a9092b..98df8b99cba 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java
@@ -102,12 +102,12 @@ public final class JDBCPortal implements Portal<Void> {
preparedStatement.getSql(), () -> Optional.of(sqlStatement), backendConnection.getConnectionSession());
return;
}
- String schemaName = backendConnection.getConnectionSession().getDefaultSchemaName();
+ String databaseName = backendConnection.getConnectionSession().getDefaultDatabaseName();
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(
- ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), parameters, sqlStatement, schemaName);
+ ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), parameters, sqlStatement, databaseName);
if (containsSystemTable(sqlStatementContext.getTablesContext().getTableNames())) {
databaseCommunicationEngine = null;
- DatabaseType databaseType = ProxyContext.getInstance().getMetaData(schemaName).getResource().getDatabaseType();
+ DatabaseType databaseType = ProxyContext.getInstance().getMetaData(databaseName).getResource().getDatabaseType();
textProtocolBackendHandler = TextProtocolBackendHandlerFactory.newInstance(databaseType,
preparedStatement.getSql(), () -> Optional.of(sqlStatement), backendConnection.getConnectionSession());
return;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
index 68d871e25e0..e37bf9965fa 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
@@ -103,7 +103,7 @@ public final class PostgreSQLBatchedStatementsExecutor {
}
private SQLStatementContext<?> createSQLStatementContext(final List<Object> parameters) {
- return SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), parameters, preparedStatement.getSqlStatement(), connectionSession.getSchemaName());
+ return SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), parameters, preparedStatement.getSqlStatement(), connectionSession.getDatabaseName());
}
private void prepareForRestOfParametersSet(final Iterator<List<Object>> parameterSetsIterator, final SQLStatementContext<?> sqlStatementContext) {
@@ -125,8 +125,8 @@ public final class PostgreSQLBatchedStatementsExecutor {
private ExecutionContext createExecutionContext(final LogicSQL logicSQL) {
SQLCheckEngine.check(logicSQL.getSqlStatementContext().getSqlStatement(), logicSQL.getParameters(),
- metaDataContexts.getMetaData(connectionSession.getSchemaName()).getRuleMetaData().getRules(), connectionSession.getSchemaName(), metaDataContexts.getMetaDataMap(), null);
- return kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getMetaData(connectionSession.getSchemaName()), metaDataContexts.getProps());
+ metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getRuleMetaData().getRules(), connectionSession.getDatabaseName(), metaDataContexts.getMetaDataMap(), null);
+ return kernelProcessor.generateExecutionContext(logicSQL, metaDataContexts.getMetaData(connectionSession.getDatabaseName()), metaDataContexts.getProps());
}
/**
@@ -141,7 +141,7 @@ public final class PostgreSQLBatchedStatementsExecutor {
}
private void addBatchedParametersToPreparedStatements() throws SQLException {
- Collection<ShardingSphereRule> rules = metaDataContexts.getMetaData(connectionSession.getSchemaName()).getRuleMetaData().getRules();
+ Collection<ShardingSphereRule> rules = metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getRuleMetaData().getRules();
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = new DriverExecutionPrepareEngine<>(
JDBCDriverType.PREPARED_STATEMENT, metaDataContexts.getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY),
(JDBCBackendConnection) connectionSession.getBackendConnection(), (JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(false), rules);
@@ -171,7 +171,7 @@ public final class PostgreSQLBatchedStatementsExecutor {
private int executeBatchedPreparedStatements() throws SQLException {
boolean isExceptionThrown = SQLExecutorExceptionHandler.isExceptionThrown();
- DatabaseType databaseType = metaDataContexts.getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = metaDataContexts.getMetaData(connectionSession.getDatabaseName()).getResource().getDatabaseType();
JDBCExecutorCallback<int[]> callback = new BatchedStatementsJDBCExecutorCallback(databaseType, preparedStatement.getSqlStatement(), isExceptionThrown);
List<int[]> executeResults = jdbcExecutor.execute(executionGroupContext, callback);
int result = 0;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
index f098c6d8b01..7903b5f3956 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
@@ -124,9 +124,9 @@ public final class PostgreSQLComDescribeExecutor implements CommandExecutor {
if (unspecifiedTypeParameterIndexes.isEmpty()) {
return;
}
- String schemaName = connectionSession.getSchemaName();
+ String databaseName = connectionSession.getDatabaseName();
String logicTableName = insertStatement.getTable().getTableName().getIdentifier().getValue();
- TableMetaData tableMetaData = ProxyContext.getInstance().getMetaData(schemaName).getDefaultSchema().get(logicTableName);
+ TableMetaData tableMetaData = ProxyContext.getInstance().getMetaData(databaseName).getDefaultSchema().get(logicTableName);
Map<String, ColumnMetaData> columnMetaData = tableMetaData.getColumns();
List<String> columnNames;
if (insertStatement.getColumns().isEmpty()) {
@@ -171,11 +171,11 @@ public final class PostgreSQLComDescribeExecutor implements CommandExecutor {
return;
}
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- String schemaName = connectionSession.getSchemaName();
+ String databaseName = connectionSession.getDatabaseName();
SQLStatementContext<?> sqlStatementContext =
- SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), preparedStatement.getSqlStatement(), schemaName);
+ SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), preparedStatement.getSqlStatement(), databaseName);
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, preparedStatement.getSql(), Collections.emptyList());
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(schemaName);
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(databaseName);
ExecutionContext executionContext = new KernelProcessor().generateExecutionContext(logicSQL, metaData, metaDataContexts.getProps());
ExecutionUnit executionUnitSample = executionContext.getExecutionUnits().iterator().next();
JDBCBackendConnection backendConnection = (JDBCBackendConnection) connectionSession.getBackendConnection();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
index e37bba6b48b..713bf160b1c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutor.java
@@ -59,7 +59,7 @@ public final class PostgreSQLComParseExecutor implements CommandExecutor {
public Collection<DatabasePacket<?>> execute() {
ShardingSphereSQLParserEngine sqlParserEngine = null;
String sql = packet.getSql();
- SQLStatement sqlStatement = sql.trim().isEmpty() ? new EmptyStatement() : (sqlParserEngine = createShardingSphereSQLParserEngine(connectionSession.getSchemaName())).parse(sql, true);
+ SQLStatement sqlStatement = sql.trim().isEmpty() ? new EmptyStatement() : (sqlParserEngine = createShardingSphereSQLParserEngine(connectionSession.getDatabaseName())).parse(sql, true);
if (sqlStatement.getParameterCount() > 0) {
sql = convertSQLToJDBCStyle(sqlStatement, sql);
sqlStatement = sqlParserEngine.parse(sql, true);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
index 20e7440d766..def196af0cb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
@@ -78,7 +78,7 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class PostgreSQLComDescribeExecutorTest {
- private static final String SCHEMA_NAME = "postgres";
+ private static final String DATABASE_NAME = "postgres";
private static final String TABLE_NAME = "t_order";
@@ -107,8 +107,8 @@ public final class PostgreSQLComDescribeExecutorTest {
contextManagerBefore = ProxyContext.getInstance().getContextManager();
ProxyContext.getInstance().init(mockContextManager);
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.SQL_SHOW)).thenReturn(false);
- when(connectionSession.getSchemaName()).thenReturn(SCHEMA_NAME);
- when(mockContextManager.getMetaDataContexts().getAllSchemaNames().contains(SCHEMA_NAME)).thenReturn(true);
+ when(connectionSession.getDatabaseName()).thenReturn(DATABASE_NAME);
+ when(mockContextManager.getMetaDataContexts().getAllDatabaseNames().contains(DATABASE_NAME)).thenReturn(true);
prepareTableMetaData();
}
@@ -119,7 +119,7 @@ public final class PostgreSQLComDescribeExecutorTest {
new ColumnMetaData("c", Types.CHAR, true, false, false),
new ColumnMetaData("pad", Types.CHAR, true, false, false));
TableMetaData tableMetaData = new TableMetaData(TABLE_NAME, columnMetaData, Collections.emptyList(), Collections.emptyList());
- when(mockContextManager.getMetaDataContexts().getMetaData(SCHEMA_NAME).getDefaultSchema().get(TABLE_NAME)).thenReturn(tableMetaData);
+ when(mockContextManager.getMetaDataContexts().getMetaData(DATABASE_NAME).getDefaultSchema().get(TABLE_NAME)).thenReturn(tableMetaData);
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
index 7a95baf6130..7cbb841cc9f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
@@ -23,9 +23,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLPreparedStatementRegistry;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.parse.PostgreSQLComParsePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.parse.PostgreSQLParseCompletePacket;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
@@ -45,14 +43,11 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Map;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -107,8 +102,8 @@ public final class PostgreSQLComParseExecutorTest {
when(parsePacket.getSql()).thenReturn(rawSQL);
when(parsePacket.getStatementId()).thenReturn(statementId);
when(parsePacket.readParameterTypes()).thenReturn(Collections.singletonList(PostgreSQLColumnType.POSTGRESQL_TYPE_INT4));
- when(connectionSession.getSchemaName()).thenReturn("schema");
- when(mockedContextManager.getMetaDataContexts().getMetaData("schema").getResource().getDatabaseType()).thenReturn(new PostgreSQLDatabaseType());
+ when(connectionSession.getDatabaseName()).thenReturn("db");
+ when(mockedContextManager.getMetaDataContexts().getMetaData("db").getResource().getDatabaseType()).thenReturn(new PostgreSQLDatabaseType());
when(mockedContextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(SQLParserRule.class)).thenReturn(Optional.of(sqlParserRule));
Collection<DatabasePacket<?>> actualPackets = executor.execute();
assertThat(actualPackets.size(), is(1));
@@ -119,12 +114,6 @@ public final class PostgreSQLComParseExecutorTest {
assertThat(actualPreparedStatement.getParameterTypes(), is(Arrays.asList(PostgreSQLColumnType.POSTGRESQL_TYPE_INT4, PostgreSQLColumnType.POSTGRESQL_TYPE_UNSPECIFIED)));
}
- private Map<String, ShardingSphereMetaData> getMetaDataMap() {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
- when(metaData.getResource().getDatabaseType()).thenReturn(new MySQLDatabaseType());
- return Collections.singletonMap("schema", metaData);
- }
-
@After
public void tearDown() {
ProxyContext.getInstance().init(contextManagerBefore);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
index d8d392af0a7..85786b63a74 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
@@ -81,20 +81,20 @@ public final class ReactiveMySQLComStmtExecuteExecutor implements ReactiveComman
private int currentSequenceId;
public ReactiveMySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket packet, final ConnectionSession connectionSession) throws SQLException {
- String schemaName = connectionSession.getSchemaName();
+ String databaseName = connectionSession.getDatabaseName();
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
Optional<SQLParserRule> sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class);
Preconditions.checkState(sqlParserRule.isPresent());
ShardingSphereSQLParserEngine sqlStatementParserEngine = new ShardingSphereSQLParserEngine(
- DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
+ DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
SQLStatement sqlStatement = sqlStatementParserEngine.parse(packet.getSql(), true);
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), packet.getParameters(),
- sqlStatement, connectionSession.getDefaultSchemaName());
+ sqlStatement, connectionSession.getDefaultDatabaseName());
// TODO optimize SQLStatementSchemaHolder
if (sqlStatementContext instanceof TableAvailable) {
((TableAvailable) sqlStatementContext).getTablesContext().getDatabaseName().ifPresent(SQLStatementSchemaHolder::set);
}
- SQLCheckEngine.check(sqlStatement, Collections.emptyList(), getRules(schemaName), schemaName, metaDataContexts.getMetaDataMap(), connectionSession.getGrantee());
+ SQLCheckEngine.check(sqlStatement, Collections.emptyList(), getRules(databaseName), databaseName, metaDataContexts.getMetaDataMap(), connectionSession.getGrantee());
characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
// TODO Refactor the following branch
if (sqlStatement instanceof TCLStatement) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
index 605f60fe175..333403b3e46 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
@@ -52,7 +52,7 @@ public final class ReactiveMySQLComFieldListPacketExecutor implements ReactiveCo
private final MySQLComFieldListPacket packet;
- private final String schemaName;
+ private final String databaseName;
private final VertxDatabaseCommunicationEngine databaseCommunicationEngine;
@@ -62,15 +62,15 @@ public final class ReactiveMySQLComFieldListPacketExecutor implements ReactiveCo
public ReactiveMySQLComFieldListPacketExecutor(final MySQLComFieldListPacket packet, final ConnectionSession connectionSession) {
this.packet = packet;
- schemaName = connectionSession.getDefaultSchemaName();
- String sql = String.format(SQL, packet.getTable(), schemaName);
+ databaseName = connectionSession.getDefaultDatabaseName();
+ String sql = String.format(SQL, packet.getTable(), databaseName);
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
Optional<SQLParserRule> sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class);
Preconditions.checkState(sqlParserRule.isPresent());
ShardingSphereSQLParserEngine sqlStatementParserEngine = new ShardingSphereSQLParserEngine(
- DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
+ DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(databaseName).getResource().getDatabaseType()), sqlParserRule.get().toParserConfiguration());
SQLStatement sqlStatement = sqlStatementParserEngine.parse(sql, false);
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), sqlStatement, schemaName);
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), sqlStatement, databaseName);
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext, sql, connectionSession.getBackendConnection());
characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
}
@@ -91,7 +91,7 @@ public final class ReactiveMySQLComFieldListPacketExecutor implements ReactiveCo
while (databaseCommunicationEngine.next()) {
String columnName = databaseCommunicationEngine.getQueryResponseRow().getCells().iterator().next().getData().toString();
result.add(new MySQLColumnDefinition41Packet(
- ++currentSequenceId, characterSet, schemaName, packet.getTable(), packet.getTable(), columnName, columnName, 100, MySQLBinaryColumnType.MYSQL_TYPE_VARCHAR, 0, true));
+ ++currentSequenceId, characterSet, databaseName, packet.getTable(), packet.getTable(), columnName, columnName, 100, MySQLBinaryColumnType.MYSQL_TYPE_VARCHAR, 0, true));
}
result.add(new MySQLEofPacket(++currentSequenceId));
return result;