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 4bebfdd Add spi-based-sharding-spring-namespace-jpa-example #15720
(#15849)
4bebfdd is described below
commit 4bebfdd1b644faf8c44a7af18417069a139e5ec7
Author: 亥时 <[email protected]>
AuthorDate: Mon Mar 7 18:05:09 2022 +0800
Add spi-based-sharding-spring-namespace-jpa-example #15720 (#15849)
---
.../spi-based-sharding-algorithm-example/pom.xml | 1 +
.../pom.xml | 24 +++--
.../SPIBasedShardingSpringNamespaceJpaExample.java | 38 +++++++
...sedAccountStandardShardingAlgorithmFixture.java | 55 ++++++++++
...DatasourceStandardShardingAlgorithmFixture.java | 54 ++++++++++
...dOrderItemStandardShardingAlgorithmFixture.java | 55 ++++++++++
...BasedOrderStandardShardingAlgorithmFixture.java | 54 ++++++++++
.../application-sharding-databases-tables.xml | 111 +++++++++++++++++++++
.../META-INF/application-sharding-databases.xml | 96 ++++++++++++++++++
.../META-INF/application-sharding-tables.xml | 95 ++++++++++++++++++
...e.shardingsphere.sharding.spi.ShardingAlgorithm | 21 ++++
.../src/main/resources/logback.xml} | 32 +++---
12 files changed, 611 insertions(+), 25 deletions(-)
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
index 13d5fc6..79686f0 100644
---
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
@@ -32,5 +32,6 @@
<modules>
<module>spi-based-sharding-raw-jdbc-example</module>
<module>spi-based-sharding-spring-boot-mybatis-example</module>
+ <module>spi-based-sharding-spring-namespace-jpa-example</module>
</modules>
</project>
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/pom.xml
similarity index 68%
copy from
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
copy to
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/pom.xml
index 13d5fc6..3024331 100644
---
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/pom.xml
@@ -21,16 +21,24 @@
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>
+ <artifactId>spi-based-sharding-algorithm-example</artifactId>
<groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>custom-sharding-algortihm-example</artifactId>
<version>${revision}</version>
</parent>
- <artifactId>spi-based-sharding-algorithm-example</artifactId>
+ <artifactId>spi-based-sharding-spring-namespace-jpa-example</artifactId>
<name>${project.artifactId}</name>
- <packaging>pom</packaging>
-
- <modules>
- <module>spi-based-sharding-raw-jdbc-example</module>
- <module>spi-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-namespace</artifactId>
+ </dependency>
+ </dependencies>
+
</project>
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/SPIBasedShardingSpringNamespaceJpaExample.java
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algori
[...]
new file mode 100644
index 0000000..282b086
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/SPIBasedShardingSpringNamespaceJpaExample.java
@@ -0,0 +1,38 @@
+/*
+ * 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.spring.namespace.jpa;
+
+import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
+import org.apache.shardingsphere.example.core.api.service.ExampleService;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.sql.SQLException;
+
+public final class SPIBasedShardingSpringNamespaceJpaExample {
+
+// private static final String CONFIG_FILE =
"META-INF/application-sharding-databases.xml";
+// private static final String CONFIG_FILE =
"META-INF/application-sharding-tables.xml";
+ private static final String CONFIG_FILE =
"META-INF/application-sharding-databases-tables.xml";
+
+ public static void main(final String[] args) throws SQLException {
+ try (ConfigurableApplicationContext applicationContext = new
ClassPathXmlApplicationContext(CONFIG_FILE)) {
+
ExampleExecuteTemplate.run(applicationContext.getBean(ExampleService.class));
+ }
+ }
+}
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedAccountStandardShardingAlgorithmFixture.java
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-s
[...]
new file mode 100644
index 0000000..93be465
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedAccountStandardShardingAlgorithmFixture.java
@@ -0,0 +1,55 @@
+/*
+ * 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.spring.namespace.jpa.fixture;
+
+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;
+
+public final class SPIBasedAccountStandardShardingAlgorithmFixture implements
StandardShardingAlgorithm<Long> {
+
+ @Override
+ public String doSharding(final Collection<String> availableTargetNames,
final PreciseShardingValue<Long> shardingValue) {
+ for (String each : availableTargetNames) {
+ if (each.endsWith(shardingSuffix(shardingValue.getValue()))) {
+ return each;
+ }
+ }
+ return null;
+ }
+
+ private String shardingSuffix(Long shardingValue) {
+ return "_" + (shardingValue % 2);
+ }
+
+ @Override
+ public Collection<String> doSharding
+ (Collection<String> availableTargetNames, RangeShardingValue<Long>
shardingValue) {
+ return availableTargetNames;
+ }
+
+ @Override
+ public void init() {}
+
+ @Override
+ public String getType() {
+ return "T_ACCOUNT_SPI_BASED";
+ }
+}
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedDatasourceStandardShardingAlgorithmFixture.java
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-base
[...]
new file mode 100644
index 0000000..dd6d7e7
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedDatasourceStandardShardingAlgorithmFixture.java
@@ -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.
+ */
+
+package
org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.jpa.fixture;
+
+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;
+
+public final class SPIBasedDatasourceStandardShardingAlgorithmFixture
implements StandardShardingAlgorithm<Integer> {
+
+ @Override
+ public String doSharding(final Collection<String> dataSourceNames, final
PreciseShardingValue<Integer> shardingValue) {
+ for (String each : dataSourceNames) {
+ if (each.endsWith(shardingSuffix(shardingValue.getValue()))) {
+ return each;
+ }
+ }
+ return null;
+ }
+
+ private String shardingSuffix(Integer shardingValue) {
+ return "_" + (shardingValue % 2);
+ }
+
+ @Override
+ public Collection<String> doSharding(Collection<String>
availableTargetNames, RangeShardingValue<Integer> shardingValue) {
+ return availableTargetNames;
+ }
+
+ @Override
+ public void init() {}
+
+ @Override
+ public String getType() {
+ return "DATASOURCE_SPI_BASED";
+ }
+}
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedOrderItemStandardShardingAlgorithmFixture.java
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based
[...]
new file mode 100644
index 0000000..b8314dd
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedOrderItemStandardShardingAlgorithmFixture.java
@@ -0,0 +1,55 @@
+/*
+ * 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.spring.namespace.jpa.fixture;
+
+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;
+
+public final class SPIBasedOrderItemStandardShardingAlgorithmFixture
implements StandardShardingAlgorithm<Long> {
+
+ @Override
+ public String doSharding(final Collection<String> availableTargetNames,
final PreciseShardingValue<Long> shardingValue) {
+ for (String each : availableTargetNames) {
+ if (each.endsWith(shardingSuffix(shardingValue.getValue()))) {
+ return each;
+ }
+ }
+ return null;
+ }
+
+ private String shardingSuffix(Long shardingValue) {
+ return "_" + (shardingValue % 2);
+ }
+
+ @Override
+ public Collection<String> doSharding
+ (Collection<String> availableTargetNames, RangeShardingValue<Long>
shardingValue) {
+ return availableTargetNames;
+ }
+
+ @Override
+ public void init() {}
+
+ @Override
+ public String getType() {
+ return "T_ORDER_ITEM_SPI_BASED";
+ }
+}
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedOrderStandardShardingAlgorithmFixture.java
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sha
[...]
new file mode 100644
index 0000000..1308007
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/java/org/apache/shardingsphere/example/extension/spibased/sharding/spring/namespace/jpa/fixture/SPIBasedOrderStandardShardingAlgorithmFixture.java
@@ -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.
+ */
+
+package
org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.jpa.fixture;
+
+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;
+
+public final class SPIBasedOrderStandardShardingAlgorithmFixture implements
StandardShardingAlgorithm<Long> {
+
+ @Override
+ public String doSharding(final Collection<String> availableTargetNames,
final PreciseShardingValue<Long> shardingValue) {
+ for (String each : availableTargetNames) {
+ if (each.endsWith(shardingSuffix(shardingValue.getValue()))) {
+ return each;
+ }
+ }
+ return null;
+ }
+
+ private String shardingSuffix(Long shardingValue) {
+ return "_" + (shardingValue % 2);
+ }
+
+ @Override
+ public Collection<String> doSharding(Collection<String>
availableTargetNames, RangeShardingValue<Long> shardingValue) {
+ return availableTargetNames;
+ }
+
+ @Override
+ public void init() {}
+
+ @Override
+ public String getType() {
+ return "T_ORDER_SPI_BASED";
+ }
+}
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/application-sharding-databases-tables.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resou
[...]
new file mode 100644
index 0000000..bd7a5f5
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/application-sharding-databases-tables.xml
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+
xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
+
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
+
http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/tx
+
http://www.springframework.org/schema/tx/spring-tx.xsd
+
http://shardingsphere.apache.org/schema/shardingsphere/datasource
+
http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
+
http://shardingsphere.apache.org/schema/shardingsphere/sharding
+
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
+ ">
+ <context:annotation-config />
+ <context:component-scan
base-package="org.apache.shardingsphere.example.core.jpa"/>
+
+ <bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="shardingDataSource" />
+ <property name="jpaVendorAdapter">
+ <bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:database="MYSQL" />
+ </property>
+ <property name="packagesToScan"
value="org.apache.shardingsphere.example.core.jpa.entity" />
+ <property name="jpaProperties">
+ <props>
+ <prop
key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
+ <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
+ <prop key="hibernate.show_sql">false</prop>
+ </props>
+ </property>
+ </bean>
+ <bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
+ <tx:annotation-driven />
+
+ <bean id="demo_ds_0" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+ <property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <property name="username" value="root"/>
+ <property name="password" value=""/>
+ <property name="maximumPoolSize" value="16"/>
+ </bean>
+
+ <bean id="demo_ds_1" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+ <property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <property name="username" value="root"/>
+ <property name="password" value=""/>
+ <property name="maximumPoolSize" value="16"/>
+ </bean>
+
+ <sharding:sharding-algorithm id="databaseAlgorithm"
type="DATASOURCE_SPI_BASED" />
+ <sharding:standard-strategy id="databaseStrategy"
sharding-column="user_id" algorithm-ref="databaseAlgorithm" />
+
+ <sharding:sharding-algorithm id="accountTableAlgorithm"
type="T_ACCOUNT_SPI_BASED" />
+ <sharding:standard-strategy id="accountTableStrategy"
algorithm-ref="accountTableAlgorithm" />
+
+ <sharding:sharding-algorithm id="orderTableAlgorithm"
type="T_ORDER_SPI_BASED" />
+ <sharding:standard-strategy id="orderTableStrategy"
sharding-column="order_id" algorithm-ref="orderTableAlgorithm" />
+
+ <sharding:sharding-algorithm id="orderItemTableAlgorithm"
type="T_ORDER_SPI_BASED" />
+ <sharding:standard-strategy id="orderItemTableStrategy"
sharding-column="order_id" algorithm-ref="orderItemTableAlgorithm" />
+
+ <sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
+ </sharding:key-generate-algorithm>
+
+ <sharding:key-generate-strategy id="orderKeyGenerator" column="order_id"
algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="itemKeyGenerator"
column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="accountKeyGenerator"
column="account_id" algorithm-ref="snowflakeAlgorithm" />
+
+ <sharding:rule id="shardingRule" default-sharding-column="account_id">
+ <sharding:table-rules>
+ <sharding:table-rule logic-table="t_order"
actual-data-nodes="demo_ds_${0..1}.t_order_${0..1}"
database-strategy-ref="databaseStrategy"
table-strategy-ref="orderTableStrategy"
key-generate-strategy-ref="orderKeyGenerator" />
+ <sharding:table-rule logic-table="t_order_item"
actual-data-nodes="demo_ds_${0..1}.t_order_item_${0..1}"
database-strategy-ref="databaseStrategy"
table-strategy-ref="orderItemTableStrategy"
key-generate-strategy-ref="itemKeyGenerator" />
+ <sharding:table-rule logic-table="t_account"
actual-data-nodes="demo_ds_${0..1}.t_account_${0..1}"
database-strategy-ref="databaseStrategy"
table-strategy-ref="accountTableStrategy"
key-generate-strategy-ref="accountKeyGenerator" />
+ </sharding:table-rules>
+ <sharding:binding-table-rules>
+ <sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
+ </sharding:binding-table-rules>
+ <sharding:broadcast-table-rules>
+ <sharding:broadcast-table-rule table="t_address"/>
+ </sharding:broadcast-table-rules>
+ </sharding:rule>
+
+ <shardingsphere:data-source id="shardingDataSource"
data-source-names="demo_ds_0, demo_ds_1" rule-refs="shardingRule">
+ <props>
+ <prop key="sql-show">false</prop>
+ </props>
+ </shardingsphere:data-source>
+</beans>
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/application-sharding-databases.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/ME
[...]
new file mode 100644
index 0000000..53ace22
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/application-sharding-databases.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+
xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
+
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
+
http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/tx
+
http://www.springframework.org/schema/tx/spring-tx.xsd
+
http://shardingsphere.apache.org/schema/shardingsphere/datasource
+
http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
+
http://shardingsphere.apache.org/schema/shardingsphere/sharding
+
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
+ ">
+ <context:annotation-config />
+ <context:component-scan
base-package="org.apache.shardingsphere.example.core.jpa"/>
+
+ <bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="shardingDataSource" />
+ <property name="jpaVendorAdapter">
+ <bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:database="MYSQL" />
+ </property>
+ <property name="packagesToScan"
value="org.apache.shardingsphere.example.core.jpa.entity" />
+ <property name="jpaProperties">
+ <props>
+ <prop
key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
+ <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
+ <prop key="hibernate.show_sql">false</prop>
+ </props>
+ </property>
+ </bean>
+ <bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
+ <tx:annotation-driven />
+
+ <bean id="demo_ds_0" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+ <property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <property name="username" value="root"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <bean id="demo_ds_1" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+ <property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <property name="username" value="root"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <sharding:sharding-algorithm id="databaseAlgorithm"
type="DATASOURCE_SPI_BASED" />
+ <sharding:standard-strategy id="databaseStrategy"
sharding-column="user_id" algorithm-ref="databaseAlgorithm" />
+
+ <sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
+ </sharding:key-generate-algorithm>
+
+ <sharding:key-generate-strategy id="orderKeyGenerator" column="order_id"
algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="accountKeyGenerator"
column="account_id" algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="itemKeyGenerator"
column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
+
+ <sharding:rule id="shardingRule">
+ <sharding:table-rules>
+ <sharding:table-rule logic-table="t_order"
database-strategy-ref="databaseStrategy"
key-generate-strategy-ref="orderKeyGenerator" />
+ <sharding:table-rule logic-table="t_order_item"
database-strategy-ref="databaseStrategy"
key-generate-strategy-ref="itemKeyGenerator" />
+ <sharding:table-rule logic-table="t_account"
database-strategy-ref="databaseStrategy"
key-generate-strategy-ref="accountKeyGenerator" />
+ </sharding:table-rules>
+ <sharding:binding-table-rules>
+ <sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
+ </sharding:binding-table-rules>
+ <sharding:broadcast-table-rules>
+ <sharding:broadcast-table-rule table="t_address"/>
+ </sharding:broadcast-table-rules>
+ </sharding:rule>
+
+ <shardingsphere:data-source id="shardingDataSource"
data-source-names="demo_ds_0, demo_ds_1" rule-refs="shardingRule" />
+</beans>
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/application-sharding-tables.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-
[...]
new file mode 100644
index 0000000..607d7b9
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/application-sharding-tables.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+
xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
+
xmlns:sharding="http://shardingsphere.apache.org/schema/shardingsphere/sharding"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context
+
http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/tx
+
http://www.springframework.org/schema/tx/spring-tx.xsd
+
http://shardingsphere.apache.org/schema/shardingsphere/datasource
+
http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
+
http://shardingsphere.apache.org/schema/shardingsphere/sharding
+
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd
+ ">
+ <context:annotation-config />
+ <context:component-scan
base-package="org.apache.shardingsphere.example.core.jpa"/>
+
+ <bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="dataSource" ref="shardingDataSource" />
+ <property name="jpaVendorAdapter">
+ <bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:database="MYSQL" />
+ </property>
+ <property name="packagesToScan"
value="org.apache.shardingsphere.example.core.jpa.entity" />
+ <property name="jpaProperties">
+ <props>
+ <prop
key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
+ <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
+ <prop key="hibernate.show_sql">false</prop>
+ </props>
+ </property>
+ </bean>
+ <bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
+ <tx:annotation-driven />
+
+ <bean id="demo_ds" class="com.zaxxer.hikari.HikariDataSource"
destroy-method="close">
+ <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
+ <property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8"/>
+ <property name="username" value="root"/>
+ <property name="password" value=""/>
+ </bean>
+
+ <sharding:sharding-algorithm id="accountTableAlgorithm"
type="T_ACCOUNT_SPI_BASED" />
+ <sharding:standard-strategy id="accountTableStrategy"
algorithm-ref="accountTableAlgorithm" />
+
+ <sharding:sharding-algorithm id="orderTableAlgorithm"
type="T_ORDER_SPI_BASED" />
+ <sharding:standard-strategy id="orderTableStrategy"
sharding-column="order_id" algorithm-ref="orderTableAlgorithm" />
+
+ <sharding:sharding-algorithm id="orderItemTableAlgorithm"
type="T_ORDER_ITEM_SPI_BASED" />
+ <sharding:standard-strategy id="orderItemTableStrategy"
sharding-column="order_id" algorithm-ref="orderItemTableAlgorithm" />
+
+ <sharding:key-generate-algorithm id="snowflakeAlgorithm" type="SNOWFLAKE">
+ </sharding:key-generate-algorithm>
+
+ <sharding:key-generate-strategy id="orderKeyGenerator" column="order_id"
algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="itemKeyGenerator"
column="order_item_id" algorithm-ref="snowflakeAlgorithm" />
+ <sharding:key-generate-strategy id="accountKeyGenerator"
column="account_id" algorithm-ref="snowflakeAlgorithm" />
+
+ <sharding:rule id="shardingRule" default-sharding-column="account_id">
+ <sharding:table-rules>
+ <sharding:table-rule logic-table="t_order"
actual-data-nodes="demo_ds.t_order_${0..1}"
table-strategy-ref="orderTableStrategy"
key-generate-strategy-ref="orderKeyGenerator" />
+ <sharding:table-rule logic-table="t_order_item"
actual-data-nodes="demo_ds.t_order_item_${0..1}"
table-strategy-ref="orderItemTableStrategy"
key-generate-strategy-ref="itemKeyGenerator" />
+ <sharding:table-rule logic-table="t_account"
actual-data-nodes="demo_ds.t_account_${0..1}"
table-strategy-ref="accountTableStrategy"
key-generate-strategy-ref="accountKeyGenerator" />
+ </sharding:table-rules>
+ <sharding:binding-table-rules>
+ <sharding:binding-table-rule logic-tables="t_order,t_order_item"/>
+ </sharding:binding-table-rules>
+ <sharding:broadcast-table-rules>
+ <sharding:broadcast-table-rule table="t_address"/>
+ </sharding:broadcast-table-rules>
+ </sharding:rule>
+
+ <shardingsphere:data-source id="shardingDataSource"
data-source-names="demo_ds" rule-refs="shardingRule" />
+</beans>
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jp
[...]
new file mode 100644
index 0000000..f02fc61
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.jpa.fixture.SPIBasedDatasourceStandardShardingAlgorithmFixture
+org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.jpa.fixture.SPIBasedAccountStandardShardingAlgorithmFixture
+org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.jpa.fixture.SPIBasedOrderStandardShardingAlgorithmFixture
+org.apache.shardingsphere.example.extension.spibased.sharding.spring.namespace.jpa.fixture.SPIBasedOrderItemStandardShardingAlgorithmFixture
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/logback.xml
similarity index 53%
copy from
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
copy to
examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/logback.xml
index 13d5fc6..ecc8f4d 100644
---
a/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/pom.xml
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/extension-example/custom-sharding-algortihm-example/spi-based-sharding-algorithm-example/spi-based-sharding-spring-namespace-jpa-example/src/main/resources/logback.xml
@@ -16,21 +16,19 @@
~ 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>spi-based-sharding-algorithm-example</artifactId>
- <name>${project.artifactId}</name>
- <packaging>pom</packaging>
+<configuration>
+ <property name="log.context.name"
value="spi-based-sharding-spring-namespace-jpa-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>spi-based-sharding-raw-jdbc-example</module>
- <module>spi-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>
+ <root>
+ <level value="INFO" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>