This is an automated email from the ASF dual-hosted git repository.
panjuan 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 966d5e1 Refactor useless meta data refresher (#13950)
966d5e1 is described below
commit 966d5e131ef12893d9704ff5120ab819a6a60de8
Author: Haoran Meng <[email protected]>
AuthorDate: Mon Dec 6 19:29:10 2021 +0800
Refactor useless meta data refresher (#13950)
Co-authored-by: shardingsphere <[email protected]>
---
.../infra/metadata/MetaDataRefresher.java | 24 ----
.../metadata/schema/refresher/SchemaRefresher.java | 45 --------
.../type/AlterIndexStatementSchemaRefresher.java | 59 ----------
.../type/AlterTableStatementSchemaRefresher.java | 72 ------------
.../type/CreateIndexStatementSchemaRefresher.java | 44 --------
.../type/CreateTableStatementSchemaRefresher.java | 57 ----------
.../type/CreateViewStatementSchemaRefresher.java | 48 --------
.../type/DropIndexStatementSchemaRefresher.java | 74 -------------
.../type/DropTableStatementSchemaRefresher.java | 42 -------
.../type/DropViewStatementSchemaRefresher.java | 42 -------
.../AlterIndexStatementSchemaRefresherTest.java | 54 ---------
.../AlterTableStatementSchemaRefresherTest.java | 105 ------------------
.../CreateIndexStatementSchemaRefresherTest.java | 105 ------------------
.../CreateTableStatementSchemaRefresherTest.java | 93 ----------------
.../CreateViewStatementSchemaRefresherTest.java | 57 ----------
.../DropIndexStatementSchemaRefresherTest.java | 98 ----------------
.../DropTableStatementSchemaRefresherTest.java | 111 -------------------
.../type/DropViewStatementSchemaRefresherTest.java | 57 ----------
.../type/ShardingSphereSchemaBuildUtil.java | 42 -------
.../refresher/MetaDataRefresherFactory.java | 95 ----------------
.../refresher/MetaDataRefresherFactoryTest.java | 66 -----------
.../refresher/FederationMetaDataRefresher.java | 48 --------
.../AlterTableFederationMetaDataRefresher.java | 58 ----------
.../CreateTableFederationMetaDataRefresher.java | 47 --------
.../type/DropTableFederationMetaDataRefresher.java | 39 -------
.../AlterTableFederationMetaDataRefresherTest.java | 123 ---------------------
...CreateTableFederationMetaDataRefresherTest.java | 111 -------------------
.../DropTableFederationMetaDataRefresherTest.java | 118 --------------------
28 files changed, 1934 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/MetaDataRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/MetaDataRefresher.java
deleted file mode 100644
index 555dfc5..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/MetaDataRefresher.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata;
-
-/**
- * Meta data refresher.
- */
-public interface MetaDataRefresher {
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
deleted file mode 100644
index 894fb46..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/SchemaRefresher.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.MetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
-
-/**
- * ShardingSphere schema refresher.
- *
- * @param <T> type of SQL statement
- */
-public interface SchemaRefresher<T extends SQLStatement> extends
MetaDataRefresher {
-
- /**
- * Refresh ShardingSphere schema.
- *
- * @param schemaMetaData schema meta data
- * @param logicDataSourceNames route data source names
- * @param sqlStatement SQL statement
- * @param props configuration properties
- * @throws SQLException SQL exception
- */
- void refresh(ShardingSphereMetaData schemaMetaData, Collection<String>
logicDataSourceNames, T sqlStatement, ConfigurationProperties props) throws
SQLException;
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterIndexStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterIndexStatementSchemaRefresher.java
deleted file mode 100644
index bf948c9..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterIndexStatementSchemaRefresher.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import com.google.common.base.Preconditions;
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterIndexStatementHandler;
-
-import java.util.Collection;
-import java.util.Optional;
-
-/**
- * Schema refresher for alter index statement.
- */
-public final class AlterIndexStatementSchemaRefresher implements
SchemaRefresher<AlterIndexStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames, final AlterIndexStatement
sqlStatement, final ConfigurationProperties props) {
- Optional<IndexSegment> renameIndex =
AlterIndexStatementHandler.getRenameIndexSegment(sqlStatement);
- if (!sqlStatement.getIndex().isPresent() || !renameIndex.isPresent()) {
- return;
- }
- String indexName =
sqlStatement.getIndex().get().getIdentifier().getValue();
- Optional<String> logicTableName =
findLogicTableName(schemaMetaData.getSchema(), indexName);
- if (logicTableName.isPresent()) {
- TableMetaData tableMetaData =
schemaMetaData.getSchema().get(logicTableName.get());
- Preconditions.checkNotNull(tableMetaData, "Can not get the table
'%s' metadata!", logicTableName.get());
- tableMetaData.getIndexes().remove(indexName);
- String renameIndexName =
renameIndex.get().getIdentifier().getValue();
- tableMetaData.getIndexes().put(renameIndexName, new
IndexMetaData(renameIndexName));
- }
- }
-
- private Optional<String> findLogicTableName(final ShardingSphereSchema
schema, final String indexName) {
- return schema.getAllTableNames().stream().filter(each ->
schema.get(each).getIndexes().containsKey(indexName)).findFirst();
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresher.java
deleted file mode 100644
index 9204f44..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresher.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-
-/**
- * Schema refresher for alter table statement.
- */
-public final class AlterTableStatementSchemaRefresher implements
SchemaRefresher<AlterTableStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames,
- final AlterTableStatement sqlStatement, final
ConfigurationProperties props) throws SQLException {
- String tableName =
sqlStatement.getTable().getTableName().getIdentifier().getValue();
- if (sqlStatement.getRenameTable().isPresent()) {
- putTableMetaData(schemaMetaData, logicDataSourceNames,
sqlStatement.getRenameTable().get().getTableName().getIdentifier().getValue(),
props);
- removeTableMetaData(schemaMetaData, tableName);
- } else {
- putTableMetaData(schemaMetaData, logicDataSourceNames, tableName,
props);
- }
- }
-
- private void removeTableMetaData(final ShardingSphereMetaData
schemaMetaData, final String tableName) {
- schemaMetaData.getSchema().remove(tableName);
-
schemaMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each
-> each.remove(tableName));
- }
-
- private void putTableMetaData(final ShardingSphereMetaData schemaMetaData,
- final Collection<String>
logicDataSourceNames, final String tableName, final ConfigurationProperties
props) throws SQLException {
- if (!containsInDataNodeContainedRule(tableName, schemaMetaData)) {
-
schemaMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each
-> each.put(tableName, logicDataSourceNames.iterator().next()));
- }
- SchemaBuilderMaterials materials = new SchemaBuilderMaterials(
- schemaMetaData.getResource().getDatabaseType(),
schemaMetaData.getResource().getDataSources(),
schemaMetaData.getRuleMetaData().getRules(), props);
- TableMetaData tableMetaData =
Optional.ofNullable(TableMetaDataBuilder.load(Collections.singletonList(tableName),
materials).get(tableName))
- .map(each ->
TableMetaDataBuilder.decorateKernelTableMetaData(each,
materials.getRules())).orElseGet(TableMetaData::new);
- schemaMetaData.getSchema().put(tableName, tableMetaData);
- }
-
- private boolean containsInDataNodeContainedRule(final String tableName,
final ShardingSphereMetaData schemaMetaData) {
- return
schemaMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream().anyMatch(each
-> each.getAllTables().contains(tableName));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateIndexStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateIndexStatementSchemaRefresher.java
deleted file mode 100644
index 24525c6..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateIndexStatementSchemaRefresher.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import com.google.common.base.Strings;
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.util.IndexMetaDataUtil;
-import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
-
-import java.util.Collection;
-
-/**
- * Schema refresher for create index statement.
- */
-public final class CreateIndexStatementSchemaRefresher implements
SchemaRefresher<CreateIndexStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames, final CreateIndexStatement
sqlStatement, final ConfigurationProperties props) {
- String indexName = null != sqlStatement.getIndex() ?
sqlStatement.getIndex().getIdentifier().getValue() :
IndexMetaDataUtil.getGeneratedLogicIndexName(sqlStatement.getColumns());
- if (Strings.isNullOrEmpty(indexName)) {
- return;
- }
- String tableName =
sqlStatement.getTable().getTableName().getIdentifier().getValue();
- schemaMetaData.getSchema().get(tableName).getIndexes().put(indexName,
new IndexMetaData(indexName));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresher.java
deleted file mode 100644
index 33fabd0..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresher.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-
-/**
- * Schema refresher for create table statement.
- */
-public final class CreateTableStatementSchemaRefresher implements
SchemaRefresher<CreateTableStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames,
- final CreateTableStatement sqlStatement, final
ConfigurationProperties props) throws SQLException {
- String tableName =
sqlStatement.getTable().getTableName().getIdentifier().getValue();
- if (!containsInDataNodeContainedRule(tableName, schemaMetaData)) {
-
schemaMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each
-> each.put(tableName, logicDataSourceNames.iterator().next()));
- }
- SchemaBuilderMaterials materials = new SchemaBuilderMaterials(
- schemaMetaData.getResource().getDatabaseType(),
schemaMetaData.getResource().getDataSources(),
schemaMetaData.getRuleMetaData().getRules(), props);
- TableMetaData tableMetaData =
Optional.ofNullable(TableMetaDataBuilder.load(Collections.singletonList(tableName),
materials).get(tableName))
- .map(each ->
TableMetaDataBuilder.decorateKernelTableMetaData(each,
materials.getRules())).orElseGet(TableMetaData::new);
- schemaMetaData.getSchema().put(tableName, tableMetaData);
- }
-
- private boolean containsInDataNodeContainedRule(final String tableName,
final ShardingSphereMetaData schemaMetaData) {
- return
schemaMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream().anyMatch(each
-> each.getAllTables().contains(tableName));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresher.java
deleted file mode 100644
index 32581a0..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresher.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
-
-import java.util.Collection;
-
-/**
- * Schema refresher for create view statement.
- */
-public final class CreateViewStatementSchemaRefresher implements
SchemaRefresher<CreateViewStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames, final CreateViewStatement
sqlStatement, final ConfigurationProperties props) {
- String viewName =
sqlStatement.getView().getTableName().getIdentifier().getValue();
- TableMetaData tableMetaData = new TableMetaData();
- schemaMetaData.getSchema().put(viewName, tableMetaData);
- if (!containsInDataNodeContainedRule(viewName, schemaMetaData)) {
-
schemaMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class).forEach(each
-> each.put(viewName, logicDataSourceNames.iterator().next()));
- }
- }
-
- private boolean containsInDataNodeContainedRule(final String tableName,
final ShardingSphereMetaData schemaMetaData) {
- return
schemaMetaData.getRuleMetaData().findRules(DataNodeContainedRule.class).stream().anyMatch(each
-> each.getAllTables().contains(tableName));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropIndexStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropIndexStatementSchemaRefresher.java
deleted file mode 100644
index c732ca3..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropIndexStatementSchemaRefresher.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.DropIndexStatementHandler;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * Schema refresher for drop index statement.
- */
-public final class DropIndexStatementSchemaRefresher implements
SchemaRefresher<DropIndexStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames, final DropIndexStatement sqlStatement,
final ConfigurationProperties props) {
- Collection<String> indexNames = getIndexNames(sqlStatement);
- Optional<SimpleTableSegment> simpleTableSegment =
DropIndexStatementHandler.getSimpleTableSegment(sqlStatement);
- String tableName = simpleTableSegment.map(tableSegment ->
tableSegment.getTableName().getIdentifier().getValue()).orElse("");
- TableMetaData tableMetaData =
schemaMetaData.getSchema().get(tableName);
- if (!Strings.isNullOrEmpty(tableName)) {
- for (String each : indexNames) {
- tableMetaData.getIndexes().remove(each);
- }
- return;
- }
- for (String each : indexNames) {
- Optional<String> logicTableNameOptional =
findLogicTableName(schemaMetaData.getSchema(), each);
- if (logicTableNameOptional.isPresent()) {
- String logicTableName = logicTableNameOptional.orElse("");
-
Preconditions.checkArgument(!Strings.isNullOrEmpty(logicTableName), "Cannot get
the table name!");
- if (null == tableMetaData) {
- tableMetaData =
schemaMetaData.getSchema().get(logicTableName);
- }
- Preconditions.checkNotNull(tableMetaData, "Cannot get the
table metadata!");
- tableMetaData.getIndexes().remove(each);
- }
- }
- }
-
- private Collection<String> getIndexNames(final DropIndexStatement
dropIndexStatement) {
- return dropIndexStatement.getIndexes().stream().map(each ->
each.getIdentifier().getValue()).collect(Collectors.toCollection(LinkedList::new));
- }
-
- private Optional<String> findLogicTableName(final ShardingSphereSchema
schema, final String logicIndexName) {
- return schema.getAllTableNames().stream().filter(each ->
schema.get(each).getIndexes().containsKey(logicIndexName)).findFirst();
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresher.java
deleted file mode 100644
index d2ae933..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresher.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
-
-import java.util.Collection;
-
-/**
- * Schema refresher for drop table statement.
- */
-public final class DropTableStatementSchemaRefresher implements
SchemaRefresher<DropTableStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames, final DropTableStatement sqlStatement,
final ConfigurationProperties props) {
- sqlStatement.getTables().forEach(each ->
schemaMetaData.getSchema().remove(each.getTableName().getIdentifier().getValue()));
- Collection<MutableDataNodeRule> rules =
schemaMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class);
- for (SimpleTableSegment each : sqlStatement.getTables()) {
- rules.forEach(rule ->
rule.remove(each.getTableName().getIdentifier().getValue()));
- }
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresher.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresher.java
deleted file mode 100644
index 2893418..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresher.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
-
-import java.util.Collection;
-
-/**
- * Schema refresher for drop view statement.
- */
-public final class DropViewStatementSchemaRefresher implements
SchemaRefresher<DropViewStatement> {
-
- @Override
- public void refresh(final ShardingSphereMetaData schemaMetaData, final
Collection<String> logicDataSourceNames, final DropViewStatement sqlStatement,
final ConfigurationProperties props) {
- sqlStatement.getViews().forEach(each ->
schemaMetaData.getSchema().remove(each.getTableName().getIdentifier().getValue()));
- Collection<MutableDataNodeRule> rules =
schemaMetaData.getRuleMetaData().findRules(MutableDataNodeRule.class);
- for (SimpleTableSegment each : sqlStatement.getViews()) {
- rules.forEach(rule ->
rule.remove(each.getTableName().getIdentifier().getValue()));
- }
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterIndexStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterIndexStatementSchemaRefresherTest.java
deleted file mode 100644
index d649e31..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterIndexStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterIndexStatement;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class AlterIndexStatementSchemaRefresherTest {
-
- @Test
- public void refreshAlterIndexStatementWithRenameIndex() throws
SQLException {
- PostgreSQLAlterIndexStatement alterIndexStatement = new
PostgreSQLAlterIndexStatement();
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- SchemaRefresher<AlterIndexStatement> schemaRefresher = new
AlterIndexStatementSchemaRefresher();
- alterIndexStatement.setIndex(new IndexSegment(1, 2, new
IdentifierValue("index")));
- alterIndexStatement.setRenameIndex(new IndexSegment(1, 2, new
IdentifierValue("index_new")));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- schemaRefresher.refresh(metaData, Collections.emptyList(),
alterIndexStatement, new ConfigurationProperties(new Properties()));
- assertFalse(schema.get("t_order").getIndexes().containsKey("index"));
-
assertTrue(schema.get("t_order").getIndexes().containsKey("index_new"));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresherTest.java
deleted file mode 100644
index fac2721..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/AlterTableStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLAlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92AlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerAlterTableStatement;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class AlterTableStatementSchemaRefresherTest {
-
- @Test
- public void refreshForMySQL() throws SQLException {
- refresh(new MySQLAlterTableStatement());
- }
-
- @Test
- public void refreshForOracle() throws SQLException {
- refresh(new OracleAlterTableStatement());
- }
-
- @Test
- public void refreshForPostgreSQL() throws SQLException {
- refresh(new PostgreSQLAlterTableStatement());
- }
-
- @Test
- public void refreshForSQL92() throws SQLException {
- refresh(new SQL92AlterTableStatement());
- }
-
- @Test
- public void refreshForSQLServer() throws SQLException {
- refresh(new SQLServerAlterTableStatement());
- }
-
- @Test
- public void refreshWithRenameTableForPostgreSQL() throws SQLException {
- refreshWithRenameTable(new PostgreSQLAlterTableStatement());
- }
-
- private void refresh(final AlterTableStatement alterTableStatement) throws
SQLException {
- alterTableStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection().getMetaData().getTables(any(), any(),
any(), any())).thenReturn(mock(ResultSet.class));
- SchemaRefresher<AlterTableStatement> schemaRefresher = new
AlterTableStatementSchemaRefresher();
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- schemaRefresher.refresh(metaData, Collections.singletonList("ds"),
alterTableStatement, new ConfigurationProperties(new Properties()));
- assertTrue(schema.containsTable("t_order"));
- }
-
- private void refreshWithRenameTable(final AlterTableStatement
alterTableStatement) throws SQLException {
- alterTableStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- alterTableStatement.setRenameTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_new"))));
- DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection().getMetaData().getTables(any(), any(),
any(), any())).thenReturn(mock(ResultSet.class));
- SchemaRefresher<AlterTableStatement> schemaRefresher = new
AlterTableStatementSchemaRefresher();
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- schemaRefresher.refresh(metaData, Collections.singletonList("ds"),
alterTableStatement, new ConfigurationProperties(new Properties()));
- assertFalse(schema.containsTable("t_order"));
- assertTrue(schema.containsTable("t_order_new"));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateIndexStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateIndexStatementSchemaRefresherTest.java
deleted file mode 100644
index 734e2fb..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateIndexStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerCreateIndexStatement;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class CreateIndexStatementSchemaRefresherTest {
-
- @Test
- public void refreshForMySQL() throws SQLException {
- refresh(new MySQLCreateIndexStatement());
- }
-
- @Test
- public void refreshForOracle() throws SQLException {
- refresh(new OracleCreateIndexStatement());
- }
-
- @Test
- public void refreshForPostgreSQL() throws SQLException {
- refresh(new PostgreSQLCreateIndexStatement());
- }
-
- @Test
- public void refreshForSQLServer() throws SQLException {
- refresh(new SQLServerCreateIndexStatement());
- }
-
- private void refresh(final CreateIndexStatement createIndexStatement)
throws SQLException {
- SchemaRefresher<CreateIndexStatement> schemaRefresher = new
CreateIndexStatementSchemaRefresher();
- createIndexStatement.setIndex(new IndexSegment(1, 2, new
IdentifierValue("t_order_index")));
- createIndexStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- schemaRefresher.refresh(metaData, Collections.emptyList(),
createIndexStatement, new ConfigurationProperties(new Properties()));
-
assertTrue(schema.get("t_order").getIndexes().containsKey("t_order_index"));
- }
-
- @Test
- public void refreshIfIndexIsNullForMySQL() throws SQLException {
- refreshIfIndexIsNull(new MySQLCreateIndexStatement());
- }
-
- @Test
- public void refreshIfIndexIsNullForOracle() throws SQLException {
- refreshIfIndexIsNull(new OracleCreateIndexStatement());
- }
-
- @Test
- public void refreshIfIndexIsNullForPostgreSQL() throws SQLException {
- refreshIfIndexIsNull(new PostgreSQLCreateIndexStatement());
- }
-
- @Test
- public void refreshIfIndexIsNullForSQLServer() throws SQLException {
- refreshIfIndexIsNull(new SQLServerCreateIndexStatement());
- }
-
- private void refreshIfIndexIsNull(final CreateIndexStatement
createIndexStatement) throws SQLException {
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- SchemaRefresher<CreateIndexStatement> schemaRefresher = new
CreateIndexStatementSchemaRefresher();
- createIndexStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
ShardingSphereSchemaBuildUtil.buildSchema());
- schemaRefresher.refresh(metaData, Collections.emptyList(),
createIndexStatement, new ConfigurationProperties(new Properties()));
-
assertFalse(schema.get("t_order").getIndexes().containsKey("t_order_index"));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresherTest.java
deleted file mode 100644
index cd2ccc8..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateTableStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92CreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerCreateTableStatement;
-import org.junit.Test;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class CreateTableStatementSchemaRefresherTest {
-
- @Test
- public void refreshForMySQL() throws SQLException {
- MySQLCreateTableStatement createTableStatement = new
MySQLCreateTableStatement();
- createTableStatement.setContainsNotExistClause(false);
- refresh(createTableStatement);
- }
-
- @Test
- public void refreshForOracle() throws SQLException {
- OracleCreateTableStatement createTableStatement = new
OracleCreateTableStatement();
- refresh(createTableStatement);
- }
-
- @Test
- public void refreshForPostgreSQL() throws SQLException {
- PostgreSQLCreateTableStatement createTableStatement = new
PostgreSQLCreateTableStatement();
- createTableStatement.setContainsNotExistClause(false);
- refresh(createTableStatement);
- }
-
- @Test
- public void refreshForSQL92() throws SQLException {
- SQL92CreateTableStatement createTableStatement = new
SQL92CreateTableStatement();
- refresh(createTableStatement);
- }
-
- @Test
- public void refreshForSQLServer() throws SQLException {
- SQLServerCreateTableStatement createTableStatement = new
SQLServerCreateTableStatement();
- refresh(createTableStatement);
- }
-
- private void refresh(final CreateTableStatement createTableStatement)
throws SQLException {
- createTableStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_0"))));
- DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection().getMetaData().getTables(any(), any(),
any(), any())).thenReturn(mock(ResultSet.class));
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- SchemaRefresher<CreateTableStatement> schemaRefresher = new
CreateTableStatementSchemaRefresher();
- schemaRefresher.refresh(metaData, Collections.singleton("ds"),
createTableStatement, new ConfigurationProperties(new Properties()));
- assertTrue(schema.containsTable("t_order_0"));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresherTest.java
deleted file mode 100644
index 6365419..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/CreateViewStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateViewStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateViewStatement;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.mockito.Mockito.mock;
-
-public final class CreateViewStatementSchemaRefresherTest {
-
- @Test
- public void refreshWithUnConfiguredForMySQL() throws SQLException {
- refreshWithUnConfigured(new MySQLCreateViewStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForPostgreSQL() throws SQLException {
- refreshWithUnConfigured(new PostgreSQLCreateViewStatement());
- }
-
- private void refreshWithUnConfigured(final CreateViewStatement
createViewStatement) throws SQLException {
- createViewStatement.setView(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_item_0"))));
- SchemaRefresher<CreateViewStatement> schemaRefresher = new
CreateViewStatementSchemaRefresher();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
ShardingSphereSchemaBuildUtil.buildSchema());
- schemaRefresher.refresh(metaData,
Collections.singletonList("t_order_item"), createViewStatement, new
ConfigurationProperties(new Properties()));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropIndexStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropIndexStatementSchemaRefresherTest.java
deleted file mode 100644
index b653845..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropIndexStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLDropIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerDropIndexStatement;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.mock;
-
-public final class DropIndexStatementSchemaRefresherTest {
-
- @Test
- public void refreshForMySQL() throws SQLException {
- MySQLDropIndexStatement dropIndexStatement = new
MySQLDropIndexStatement();
- dropIndexStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- refresh(dropIndexStatement);
- }
-
- @Test
- public void refreshForSQLServer() throws SQLException {
- SQLServerDropIndexStatement dropIndexStatement = new
SQLServerDropIndexStatement();
- dropIndexStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- refresh(dropIndexStatement);
- }
-
- private void refresh(final DropIndexStatement dropIndexStatement) throws
SQLException {
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- dropIndexStatement.getIndexes().add(new IndexSegment(1, 2, new
IdentifierValue("index")));
- SchemaRefresher<DropIndexStatement> metaDataRefreshStrategy = new
DropIndexStatementSchemaRefresher();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- metaDataRefreshStrategy.refresh(metaData, Collections.emptyList(),
dropIndexStatement, new ConfigurationProperties(new Properties()));
- assertFalse(schema.get("t_order").getIndexes().containsKey("index"));
- }
-
- @Test
- public void assertRemoveIndexesForMySQL() throws SQLException {
- MySQLDropIndexStatement dropIndexStatement = new
MySQLDropIndexStatement();
- dropIndexStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- assertRemoveIndexes(dropIndexStatement);
- }
-
- @Test
- public void assertRemoveIndexesForSQLServer() throws SQLException {
- SQLServerDropIndexStatement dropIndexStatement = new
SQLServerDropIndexStatement();
- dropIndexStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- assertRemoveIndexes(dropIndexStatement);
- }
-
- private void assertRemoveIndexes(final DropIndexStatement
dropIndexStatement) throws SQLException {
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- dropIndexStatement.getIndexes().add(new IndexSegment(1, 2, new
IdentifierValue("index")));
- dropIndexStatement.getIndexes().add(new IndexSegment(2, 3, new
IdentifierValue("t_order_index")));
- dropIndexStatement.getIndexes().add(new IndexSegment(3, 4, new
IdentifierValue("order_id_index")));
- Map<String, IndexMetaData> actualIndex =
schema.get("t_order").getIndexes();
- actualIndex.put("t_order_index", new IndexMetaData("t_order_index"));
- actualIndex.put("order_id_index", new IndexMetaData("order_id_index"));
- SchemaRefresher<DropIndexStatement> schemaRefresher = new
DropIndexStatementSchemaRefresher();
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- schemaRefresher.refresh(metaData, Collections.emptyList(),
dropIndexStatement, new ConfigurationProperties(new Properties()));
- assertFalse(schema.get("t_order").getIndexes().containsKey("index"));
-
assertFalse(schema.get("t_order").getIndexes().containsKey("t_order_index"));
-
assertFalse(schema.get("t_order").getIndexes().containsKey("order_id_index"));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresherTest.java
deleted file mode 100644
index d28ea77..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropTableStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLDropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92DropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerDropTableStatement;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.mock;
-
-public final class DropTableStatementSchemaRefresherTest {
-
- @Test
- public void refreshForMySQL() throws SQLException {
- refresh(new MySQLDropTableStatement());
- }
-
- @Test
- public void refreshForOracle() throws SQLException {
- refresh(new OracleDropTableStatement());
- }
-
- @Test
- public void refreshForPostgreSQL() throws SQLException {
- refresh(new PostgreSQLDropTableStatement());
- }
-
- @Test
- public void refreshForSQL92() throws SQLException {
- refresh(new SQL92DropTableStatement());
- }
-
- @Test
- public void refreshForSQLServer() throws SQLException {
- refresh(new SQLServerDropTableStatement());
- }
-
- private void refresh(final DropTableStatement dropTableStatement) throws
SQLException {
- ShardingSphereSchema schema =
ShardingSphereSchemaBuildUtil.buildSchema();
- SchemaRefresher<DropTableStatement> schemaRefresher = new
DropTableStatementSchemaRefresher();
- dropTableStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
schema);
- schemaRefresher.refresh(metaData, Collections.emptyList(),
dropTableStatement, new ConfigurationProperties(new Properties()));
- assertFalse(schema.containsTable("t_order"));
- }
-
- @Test
- public void refreshWithUnConfiguredForMySQL() throws SQLException {
- refreshWithUnConfigured(new MySQLDropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForOracle() throws SQLException {
- refreshWithUnConfigured(new OracleDropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForPostgreSQL() throws SQLException {
- refreshWithUnConfigured(new PostgreSQLDropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForSQL92() throws SQLException {
- refreshWithUnConfigured(new SQL92DropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForSQLServer() throws SQLException {
- refreshWithUnConfigured(new SQLServerDropTableStatement());
- }
-
- private void refreshWithUnConfigured(final DropTableStatement
dropTableStatement) throws SQLException {
- SchemaRefresher<DropTableStatement> schemaRefresher = new
DropTableStatementSchemaRefresher();
- dropTableStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_item"))));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
ShardingSphereSchemaBuildUtil.buildSchema());
- schemaRefresher.refresh(metaData,
Collections.singletonList("t_order_item"), dropTableStatement, new
ConfigurationProperties(new Properties()));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresherTest.java
deleted file mode 100644
index 93dc11a..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/DropViewStatementSchemaRefresherTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLDropViewStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropViewStatement;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.mockito.Mockito.mock;
-
-public final class DropViewStatementSchemaRefresherTest {
-
- @Test
- public void refreshWithUnConfiguredForMySQL() throws SQLException {
- refreshWithUnConfigured(new MySQLDropViewStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForPostgreSQL() throws SQLException {
- refreshWithUnConfigured(new PostgreSQLDropViewStatement());
- }
-
- private void refreshWithUnConfigured(final DropViewStatement
dropViewStatement) throws SQLException {
- SchemaRefresher<DropViewStatement> schemaRefresher = new
DropViewStatementSchemaRefresher();
- dropViewStatement.getViews().add(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_item"))));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
ShardingSphereSchemaBuildUtil.buildSchema());
- schemaRefresher.refresh(metaData,
Collections.singletonList("t_order_item"), dropViewStatement, new
ConfigurationProperties(new Properties()));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/ShardingSphereSchemaBuildUtil.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/ShardingSphereSchemaBuildUtil.java
deleted file mode 100644
index 7ca85f9..0000000
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/refresher/type/ShardingSphereSchemaBuildUtil.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.metadata.schema.refresher.type;
-
-import com.google.common.collect.ImmutableMap;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-
-import java.util.Collections;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingSphereSchemaBuildUtil {
-
- /**
- * Build schema.
- *
- * @return ShardingSphere schema
- */
- public static ShardingSphereSchema buildSchema() {
- return new ShardingSphereSchema(ImmutableMap.of("t_order",
- new TableMetaData("t_order", Collections.singletonList(new
ColumnMetaData("order_id", 1, false, false, false)),
Collections.singletonList(new IndexMetaData("index")))));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresherFactory.java
b/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresherFactory.java
deleted file mode 100644
index 2c5866e..0000000
---
a/shardingsphere-infra/shardingsphere-infra-context/src/main/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresherFactory.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.context.refresher;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.metadata.MetaDataRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.AlterIndexStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.AlterTableStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateIndexStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateTableStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateViewStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.DropIndexStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.DropTableStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.metadata.schema.refresher.type.DropViewStatementSchemaRefresher;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type.AlterTableFederationMetaDataRefresher;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type.CreateTableFederationMetaDataRefresher;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type.DropTableFederationMetaDataRefresher;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropViewStatement;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * ShardingSphere meta data refresher factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MetaDataRefresherFactory {
-
- private static final Map<Class<?>, Collection<MetaDataRefresher>> REGISTRY
= new HashMap<>();
-
- static {
- REGISTRY.put(CreateTableStatement.class, new LinkedHashSet<>());
- REGISTRY.put(AlterTableStatement.class, new LinkedHashSet<>());
- REGISTRY.put(DropTableStatement.class, new LinkedHashSet<>());
- REGISTRY.put(CreateIndexStatement.class, new LinkedHashSet<>());
- REGISTRY.put(AlterIndexStatement.class, new LinkedHashSet<>());
- REGISTRY.put(DropIndexStatement.class, new LinkedHashSet<>());
- REGISTRY.put(CreateViewStatement.class, new LinkedHashSet<>());
- REGISTRY.put(DropViewStatement.class, new LinkedHashSet<>());
- REGISTRY.get(CreateTableStatement.class).add(new
CreateTableStatementSchemaRefresher());
- REGISTRY.get(CreateTableStatement.class).add(new
CreateTableFederationMetaDataRefresher());
- REGISTRY.get(AlterTableStatement.class).add(new
AlterTableStatementSchemaRefresher());
- REGISTRY.get(AlterTableStatement.class).add(new
AlterTableFederationMetaDataRefresher());
- REGISTRY.get(DropTableStatement.class).add(new
DropTableStatementSchemaRefresher());
- REGISTRY.get(DropTableStatement.class).add(new
DropTableFederationMetaDataRefresher());
- REGISTRY.get(CreateIndexStatement.class).add(new
CreateIndexStatementSchemaRefresher());
- REGISTRY.get(AlterIndexStatement.class).add(new
AlterIndexStatementSchemaRefresher());
- REGISTRY.get(DropIndexStatement.class).add(new
DropIndexStatementSchemaRefresher());
- REGISTRY.get(CreateViewStatement.class).add(new
CreateViewStatementSchemaRefresher());
- REGISTRY.get(DropViewStatement.class).add(new
DropViewStatementSchemaRefresher());
- }
-
- /**
- * Create new instance of schema refresher.
- *
- * @param sqlStatement SQL statement
- * @return instance of schema refresher
- */
- public static Collection<MetaDataRefresher> newInstance(final SQLStatement
sqlStatement) {
- for (Entry<Class<?>, Collection<MetaDataRefresher>> entry :
REGISTRY.entrySet()) {
- if (entry.getKey().isAssignableFrom(sqlStatement.getClass())) {
- return entry.getValue();
- }
- }
- return Collections.emptyList();
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresherFactoryTest.java
b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresherFactoryTest.java
deleted file mode 100644
index c2505dd..0000000
---
a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/MetaDataRefresherFactoryTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.context.refresher;
-
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class MetaDataRefresherFactoryTest {
-
- @Test
- public void assertNewInstanceWithCreateTableStatement() {
-
assertThat(MetaDataRefresherFactory.newInstance(mock(CreateTableStatement.class)).size(),
is(2));
- }
-
- @Test
- public void assertNewInstanceWithAlterTableStatement() {
-
assertThat(MetaDataRefresherFactory.newInstance(mock(AlterTableStatement.class)).size(),
is(2));
- }
-
- @Test
- public void assertNewInstanceWithDropTableStatement() {
-
assertThat(MetaDataRefresherFactory.newInstance(mock(DropTableStatement.class)).size(),
is(2));
- }
-
- @Test
- public void assertNewInstanceWithCreateIndexStatement() {
-
assertThat(MetaDataRefresherFactory.newInstance(mock(CreateIndexStatement.class)).size(),
is(1));
- }
-
- @Test
- public void assertNewInstanceWithDropIndexStatement() {
-
assertThat(MetaDataRefresherFactory.newInstance(mock(DropIndexStatement.class)).size(),
is(1));
- }
-
- @Test
- public void assertNewInstanceWithAlterIndexStatement() {
-
assertThat(MetaDataRefresherFactory.newInstance(mock(AlterIndexStatement.class)).size(),
is(1));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/FederationMetaDataRefresher.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/FederationMetaDataRefresher.java
deleted file mode 100644
index c9c3e04..0000000
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/FederationMetaDataRefresher.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData;
-import org.apache.shardingsphere.infra.metadata.MetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
-
-/**
- * Federation meta data refresher.
- *
- * @param <T> type of SQL statement
- */
-public interface FederationMetaDataRefresher<T extends SQLStatement> extends
MetaDataRefresher {
-
- /**
- * Refresh federation meta data.
- *
- * @param schema federation schema to be refreshed
- * @param logicDataSourceNames logic data source names
- * @param sqlStatement SQL statement
- * @param schemaMetaData meta data
- * @param props props
- * @throws SQLException SQL exception
- */
- void refresh(FederationSchemaMetaData schema, Collection<String>
logicDataSourceNames, T sqlStatement, ShardingSphereMetaData schemaMetaData,
- ConfigurationProperties props) throws SQLException;
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/AlterTableFederationMetaDataRefresher.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/AlterTableFederationMetaDataRefresher.java
deleted file mode 100644
index 82fc4d3..0000000
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/AlterTableFederationMetaDataRefresher.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.FederationMetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-
-/**
- * Federation meta data refresher for alter table.
- */
-public final class AlterTableFederationMetaDataRefresher implements
FederationMetaDataRefresher<AlterTableStatement> {
-
- @Override
- public void refresh(final FederationSchemaMetaData schema, final
Collection<String> logicDataSourceNames, final AlterTableStatement
sqlStatement,
- final ShardingSphereMetaData schemaMetaData, final
ConfigurationProperties props) throws SQLException {
- SchemaBuilderMaterials materials = new
SchemaBuilderMaterials(schemaMetaData.getResource().getDatabaseType(),
schemaMetaData.getResource().getDataSources(),
- schemaMetaData.getRuleMetaData().getRules(), props);
- String tableName =
sqlStatement.getTable().getTableName().getIdentifier().getValue();
- if (sqlStatement.getRenameTable().isPresent()) {
- String renameTableName =
sqlStatement.getRenameTable().get().getTableName().getIdentifier().getValue();
- buildTableMetaData(materials,
renameTableName).ifPresent(schema::put);
- schema.remove(tableName);
- } else {
- buildTableMetaData(materials, tableName).ifPresent(schema::put);
- }
- }
-
- private Optional<TableMetaData> buildTableMetaData(final
SchemaBuilderMaterials materials, final String tableName) throws SQLException {
- return
Optional.ofNullable(TableMetaDataBuilder.load(Collections.singletonList(tableName),
materials).get(tableName))
- .map(each ->
TableMetaDataBuilder.decorateFederationTableMetaData(each,
materials.getRules()));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/CreateTableFederationMetaDataRefresher.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/CreateTableFederationMetaDataRefresher.java
deleted file mode 100644
index 6ffb3be..0000000
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/CreateTableFederationMetaDataRefresher.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.FederationMetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.TableMetaDataBuilder;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-
-/**
- * Federation meta data refresher for create table.
- */
-public final class CreateTableFederationMetaDataRefresher implements
FederationMetaDataRefresher<CreateTableStatement> {
-
- @Override
- public void refresh(final FederationSchemaMetaData schema, final
Collection<String> logicDataSourceNames, final CreateTableStatement
sqlStatement,
- final ShardingSphereMetaData schemaMetaData, final
ConfigurationProperties props) throws SQLException {
- SchemaBuilderMaterials materials = new
SchemaBuilderMaterials(schemaMetaData.getResource().getDatabaseType(),
schemaMetaData.getResource().getDataSources(),
- schemaMetaData.getRuleMetaData().getRules(), props);
- String tableName =
sqlStatement.getTable().getTableName().getIdentifier().getValue();
-
Optional.ofNullable(TableMetaDataBuilder.load(Collections.singletonList(tableName),
materials).get(tableName))
- .map(each ->
TableMetaDataBuilder.decorateFederationTableMetaData(each,
materials.getRules())).ifPresent(schema::put);
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/DropTableFederationMetaDataRefresher.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/DropTableFederationMetaDataRefresher.java
deleted file mode 100644
index 56606d2..0000000
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/main/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/type/DropTableFederationMetaDataRefresher.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type;
-
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.FederationMetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
-
-import java.sql.SQLException;
-import java.util.Collection;
-
-/**
- * Federation meta data refresher for drop table.
- */
-public final class DropTableFederationMetaDataRefresher implements
FederationMetaDataRefresher<DropTableStatement> {
-
- @Override
- public void refresh(final FederationSchemaMetaData schema, final
Collection<String> logicDataSourceNames, final DropTableStatement sqlStatement,
- final ShardingSphereMetaData schemaMetaData, final
ConfigurationProperties props) throws SQLException {
- sqlStatement.getTables().forEach(each ->
schema.remove(each.getTableName().getIdentifier().getValue()));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/AlterTableFederationMetaDataRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/AlterTableFederationMetaDataRefresherTest.java
deleted file mode 100644
index 2858b1d..0000000
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/AlterTableFederationMetaDataRefresherTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher;
-
-import com.google.common.collect.ImmutableMap;
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.fixture.CommonFixtureRule;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type.AlterTableFederationMetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLAlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLAlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92AlterTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerAlterTableStatement;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class AlterTableFederationMetaDataRefresherTest {
-
- @Test
- public void refreshTable() throws SQLException {
- refreshTable(new MySQLAlterTableStatement());
- refreshTable(new OracleAlterTableStatement());
- refreshTable(new PostgreSQLAlterTableStatement());
- refreshTable(new SQLServerAlterTableStatement());
- refreshTable(new SQL92AlterTableStatement());
- }
-
- private void refreshTable(final AlterTableStatement alterTableStatement)
throws SQLException {
- alterTableStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection().getMetaData().getTables(any(), any(),
any(), any())).thenReturn(mock(ResultSet.class));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
buildSchema());
- FederationMetaDataRefresher<AlterTableStatement>
federationMetaDataRefresher = new AlterTableFederationMetaDataRefresher();
- FederationSchemaMetaData schema = buildFederationSchema();
- federationMetaDataRefresher.refresh(schema,
Collections.singletonList("ds"), alterTableStatement, metaData,
mock(ConfigurationProperties.class));
- assertTrue(schema.getTables().containsKey("t_order"));
- }
-
- @Test
- public void renameTable() throws SQLException {
- renameTable(new MySQLAlterTableStatement());
- renameTable(new OracleAlterTableStatement());
- renameTable(new PostgreSQLAlterTableStatement());
- renameTable(new SQLServerAlterTableStatement());
- renameTable(new SQL92AlterTableStatement());
- }
-
- private void renameTable(final AlterTableStatement alterTableStatement)
throws SQLException {
- alterTableStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- alterTableStatement.setRenameTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_new"))));
- DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection().getMetaData().getTables(any(), any(),
any(), any())).thenReturn(mock(ResultSet.class));
- ShardingSphereResource resource = mock(ShardingSphereResource.class);
- Map<String, DataSource> dataSourceMap = new HashMap<>();
- dataSourceMap.put("ds", dataSource);
- when(resource.getDataSources()).thenReturn(dataSourceMap);
- when(resource.getDatabaseType()).thenReturn(new MySQLDatabaseType());
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
- when(metaData.getResource()).thenReturn(resource);
-
when(metaData.getRuleMetaData()).thenReturn(mock(ShardingSphereRuleMetaData.class));
-
when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.singletonList(new
CommonFixtureRule()));
- FederationMetaDataRefresher<AlterTableStatement>
federationMetaDataRefresher = new AlterTableFederationMetaDataRefresher();
- FederationSchemaMetaData schema = buildFederationSchema();
- federationMetaDataRefresher.refresh(schema,
Collections.singletonList("ds"), alterTableStatement, metaData,
mock(ConfigurationProperties.class));
- assertFalse(schema.getTables().containsKey("t_order"));
- assertTrue(schema.getTables().containsKey("t_order_new"));
- }
-
- private FederationSchemaMetaData buildFederationSchema() {
- Map<String, TableMetaData> metaData = ImmutableMap.of("t_order", new
TableMetaData("t_order", Collections.singletonList(new
ColumnMetaData("order_id", 1, false, false, false)),
- Collections.singletonList(new
IndexMetaData("index"))));
- return new FederationSchemaMetaData("t_order", metaData);
- }
-
- private ShardingSphereSchema buildSchema() {
- return new ShardingSphereSchema(ImmutableMap.of("t_order",
- new TableMetaData("t_order", Collections.singletonList(new
ColumnMetaData("order_id", 1, false, false, false)),
Collections.singletonList(new IndexMetaData("index")))));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/CreateTableFederationMetaDataRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/CreateTableFederationMetaDataRefresherTest.java
deleted file mode 100644
index 75b9893..0000000
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/CreateTableFederationMetaDataRefresherTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher;
-
-import com.google.common.collect.ImmutableMap;
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type.CreateTableFederationMetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
-import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92CreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerCreateTableStatement;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import javax.sql.DataSource;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Map;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class CreateTableFederationMetaDataRefresherTest {
-
- @Mock
- private SchemaBuilderMaterials materials;
-
- @Test
- public void refreshForMySQL() throws SQLException {
- refreshTableWithRule(new MySQLCreateTableStatement());
- }
-
- @Test
- public void refreshForOracle() throws SQLException {
- refreshTableWithRule(new OracleCreateTableStatement());
- }
-
- @Test
- public void refreshForPostgreSQL() throws SQLException {
- refreshTableWithRule(new PostgreSQLCreateTableStatement());
- }
-
- @Test
- public void refreshForSQL92() throws SQLException {
- refreshTableWithRule(new SQL92CreateTableStatement());
- }
-
- @Test
- public void refreshForSQLServer() throws SQLException {
- refreshTableWithRule(new SQLServerCreateTableStatement());
- }
-
- private void refreshTableWithRule(final CreateTableStatement
createTableStatement) throws SQLException {
- createTableStatement.setTable(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
- when(dataSource.getConnection().getMetaData().getTables(any(), any(),
any(), any())).thenReturn(mock(ResultSet.class));
- ShardingSphereMetaData metaData = new ShardingSphereMetaData("",
mock(ShardingSphereResource.class), mock(ShardingSphereRuleMetaData.class),
buildSchema());
- FederationMetaDataRefresher<CreateTableStatement>
federationMetaDataRefresher = new CreateTableFederationMetaDataRefresher();
- FederationSchemaMetaData schema = buildFederationSchema();
- federationMetaDataRefresher.refresh(schema,
Collections.singletonList("ds"), createTableStatement, metaData,
mock(ConfigurationProperties.class));
- assertTrue(schema.getTables().containsKey("t_order"));
-
assertTrue(schema.getTables().get("t_order").getColumnNames().contains("order_id"));
- }
-
- private FederationSchemaMetaData buildFederationSchema() {
- Map<String, TableMetaData> metaData = ImmutableMap.of("t_order", new
TableMetaData("t_order", Collections.singletonList(new
ColumnMetaData("order_id", 1, false, false, false)),
- Collections.singletonList(new IndexMetaData("index"))));
- return new FederationSchemaMetaData("t_order", metaData);
- }
-
- private ShardingSphereSchema buildSchema() {
- return new ShardingSphereSchema(ImmutableMap.of("t_order",
- new TableMetaData("t_order", Collections.singletonList(new
ColumnMetaData("order_id", 1, false, false, false)),
Collections.singletonList(new IndexMetaData("index")))));
- }
-}
diff --git
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/DropTableFederationMetaDataRefresherTest.java
b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/DropTableFederationMetaDataRefresherTest.java
deleted file mode 100644
index 1b80bea..0000000
---
a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-optimizer/src/test/java/org/apache/shardingsphere/infra/federation/optimizer/metadata/refresher/DropTableFederationMetaDataRefresherTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher;
-
-import com.google.common.collect.ImmutableMap;
-import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationSchemaMetaData;
-import
org.apache.shardingsphere.infra.federation.optimizer.metadata.refresher.type.DropTableFederationMetaDataRefresher;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLDropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLDropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.ddl.SQL92DropTableStatement;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerDropTableStatement;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Map;
-
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Mockito.mock;
-
-public final class DropTableFederationMetaDataRefresherTest {
-
- @Test
- public void refreshForMySQL() throws SQLException {
- refresh(new MySQLDropTableStatement());
- }
-
- @Test
- public void refreshForOracle() throws SQLException {
- refresh(new OracleDropTableStatement());
- }
-
- @Test
- public void refreshForPostgreSQL() throws SQLException {
- refresh(new PostgreSQLDropTableStatement());
- }
-
- @Test
- public void refreshForSQL92() throws SQLException {
- refresh(new SQL92DropTableStatement());
- }
-
- @Test
- public void refreshForSQLServer() throws SQLException {
- refresh(new SQLServerDropTableStatement());
- }
-
- private void refresh(final DropTableStatement dropTableStatement) throws
SQLException {
- FederationSchemaMetaData schema = buildSchema();
- FederationMetaDataRefresher<DropTableStatement> schemaRefresher = new
DropTableFederationMetaDataRefresher();
- dropTableStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order"))));
- schemaRefresher.refresh(schema, Collections.emptyList(),
dropTableStatement, mock(ShardingSphereMetaData.class),
mock(ConfigurationProperties.class));
- assertFalse(schema.getTables().containsKey("t_order"));
- }
-
- @Test
- public void refreshWithUnConfiguredForMySQL() throws SQLException {
- refreshWithUnConfigured(new MySQLDropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForOracle() throws SQLException {
- refreshWithUnConfigured(new OracleDropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForPostgreSQL() throws SQLException {
- refreshWithUnConfigured(new PostgreSQLDropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForSQL92() throws SQLException {
- refreshWithUnConfigured(new SQL92DropTableStatement());
- }
-
- @Test
- public void refreshWithUnConfiguredForSQLServer() throws SQLException {
- refreshWithUnConfigured(new SQLServerDropTableStatement());
- }
-
- private void refreshWithUnConfigured(final DropTableStatement
dropTableStatement) throws SQLException {
- FederationSchemaMetaData schema = buildSchema();
- FederationMetaDataRefresher<DropTableStatement> schemaRefresher = new
DropTableFederationMetaDataRefresher();
- dropTableStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(1, 3, new IdentifierValue("t_order_item"))));
- schemaRefresher.refresh(schema,
Collections.singletonList("t_order_item"), dropTableStatement,
mock(ShardingSphereMetaData.class), mock(ConfigurationProperties.class));
- }
-
- private FederationSchemaMetaData buildSchema() {
- Map<String, TableMetaData> metaData = ImmutableMap.of("t_order", new
TableMetaData("t_order", Collections.singletonList(new
ColumnMetaData("order_id", 1, false, false, false)),
- Collections.singletonList(new IndexMetaData("index"))));
- return new FederationSchemaMetaData("t_order", metaData);
- }
-}