You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/07/24 08:26:10 UTC

[shardingsphere] branch master updated: class-based-sharding-spring-boot-jpa-example (#18856)

This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 76e0fbc181b class-based-sharding-spring-boot-jpa-example (#18856)
76e0fbc181b is described below

commit 76e0fbc181bfdd75e32de236a78df491cd6af8d2
Author: Swastika Gupta <64...@users.noreply.github.com>
AuthorDate: Sun Jul 24 13:56:03 2022 +0530

    class-based-sharding-spring-boot-jpa-example (#18856)
    
    * class-based-sharding-spring-boot-jpa-example
    
    * Delete application-sharding-auto-tables.properties
    
    * blank lines
    
    * class-based
    
    * corrections
    
    * Create ClassBasedDataSourceStandardShardingAlgorithmFixture.java
    
    * Create ClassBasedOrderItemStandardShardingAlgorithmFixture.java
    
    * Update and rename examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/ClassBasedDataSourceStandardShardingAlgorithmFixture.java to examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class- [...]
    
    * Create ClassBasedOrderStandardShardingAlgorithmFixture.java
---
 .../pom.xml                                        | 30 +++++++---
 .../ClassBasedShardingSpringBootJpaExample.java    | 41 +++++++++++++
 ...DataSourceStandardShardingAlgorithmFixture.java | 61 +++++++++++++++++++
 ...dOrderItemStandardShardingAlgorithmFixture.java | 61 +++++++++++++++++++
 ...BasedOrderStandardShardingAlgorithmFixture.java | 61 +++++++++++++++++++
 ...pplication-sharding-databases-tables.properties | 70 ++++++++++++++++++++++
 .../application-sharding-databases.properties      | 54 +++++++++++++++++
 .../application-sharding-tables.properties         | 54 +++++++++++++++++
 .../src/main/resources/application.properties      | 24 ++++++++
 .../src/main/resources/logback.xml}                | 36 ++++++-----
 .../class-based-sharding-algorithm-example/pom.xml |  2 +-
 11 files changed, 465 insertions(+), 29 deletions(-)

diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/pom.xml
similarity index 58%
copy from examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml
copy to examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/pom.xml
index 7e85c46854d..4f4781baf0b 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/pom.xml
@@ -22,17 +22,29 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere.example</groupId>
-        <artifactId>custom-sharding-algortihm-example</artifactId>
+        <artifactId>class-based-sharding-algorithm-example</artifactId>
         <version>${revision}</version>
     </parent>
-    <artifactId>class-based-sharding-algorithm-example</artifactId>
+    <artifactId>class-based-sharding-spring-boot-jpa-example</artifactId>
     <name>${project.artifactId}</name>
-    <packaging>pom</packaging>
     
-    <modules>
-        <module>class-based-sharding-raw-jdbc-example</module>
-        <module>class-based-sharding-spring-namespace-mybatis-example</module>
-        <module>class-based-sharding-spring-boot-mybatis-example</module>
-
-    </modules>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere.example</groupId>
+            <artifactId>example-spring-jpa</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+        </dependency>
+    </dependencies>
 </project>
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/ClassBasedShardingSpringBootJpaExample.java b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-e [...]
new file mode 100644
index 00000000000..7841eb12918
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/ClassBasedShardingSpringBootJpaExample.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.classbased.sharding.spring.boot.jpa;
+
+import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
+import org.apache.shardingsphere.example.core.api.service.ExampleService;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.ComponentScan;
+
+import java.sql.SQLException;
+
+@ComponentScan("org.apache.shardingsphere.example.core.jpa")
+@EntityScan(basePackages = "org.apache.shardingsphere.example.core.jpa.entity")
+@SpringBootApplication(exclude = JtaAutoConfiguration.class)
+public class ClassBasedShardingSpringBootJpaExample {
+    
+    public static void main(final String[] args) throws SQLException {
+        try (ConfigurableApplicationContext applicationContext = SpringApplication.run(ClassBasedShardingSpringBootJpaExample.class, args)) {
+            ExampleExecuteTemplate.run(applicationContext.getBean(ExampleService.class));
+        }
+    }
+}
\ No newline at end of file
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/fixture/ClassBasedDataSourceStandardShardingAlgorithmFixture.java b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-base [...]
new file mode 100644
index 00000000000..b7e127f57dc
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/fixture/ClassBasedDataSourceStandardShardingAlgorithmFixture.java
@@ -0,0 +1,61 @@
+/*
+ * 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.classbased.sharding.spring.boot.jpa.fixture;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Ints;
+import lombok.Getter;
+import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.util.Collection;
+import java.util.Properties;
+
+public final class ClassBasedDataSourceStandardShardingAlgorithmFixture implements StandardShardingAlgorithm<Integer> {
+    
+    private static final String SHARDING_COUNT = "sharding-count";
+    
+    @Getter
+    private Properties props;
+    
+    private Integer shardingCount;
+    
+    @Override
+    public void init(final Properties props) {
+        this.props = props;
+        Preconditions.checkArgument(props.containsKey(SHARDING_COUNT), "%s can not be null.", SHARDING_COUNT);
+        shardingCount = Ints.tryParse(props.getProperty(SHARDING_COUNT));
+        Preconditions.checkArgument(null != shardingCount, "%s is not valid.", SHARDING_COUNT);
+    }
+    
+    @Override
+    public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Integer> shardingValue) {
+        for (String each : availableTargetNames) {
+            if (each.endsWith(String.valueOf(shardingValue.getValue() % shardingCount))) {
+                return each;
+            }
+        }
+        return null;
+    }
+    
+    @Override
+    public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Integer> shardingValue) {
+        return availableTargetNames;
+    }
+}
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/fixture/ClassBasedOrderItemStandardShardingAlgorithmFixture.java b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based [...]
new file mode 100644
index 00000000000..8c50a21d38f
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/fixture/ClassBasedOrderItemStandardShardingAlgorithmFixture.java
@@ -0,0 +1,61 @@
+/*
+ * 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.classbased.sharding.spring.boot.jpa.fixture;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Ints;
+import lombok.Getter;
+import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.util.Collection;
+import java.util.Properties;
+
+public final class ClassBasedOrderItemStandardShardingAlgorithmFixture implements StandardShardingAlgorithm<Long> {
+    
+    private static final String SHARDING_COUNT = "sharding-count";
+    
+    @Getter
+    private Properties props;
+    
+    private Integer shardingCount;
+    
+    @Override
+    public void init(final Properties props) {
+        this.props = props;
+        Preconditions.checkArgument(props.containsKey(SHARDING_COUNT), "%s can not be null.", SHARDING_COUNT);
+        shardingCount = Ints.tryParse(props.getProperty(SHARDING_COUNT));
+        Preconditions.checkArgument(null != shardingCount, "%s is not valid.", SHARDING_COUNT);
+    }
+    
+    @Override
+    public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Long> shardingValue) {
+        for (String each : availableTargetNames) {
+            if (each.endsWith(String.valueOf(shardingValue.getValue() % shardingCount))) {
+                return each;
+            }
+        }
+        return null;
+    }
+    
+    @Override
+    public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Long> shardingValue) {
+        return availableTargetNames;
+    }
+}
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/fixture/ClassBasedOrderStandardShardingAlgorithmFixture.java b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sha [...]
new file mode 100644
index 00000000000..e05a13ac41e
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/classbased/sharding/spring/boot/jpa/fixture/ClassBasedOrderStandardShardingAlgorithmFixture.java
@@ -0,0 +1,61 @@
+/*
+ * 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.classbased.sharding.spring.boot.jpa.fixture;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Ints;
+import lombok.Getter;
+import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
+import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
+
+import java.util.Collection;
+import java.util.Properties;
+
+public final class ClassBasedOrderStandardShardingAlgorithmFixture implements StandardShardingAlgorithm<Long> {
+    
+    private static final String SHARDING_COUNT = "sharding-count";
+    
+    @Getter
+    private Properties props;
+    
+    private Integer shardingCount;
+    
+    @Override
+    public void init(final Properties props) {
+        this.props = props;
+        Preconditions.checkArgument(props.containsKey(SHARDING_COUNT), "%s can not be null.", SHARDING_COUNT);
+        shardingCount = Ints.tryParse(props.getProperty(SHARDING_COUNT));
+        Preconditions.checkArgument(null != shardingCount, "%s is not valid.", SHARDING_COUNT);
+    }
+    
+    @Override
+    public String doSharding(final Collection<String> availableTargetNames, final PreciseShardingValue<Long> shardingValue) {
+        for (String each : availableTargetNames) {
+            if (each.endsWith(String.valueOf(shardingValue.getValue() % shardingCount))) {
+                return each;
+            }
+        }
+        return null;
+    }
+    
+    @Override
+    public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Long> shardingValue) {
+        return availableTargetNames;
+    }
+}
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases-tables.properties b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources [...]
new file mode 100644
index 00000000000..77eb3224d35
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases-tables.properties
@@ -0,0 +1,70 @@
+#
+# 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.
+#
+
+spring.shardingsphere.mode.type=Standalone
+spring.shardingsphere.mode.repository.type=File
+spring.shardingsphere.mode.overwrite=true
+
+spring.shardingsphere.datasource.names=ds-0,ds-1
+
+spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds-0.username=root
+spring.shardingsphere.datasource.ds-0.password=
+
+spring.shardingsphere.datasource.ds-1.jdbc-url=jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds-1.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds-1.username=root
+spring.shardingsphere.datasource.ds-1.password=
+
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=datasource-class-based
+spring.shardingsphere.rules.sharding.binding-tables[0]=t_order,t_order_item
+spring.shardingsphere.rules.sharding.broadcast-tables=t_address
+
+spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds-$->{0..1}.t_order_$->{0..1}
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=t-order-class-based
+
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds-$->{0..1}.t_order_item_$->{0..1}
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-algorithm-name=t-order-item-class-based
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.type=CLASS_BASED
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.strategy=standard
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.algorithmClassName=org.apache.shardingsphere.example.extension.classbased.sharding.spring.boot.jpa.fixture.ClassBasedDataSourceStandardShardingAlgorithmFixture
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.sharding-count=2
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.type=CLASS_BASED
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.strategy=standard
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.algorithmClassName=org.apache.shardingsphere.example.extension.classbased.sharding.spring.boot.jpa.fixture.ClassBasedOrderStandardShardingAlgorithmFixture
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.sharding-count=2
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.type=CLASS_BASED
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.props.strategy=standard
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.props.algorithmClassName=org.apache.shardingsphere.example.extension.classbased.sharding.spring.boot.jpa.fixture.ClassBasedOrderItemStandardShardingAlgorithmFixture
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.props.sharding-count=2
+
+spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
+
+spring.shardingsphere.props.sql-show=true
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases.properties b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/applic [...]
new file mode 100644
index 00000000000..42502ff9698
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application-sharding-databases.properties
@@ -0,0 +1,54 @@
+#
+# 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.
+#
+
+spring.shardingsphere.datasource.names=ds-0,ds-1
+
+spring.shardingsphere.datasource.ds-0.jdbc-url=jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds-0.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds-0.username=root
+spring.shardingsphere.datasource.ds-0.password=
+
+spring.shardingsphere.datasource.ds-1.jdbc-url=jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds-1.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds-1.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds-1.username=root
+spring.shardingsphere.datasource.ds-1.password=
+
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
+spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=datasource-class-based
+spring.shardingsphere.rules.sharding.binding-tables[0]=t_order,t_order_item
+spring.shardingsphere.rules.sharding.broadcast-tables=t_address
+
+spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds-$->{0..1}.t_order
+
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds-$->{0..1}.t_order_item
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.type=CLASS_BASED
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.strategy=standard
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.algorithmClassName=org.apache.shardingsphere.example.extension.classbased.sharding.spring.boot.jpa.fixture.ClassBasedDataSourceStandardShardingAlgorithmFixture
+spring.shardingsphere.rules.sharding.sharding-algorithms.datasource-class-based.props.sharding-count=2
+
+spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
+
+spring.shardingsphere.props.sql-show=true
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application-sharding-tables.properties b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/applicati [...]
new file mode 100644
index 00000000000..16f4f4bf3ce
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application-sharding-tables.properties
@@ -0,0 +1,54 @@
+#
+# 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.
+#
+
+spring.shardingsphere.datasource.names=ds
+
+spring.shardingsphere.datasource.ds.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds.jdbc-url=jdbc:mysql://127.0.0.1:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds.username=root
+spring.shardingsphere.datasource.ds.password=
+
+spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds.t_order_$->{0..1}
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=t-order-class-based
+
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.actual-data-nodes=ds.t_order_item_$->{0..1}
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-column=order_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.table-strategy.standard.sharding-algorithm-name=t-order-item-class-based
+
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.column=order_item_id
+spring.shardingsphere.rules.sharding.tables.t_order_item.key-generate-strategy.key-generator-name=snowflake
+
+spring.shardingsphere.rules.sharding.binding-tables[0]=t_order,t_order_item
+spring.shardingsphere.rules.sharding.broadcast-tables=t_address
+
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.type=CLASS_BASED
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.strategy=standard
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.algorithmClassName=org.apache.shardingsphere.example.extension.classbased.sharding.spring.boot.jpa.fixture.ClassBasedOrderStandardShardingAlgorithmFixture
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-class-based.props.sharding-count=2
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.type=CLASS_BASED
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.props.strategy=standard
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.props.algorithmClassName=org.apache.shardingsphere.example.extension.classbased.sharding.spring.boot.jpa.fixture.ClassBasedOrderItemStandardShardingAlgorithmFixture
+spring.shardingsphere.rules.sharding.sharding-algorithms.t-order-item-class-based.props.sharding-count=2
+
+spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
+
+spring.shardingsphere.props.sql-show=true
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application.properties b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application.properties
new file mode 100644
index 00000000000..fc1c816023e
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/application.properties
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+
+spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
+spring.jpa.properties.hibernate.show_sql=false
+
+spring.profiles.active=sharding-databases
+#spring.profiles.active=sharding-tables
+#spring.profiles.active=sharding-databases-tables
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/logback.xml
similarity index 50%
copy from examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml
copy to examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/logback.xml
index 7e85c46854d..10f070c99ae 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/class-based-sharding-spring-boot-jpa-example/src/main/resources/logback.xml
@@ -16,23 +16,21 @@
   ~ limitations under the License.
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>org.apache.shardingsphere.example</groupId>
-        <artifactId>custom-sharding-algortihm-example</artifactId>
-        <version>${revision}</version>
-    </parent>
-    <artifactId>class-based-sharding-algorithm-example</artifactId>
-    <name>${project.artifactId}</name>
-    <packaging>pom</packaging>
+<configuration>
+    <property name="log.context.name" value="class-based-sharding-spring-boot-mybatis-example" />
+    <property name="log.charset" value="UTF-8" />
+    <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
+    <contextName>${log.context.name}</contextName>
     
-    <modules>
-        <module>class-based-sharding-raw-jdbc-example</module>
-        <module>class-based-sharding-spring-namespace-mybatis-example</module>
-        <module>class-based-sharding-spring-boot-mybatis-example</module>
-
-    </modules>
-</project>
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder charset="${log.charset}">
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+    </appender>
+    <logger name="org.springframework" level="WARN" />
+    <logger name="com.zaxxer.hikari" level="WARN" />
+    <root>
+        <level value="INFO" />
+        <appender-ref ref="STDOUT" />
+    </root>
+</configuration>
diff --git a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml
index 7e85c46854d..5a6ed963a85 100644
--- a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml
+++ b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example/pom.xml
@@ -33,6 +33,6 @@
         <module>class-based-sharding-raw-jdbc-example</module>
         <module>class-based-sharding-spring-namespace-mybatis-example</module>
         <module>class-based-sharding-spring-boot-mybatis-example</module>
-
+        <module>class-based-sharding-spring-boot-jpa-example</module>
     </modules>
 </project>