strongduanmu commented on code in PR #19718:
URL: https://github.com/apache/shardingsphere/pull/19718#discussion_r933939849


##########
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/raw/jdbc/config/SPIBasedShardingRawJavaConfiguration.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.example.extension.spibased.sharding.raw.jdbc.config;
+
+import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.example.config.ExampleConfiguration;
+import org.apache.shardingsphere.example.core.api.DataSourceUtil;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.*;
+
+public final class SPIBasedShardingRawJavaConfiguration  implements 
ExampleConfiguration {
+    @Override

Review Comment:
   Please add a blank line before here.



##########
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/raw/jdbc/SPIBasedShardingRawJavaConfigurationExample.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.example.extension.spibased.sharding.raw.jdbc;
+
+import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
+import org.apache.shardingsphere.example.core.api.service.ExampleService;
+import org.apache.shardingsphere.example.core.jdbc.service.OrderServiceImpl;
+import 
org.apache.shardingsphere.example.extension.spibased.sharding.raw.jdbc.factory.DataSourceFactory;
+import org.apache.shardingsphere.example.type.ShardingType;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+
+public final class SPIBasedShardingRawJavaConfigurationExample {
+    
+    private static ShardingType shardingType = ShardingType.SHARDING_DATABASES;
+    
+    public static void main(final String[] args) throws SQLException {
+        DataSource dataSource = DataSourceFactory.newInstance(shardingType);

Review Comment:
   Do you think inline `ShardingType.SHARDING_DATABASES` is better?



##########
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/raw/jdbc/config/SPIBasedShardingRawJavaConfiguration.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.example.extension.spibased.sharding.raw.jdbc.config;
+
+import org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.example.config.ExampleConfiguration;
+import org.apache.shardingsphere.example.core.api.DataSourceUtil;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.*;
+
+public final class SPIBasedShardingRawJavaConfiguration  implements 
ExampleConfiguration {
+    @Override
+    public DataSource getDataSource() throws SQLException {
+        return 
ShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(),
+                Collections.singletonList(createShardingRuleConfiguration()), 
new Properties());
+    }
+
+    private Map<String, DataSource> createDataSourceMap() {
+        Map<String, DataSource> result = new HashMap<>();
+        result.put("demo_ds_0", DataSourceUtil.createDataSource("demo_ds_0"));
+        result.put("demo_ds_1", DataSourceUtil.createDataSource("demo_ds_1"));
+        return result;
+    }
+
+    private ShardingRuleConfiguration createShardingRuleConfiguration() {
+        ShardingRuleConfiguration result = new ShardingRuleConfiguration();
+        result.getTables().add(getOrderTableRuleConfiguration());
+        result.getTables().add(getOrderItemTableRuleConfiguration());
+        result.getBindingTableGroups().add("t_order, t_order_item");
+        result.getBroadcastTables().add("t_address");
+        result.setDefaultDatabaseShardingStrategy(new 
StandardShardingStrategyConfiguration("user_id", "spi_based"));
+        result.getShardingAlgorithms().put("spi_based", new 
ShardingSphereAlgorithmConfiguration("SPI_BASED", new Properties()));
+        result.getKeyGenerators().put("snowflake", new 
ShardingSphereAlgorithmConfiguration("SNOWFLAKE", new Properties()));
+        return result;
+    }
+
+    private ShardingTableRuleConfiguration getOrderTableRuleConfiguration() {
+        ShardingTableRuleConfiguration result = new 
ShardingTableRuleConfiguration("t_order", "demo_ds_${0..1}.t_order_${[0, 1]}");
+        result.setKeyGenerateStrategy(new 
KeyGenerateStrategyConfiguration("order_id", "snowflake"));
+        return result;
+    }
+
+    private ShardingTableRuleConfiguration 
getOrderItemTableRuleConfiguration() {
+        ShardingTableRuleConfiguration result = new 
ShardingTableRuleConfiguration("t_order_item", 
"demo_ds_${0..1}.t_order_item_${[0, 1]}");
+        result.setKeyGenerateStrategy(new 
KeyGenerateStrategyConfiguration("order_item_id", "snowflake"));
+        return result;
+    }
+

Review Comment:
   Please remove this blank 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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to