You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/04/02 09:02:21 UTC

[GitHub] [incubator-shardingsphere] yu199195 opened a new pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

yu199195 opened a new pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048
 
 
   i find sharding-jdbc and sharding-proxy have same code for metaDataRefresh after execute ddl.
   
   so i remove MetaDataRefreshStrategy  from Sharding-jdbc-core to ShardingSphere-common.
   
   then sharding-jdbc ,sharding-proxy can use same code.
   
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402185432
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/refresh/MetaDataRefreshStrategy.java
 ##########
 @@ -15,26 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shardingjdbc.jdbc.refreh;
+package org.apache.shardingsphere.underlying.common.metadata.refresh;
 
-import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
 import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 
 import java.sql.SQLException;
 
 /**
  * Meta data refresh strategy.
- * 
+ *
  * @param <T> type of SQL statement context
  */
 public interface MetaDataRefreshStrategy<T extends SQLStatementContext> {
     
     /**
      * Refresh meta data.
      *
-     * @param shardingRuntimeContext sharding runtime context
+     * @param metaData sharding sphere meta data
 
 Review comment:
   sharding sphere only one word

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 closed pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 closed pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402193143
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/refresh/MetaDataRefreshStrategy.java
 ##########
 @@ -15,26 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shardingjdbc.jdbc.refreh;
+package org.apache.shardingsphere.underlying.common.metadata.refresh;
 
-import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
 import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 
 import java.sql.SQLException;
 
 /**
  * Meta data refresh strategy.
- * 
+ *
  * @param <T> type of SQL statement context
  */
 public interface MetaDataRefreshStrategy<T extends SQLStatementContext> {
     
     /**
      * Refresh meta data.
      *
-     * @param shardingRuntimeContext sharding runtime context
+     * @param metaData sharding sphere meta data
 
 Review comment:
   fix it

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402192964
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/CreateTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,52 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.CreateTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class CreateTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<CreateTableStatementContext> metaDataRefreshStrategy = new CreateTableStatementMetaDataRefreshStrategy();
+        CreateTableStatement createTableStatement = new CreateTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order_0"))));
+        CreateTableStatementContext createTableStatementContext = new CreateTableStatementContext(createTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), createTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index"))));
+        assertThat(getMetaData().getSchema().containsTable("t_order_0"), is(true));
+    }
+}
+
+
 
 Review comment:
   fix it

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] coveralls edited a comment on issue #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#issuecomment-607734550
 
 
   ## Pull Request Test Coverage Report for [Build 10799](https://coveralls.io/builds/29793318)
   
   * **12** of **24**   **(50.0%)**  changed or added relevant lines in **7** files are covered.
   * No unchanged relevant lines lost coverage.
   * Overall coverage increased (+**0.2%**) to **57.521%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/impl/ShardingSchema.java](https://coveralls.io/builds/29793318/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2Fimpl%2FShardingSchema.java#L155) | 0 | 3 | 0.0%
   | [sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/executor/AbstractStatementExecutor.java](https://coveralls.io/builds/29793318/source?filename=sharding-jdbc%2Fsharding-jdbc-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingjdbc%2Fexecutor%2FAbstractStatementExecutor.java#L158) | 0 | 9 | 0.0%
   <!-- | **Total:** | **12** | **24** | **50.0%** | -->
   
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/29793318/badge)](https://coveralls.io/builds/29793318) |
   | :-- | --: |
   | Change from base [Build 10791](https://coveralls.io/builds/29791061): |  0.2% |
   | Covered Lines: | 11720 |
   | Relevant Lines: | 20375 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402206552
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/CreateTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.CreateTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class CreateTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<CreateTableStatementContext> metaDataRefreshStrategy = new CreateTableStatementMetaDataRefreshStrategy();
+        CreateTableStatement createTableStatement = new CreateTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order_0"))));
+        CreateTableStatementContext createTableStatementContext = new CreateTableStatementContext(createTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), createTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index"))));
+        assertThat(getMetaData().getSchema().containsTable("t_order_0"), is(true));
+    }
+}
 
 Review comment:
   let an empty line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402185553
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/refresh/MetaDataRefreshStrategy.java
 ##########
 @@ -15,26 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shardingjdbc.jdbc.refreh;
+package org.apache.shardingsphere.underlying.common.metadata.refresh;
 
-import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
 import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 
 import java.sql.SQLException;
 
 /**
  * Meta data refresh strategy.
- * 
 
 Review comment:
   keep original

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402206989
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/refresh/MetaDataRefreshStrategy.java
 ##########
 @@ -15,26 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shardingjdbc.jdbc.refreh;
+package org.apache.shardingsphere.underlying.common.metadata.refresh;
 
-import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
 import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 
 import java.sql.SQLException;
 
 /**
  * Meta data refresh strategy.
- * 
+ *
  * @param <T> type of SQL statement context
  */
 public interface MetaDataRefreshStrategy<T extends SQLStatementContext> {
     
     /**
      * Refresh meta data.
      *
-     * @param shardingRuntimeContext sharding runtime context
+     * @param metaData ShardingSphere meta data
      * @param sqlStatementContext SQL statement context
+     * @param callback callback
      * @throws SQLException SQL exception
      */
-    void refreshMetaData(ShardingRuntimeContext shardingRuntimeContext, T sqlStatementContext) throws SQLException;
+    void refreshMetaData(ShardingSphereMetaData metaData, T sqlStatementContext, TableMetaDataLoaderCallback callback) throws SQLException;
 }
 
 Review comment:
   let an empty line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] coveralls edited a comment on issue #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#issuecomment-607734550
 
 
   ## Pull Request Test Coverage Report for [Build 10798](https://coveralls.io/builds/29792790)
   
   * **12** of **24**   **(50.0%)**  changed or added relevant lines in **7** files are covered.
   * No unchanged relevant lines lost coverage.
   * Overall coverage increased (+**0.2%**) to **57.521%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/impl/ShardingSchema.java](https://coveralls.io/builds/29792790/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2Fimpl%2FShardingSchema.java#L155) | 0 | 3 | 0.0%
   | [sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/executor/AbstractStatementExecutor.java](https://coveralls.io/builds/29792790/source?filename=sharding-jdbc%2Fsharding-jdbc-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingjdbc%2Fexecutor%2FAbstractStatementExecutor.java#L158) | 0 | 9 | 0.0%
   <!-- | **Total:** | **12** | **24** | **50.0%** | -->
   
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/29792790/badge)](https://coveralls.io/builds/29792790) |
   | :-- | --: |
   | Change from base [Build 10791](https://coveralls.io/builds/29791061): |  0.2% |
   | Covered Lines: | 11720 |
   | Relevant Lines: | 20375 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402207129
 
 

 ##########
 File path: sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/executor/AbstractStatementExecutor.java
 ##########
 @@ -150,7 +155,19 @@ private void refreshMetaDataIfNeeded(final ShardingRuntimeContext runtimeContext
         }
         Optional<MetaDataRefreshStrategy> refreshStrategy = MetaDataRefreshStrategyFactory.newInstance(sqlStatementContext);
         if (refreshStrategy.isPresent()) {
-            refreshStrategy.get().refreshMetaData(runtimeContext, sqlStatementContext);
+            refreshStrategy.get().refreshMetaData(runtimeContext.getMetaData(), sqlStatementContext, this::loadTableMeta);
         }
     }
+    
+    private TableMetaData loadTableMeta(final String tableName) throws SQLException {
+        ShardingRule shardingRule = connection.getRuntimeContext().getRule();
+        int maxConnectionsSizePerQuery = connection.getRuntimeContext().getProperties().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
+        boolean isCheckingMetaData = connection.getRuntimeContext().getProperties().<Boolean>getValue(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED);
+        TableMetaData result = new ShardingMetaDataLoader(connection.getDataSourceMap(), shardingRule, maxConnectionsSizePerQuery, isCheckingMetaData).load(tableName, databaseType);
+        result = new ShardingTableMetaDataDecorator().decorate(result, tableName, shardingRule);
+        if (!shardingRule.getEncryptRule().getEncryptTableNames().isEmpty()) {
+            result = new EncryptTableMetaDataDecorator().decorate(result, tableName, shardingRule.getEncryptRule());
+        }
+        return result;
+    }
 }
 
 Review comment:
   let an empty line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402193857
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/AlterTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,52 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.AlterTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.AlterTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class AlterTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<AlterTableStatementContext> metaDataRefreshStrategy = new AlterTableStatementMetaDataRefreshStrategy();
+        AlterTableStatement alterTableStatement = new AlterTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order"))));
+        AlterTableStatementContext alterTableStatementContext = new AlterTableStatementContext(alterTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), alterTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index_alter"))));
+        assertThat(getMetaData().getSchema().get("t_order").getIndexes().containsKey("index_alter"), is(true));
+    }
+}
+
+
 
 Review comment:
   fit it

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402193736
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/refresh/MetaDataRefreshStrategy.java
 ##########
 @@ -15,26 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shardingjdbc.jdbc.refreh;
+package org.apache.shardingsphere.underlying.common.metadata.refresh;
 
-import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
 import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 
 import java.sql.SQLException;
 
 /**
  * Meta data refresh strategy.
- * 
 
 Review comment:
   There's an extra space,now it not need

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402212890
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/metadata/refresh/MetaDataRefreshStrategy.java
 ##########
 @@ -15,26 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.shardingjdbc.jdbc.refreh;
+package org.apache.shardingsphere.underlying.common.metadata.refresh;
 
-import org.apache.shardingsphere.shardingjdbc.jdbc.core.context.ShardingRuntimeContext;
 import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData;
 
 import java.sql.SQLException;
 
 /**
  * Meta data refresh strategy.
- * 
+ *
  * @param <T> type of SQL statement context
  */
 public interface MetaDataRefreshStrategy<T extends SQLStatementContext> {
     
     /**
      * Refresh meta data.
      *
-     * @param shardingRuntimeContext sharding runtime context
+     * @param metaData ShardingSphere meta data
      * @param sqlStatementContext SQL statement context
+     * @param callback callback
      * @throws SQLException SQL exception
      */
-    void refreshMetaData(ShardingRuntimeContext shardingRuntimeContext, T sqlStatementContext) throws SQLException;
+    void refreshMetaData(ShardingSphereMetaData metaData, T sqlStatementContext, TableMetaDataLoaderCallback callback) throws SQLException;
 }
 
 Review comment:
   fix

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] coveralls commented on issue #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
coveralls commented on issue #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#issuecomment-607734550
 
 
   ## Pull Request Test Coverage Report for [Build 10793](https://coveralls.io/builds/29791463)
   
   * **12** of **24**   **(50.0%)**  changed or added relevant lines in **7** files are covered.
   * No unchanged relevant lines lost coverage.
   * Overall coverage increased (+**0.2%**) to **57.521%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [sharding-proxy/sharding-proxy-backend/src/main/java/org/apache/shardingsphere/shardingproxy/backend/schema/impl/ShardingSchema.java](https://coveralls.io/builds/29791463/source?filename=sharding-proxy%2Fsharding-proxy-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingproxy%2Fbackend%2Fschema%2Fimpl%2FShardingSchema.java#L155) | 0 | 3 | 0.0%
   | [sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/executor/AbstractStatementExecutor.java](https://coveralls.io/builds/29791463/source?filename=sharding-jdbc%2Fsharding-jdbc-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fshardingjdbc%2Fexecutor%2FAbstractStatementExecutor.java#L158) | 0 | 9 | 0.0%
   <!-- | **Total:** | **12** | **24** | **50.0%** | -->
   
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/29791463/badge)](https://coveralls.io/builds/29791463) |
   | :-- | --: |
   | Change from base [Build 10791](https://coveralls.io/builds/29791061): |  0.2% |
   | Covered Lines: | 11720 |
   | Relevant Lines: | 20375 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402212937
 
 

 ##########
 File path: sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/executor/AbstractStatementExecutor.java
 ##########
 @@ -150,7 +155,19 @@ private void refreshMetaDataIfNeeded(final ShardingRuntimeContext runtimeContext
         }
         Optional<MetaDataRefreshStrategy> refreshStrategy = MetaDataRefreshStrategyFactory.newInstance(sqlStatementContext);
         if (refreshStrategy.isPresent()) {
-            refreshStrategy.get().refreshMetaData(runtimeContext, sqlStatementContext);
+            refreshStrategy.get().refreshMetaData(runtimeContext.getMetaData(), sqlStatementContext, this::loadTableMeta);
         }
     }
+    
+    private TableMetaData loadTableMeta(final String tableName) throws SQLException {
+        ShardingRule shardingRule = connection.getRuntimeContext().getRule();
+        int maxConnectionsSizePerQuery = connection.getRuntimeContext().getProperties().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
+        boolean isCheckingMetaData = connection.getRuntimeContext().getProperties().<Boolean>getValue(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED);
+        TableMetaData result = new ShardingMetaDataLoader(connection.getDataSourceMap(), shardingRule, maxConnectionsSizePerQuery, isCheckingMetaData).load(tableName, databaseType);
+        result = new ShardingTableMetaDataDecorator().decorate(result, tableName, shardingRule);
+        if (!shardingRule.getEncryptRule().getEncryptTableNames().isEmpty()) {
+            result = new EncryptTableMetaDataDecorator().decorate(result, tableName, shardingRule.getEncryptRule());
+        }
+        return result;
+    }
 }
 
 Review comment:
   fix

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402206766
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/AlterTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.AlterTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.AlterTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class AlterTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<AlterTableStatementContext> metaDataRefreshStrategy = new AlterTableStatementMetaDataRefreshStrategy();
+        AlterTableStatement alterTableStatement = new AlterTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order"))));
+        AlterTableStatementContext alterTableStatementContext = new AlterTableStatementContext(alterTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), alterTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index_alter"))));
+        assertThat(getMetaData().getSchema().get("t_order").getIndexes().containsKey("index_alter"), is(true));
+    }
+}
 
 Review comment:
   let an empty line.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402187792
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/CreateTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,52 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.CreateTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class CreateTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<CreateTableStatementContext> metaDataRefreshStrategy = new CreateTableStatementMetaDataRefreshStrategy();
+        CreateTableStatement createTableStatement = new CreateTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order_0"))));
+        CreateTableStatementContext createTableStatementContext = new CreateTableStatementContext(createTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), createTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index"))));
+        assertThat(getMetaData().getSchema().containsTable("t_order_0"), is(true));
+    }
+}
+
+
 
 Review comment:
   one more line

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402187480
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/AlterTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,52 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.AlterTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.AlterTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class AlterTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<AlterTableStatementContext> metaDataRefreshStrategy = new AlterTableStatementMetaDataRefreshStrategy();
+        AlterTableStatement alterTableStatement = new AlterTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order"))));
+        AlterTableStatementContext alterTableStatementContext = new AlterTableStatementContext(alterTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), alterTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index_alter"))));
+        assertThat(getMetaData().getSchema().get("t_order").getIndexes().containsKey("index_alter"), is(true));
+    }
+}
+
+
 
 Review comment:
   one more line

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402212477
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/AlterTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.AlterTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.AlterTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.AlterTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class AlterTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<AlterTableStatementContext> metaDataRefreshStrategy = new AlterTableStatementMetaDataRefreshStrategy();
+        AlterTableStatement alterTableStatement = new AlterTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order"))));
+        AlterTableStatementContext alterTableStatementContext = new AlterTableStatementContext(alterTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), alterTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index_alter"))));
+        assertThat(getMetaData().getSchema().get("t_order").getIndexes().containsKey("index_alter"), is(true));
+    }
+}
 
 Review comment:
   fix
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.

Posted by GitBox <gi...@apache.org>.
yu199195 commented on a change in pull request #5048: sharding-jdbc and sharding-proxy use same metaData refresh strategy.
URL: https://github.com/apache/incubator-shardingsphere/pull/5048#discussion_r402212837
 
 

 ##########
 File path: shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/metadata/refresh/CreateTableStatementMetaDataRefreshStrategyTest.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.underlying.common.metadata.refresh;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateTableStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.statement.ddl.CreateTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.underlying.common.metadata.refresh.impl.CreateTableStatementMetaDataRefreshStrategy;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class CreateTableStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
+    
+    @SneakyThrows
+    @Test
+    public void refreshMetaData() {
+        MetaDataRefreshStrategy<CreateTableStatementContext> metaDataRefreshStrategy = new CreateTableStatementMetaDataRefreshStrategy();
+        CreateTableStatement createTableStatement = new CreateTableStatement(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order_0"))));
+        CreateTableStatementContext createTableStatementContext = new CreateTableStatementContext(createTableStatement);
+        metaDataRefreshStrategy.refreshMetaData(getMetaData(), createTableStatementContext, tableName -> new TableMetaData(
+                Collections.singletonList(new ColumnMetaData("order_id", 1, "String", true, false, false)),
+                Collections.singletonList(new IndexMetaData("index"))));
+        assertThat(getMetaData().getSchema().containsTable("t_order_0"), is(true));
+    }
+}
 
 Review comment:
   this alreay empty line in the end file.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services