提交 4c9d34ea 编写于 作者: L liya.cookie

move logic to broadcast-table-example

上级 de3a1e0a
/*
* 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.
*/
/*
* Please make sure master-slave data sync on MySQL is running correctly. Otherwise this example will query empty data from slave.
*/
package org.apache.shardingsphere.example.broadcast.table.raw.jdbc;
import org.apache.shardingsphere.example.broadcast.table.raw.jdbc.factory.DataSourceFactory;
import org.apache.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl;
import org.apache.shardingsphere.example.common.jdbc.service.CountryServiceImpl;
import org.apache.shardingsphere.example.common.service.CommonService;
import org.apache.shardingsphere.example.type.ShardingType;
import javax.sql.DataSource;
import java.sql.SQLException;
public class JavaConfigurationExample {
private static ShardingType shardingType = ShardingType.SHARDING_DATABASES;
// private static ShardingType shardingType = ShardingType.MASTER_SLAVE;
public static void main(final String[] args) throws SQLException {
DataSource dataSource = DataSourceFactory.newInstance(shardingType);
CommonService countryService = getCountryService(dataSource);
countryService.initEnvironment();
countryService.processSuccess();
countryService.cleanEnvironment();
}
private static CommonService getCountryService(final DataSource dataSource) {
return new CountryServiceImpl(new CountryRepositroyImpl(dataSource));
}
}
/*
* 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.broadcast.table.raw.jdbc;
import org.apache.shardingsphere.example.broadcast.table.raw.jdbc.factory.YamlDataSourceFactory;
import org.apache.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl;
import org.apache.shardingsphere.example.common.jdbc.service.CountryServiceImpl;
import org.apache.shardingsphere.example.common.service.CommonService;
import org.apache.shardingsphere.example.type.ShardingType;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.SQLException;
/*
* Please make sure master-slave data sync on MySQL is running correctly. Otherwise this example will query empty data from slave.
*/
public class YamlConfigurationExample {
private static ShardingType shardingType = ShardingType.SHARDING_DATABASES;
// private static ShardingType shardingType = ShardingType.MASTER_SLAVE;
public static void main(final String[] args) throws SQLException, IOException {
DataSource dataSource = YamlDataSourceFactory.newInstance(shardingType);
CommonService countryService = getCountryService(dataSource);
countryService.initEnvironment();
countryService.processSuccess();
countryService.cleanEnvironment();
}
private static CommonService getCountryService(final DataSource dataSource) {
return new CountryServiceImpl(new CountryRepositroyImpl(dataSource));
}
}
/*
* 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.broadcast.table.raw.jdbc.config;
import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;
import org.apache.shardingsphere.example.common.DataSourceUtil;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.shardingjdbc.api.MasterSlaveDataSourceFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class MasterSlaveConfiguration implements ExampleConfiguration {
@Override
public DataSource getDataSource() throws SQLException {
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration("demo_ds_master_slave", "demo_ds_master", Arrays.asList("demo_ds_slave_0", "demo_ds_slave_1"));
return MasterSlaveDataSourceFactory.createDataSource(createDataSourceMap(), masterSlaveRuleConfig, new Properties());
}
private Map<String, DataSource> createDataSourceMap() {
Map<String, DataSource> result = new HashMap<>();
result.put("demo_ds_master", DataSourceUtil.createDataSource("demo_ds_master"));
result.put("demo_ds_slave_0", DataSourceUtil.createDataSource("demo_ds_slave_0"));
result.put("demo_ds_slave_1", DataSourceUtil.createDataSource("demo_ds_slave_1"));
return result;
}
}
/*
* 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.broadcast.table.raw.jdbc.config;
import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
import org.apache.shardingsphere.example.common.DataSourceUtil;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class ShardingDatabasesConfigurationPrecise implements ExampleConfiguration {
@Override
public DataSource getDataSource() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getBroadcastTables().add("t_country");
return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new Properties());
}
private static 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;
}
}
/*
* 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.broadcast.table.raw.jdbc.factory;
import org.apache.shardingsphere.example.broadcast.table.raw.jdbc.config.MasterSlaveConfiguration;
import org.apache.shardingsphere.example.broadcast.table.raw.jdbc.config.ShardingDatabasesConfigurationPrecise;
import org.apache.shardingsphere.example.type.ShardingType;
import javax.sql.DataSource;
import java.sql.SQLException;
public class DataSourceFactory {
public static DataSource newInstance(final ShardingType shardingType) throws SQLException {
switch (shardingType) {
case SHARDING_DATABASES:
return new ShardingDatabasesConfigurationPrecise().getDataSource();
case MASTER_SLAVE:
return new MasterSlaveConfiguration().getDataSource();
default:
throw new UnsupportedOperationException(shardingType.name());
}
}
}
/*
* 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.broadcast.table.raw.jdbc.factory;
import org.apache.shardingsphere.example.type.ShardingType;
import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlMasterSlaveDataSourceFactory;
import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
public class YamlDataSourceFactory {
public static DataSource newInstance(final ShardingType shardingType) throws SQLException, IOException {
switch (shardingType) {
case SHARDING_DATABASES:
return YamlShardingDataSourceFactory.createDataSource(getFile("/META-INF/sharding-databases.yaml"));
case MASTER_SLAVE:
return YamlMasterSlaveDataSourceFactory.createDataSource(getFile("/META-INF/master-slave.yaml"));
default:
throw new UnsupportedOperationException(shardingType.name());
}
}
private static File getFile(final String fileName) {
return new File(Thread.currentThread().getClass().getResource(fileName).getFile());
}
}
dataSources:
ds_master: !!com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_master?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password:
ds_slave_0: !!com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_slave_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password:
ds_slave_1: !!com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_slave_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password:
masterSlaveRule:
name: ds_ms
masterDataSourceName: ds_master
slaveDataSourceNames: [ds_slave_0, ds_slave_1]
props:
sql.show: false
dataSources:
ds_0: !!com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password:
ds_1: !!com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: root
password:
shardingRule:
broadcastTables:
- t_country
props:
sql.show: false
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log.context.name" value="sharding-jdbc-api-quickstart" />
<property name="log.charset" value="UTF-8" />
<property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
<contextName>${log.context.name}</contextName>
<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>
/*
* 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.broadcast.table.spring.boot;
import org.apache.shardingsphere.example.common.jpa.service.JPACountryService;
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;
@ComponentScan("org.apache.shardingsphere.example.common.jpa")
@EntityScan(basePackages = "org.apache.shardingsphere.example.common.jpa.entity")
@SpringBootApplication(exclude = JtaAutoConfiguration.class)
public class SpringBootExample {
public static void main(final String[] args) {
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBootExample.class, args)) {
JPACountryService countryService = applicationContext.getBean(JPACountryService.class);
countryService.processSuccess();
}
}
}
sharding.jdbc.datasource.names=ds_master,ds_slave_0,ds_slave_1
sharding.jdbc.datasource.ds_master.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.ds_master.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_master.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
sharding.jdbc.datasource.ds_master.username=root
sharding.jdbc.datasource.ds_master.password=
sharding.jdbc.datasource.ds_slave_0.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.ds_slave_0.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_slave_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_slave_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
sharding.jdbc.datasource.ds_slave_0.username=root
sharding.jdbc.datasource.ds_slave_0.password=
sharding.jdbc.datasource.ds_slave_1.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.ds_slave_1.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_slave_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_slave_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
sharding.jdbc.datasource.ds_slave_1.username=root
sharding.jdbc.datasource.ds_slave_1.password=
sharding.jdbc.config.masterslave.load-balance-algorithm-type=round_robin
sharding.jdbc.config.masterslave.name=ds_ms
sharding.jdbc.config.masterslave.master-data-source-name=ds_master
sharding.jdbc.config.masterslave.slave-data-source-names=ds_slave_0,ds_slave_1
sharding.jdbc.datasource.names=ds_0,ds_1
sharding.jdbc.datasource.ds_0.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.ds_0.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
sharding.jdbc.datasource.ds_0.username=root
sharding.jdbc.datasource.ds_0.password=
sharding.jdbc.datasource.ds_1.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.ds_1.driver-class-name=com.mysql.jdbc.Driver
sharding.jdbc.datasource.ds_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
sharding.jdbc.datasource.ds_1.username=root
sharding.jdbc.datasource.ds_1.password=
sharding.jdbc.config.sharding.broadcast-tables=t_country
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=master-slave
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log.context.name" value="spring-boot-nodep-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>
<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>
/*
* 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.broadcast.table.spring.namespace;
import org.apache.shardingsphere.example.common.mybatis.service.SpringCountryService;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringNamespaceExample {
private static final String CONFIG_FILE = "META-INF/application-sharding-databases.xml";
// private static final String CONFIG_FILE = "META-INF/application-master-slave.xml";
public static void main(final String[] args) {
try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_FILE)) {
SpringCountryService countryService = applicationContext.getBean(SpringCountryService.class);
countryService.initEnvironment();
countryService.processSuccess();
countryService.cleanEnvironment();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:master-slave="http://shardingsphere.apache.org/schema/shardingsphere/masterslave"
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/masterslave
http://shardingsphere.apache.org/schema/shardingsphere/masterslave/master-slave.xsd">
<context:component-scan base-package="org.apache.shardingsphere.example.common.mybatis" />
<bean id="demo_ds_master" 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_master?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="demo_ds_slave_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_slave_0?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="demo_ds_slave_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_slave_1?useSSL=false"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<bean id="randomStrategy" class="org.apache.shardingsphere.core.strategy.masterslave.RandomMasterSlaveLoadBalanceAlgorithm" />
<master-slave:data-source id="masterSlaveDataSource" master-data-source-name="demo_ds_master" slave-data-source-names="demo_ds_slave_0, demo_ds_slave_1" strategy-ref="randomStrategy" />
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="masterSlaveDataSource" />
</bean>
<tx:annotation-driven />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="masterSlaveDataSource"/>
<property name="mapperLocations" value="classpath*:META-INF/mappers/*.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.apache.shardingsphere.example.common.mybatis.repository"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://shardingsphere.apache.org/schema/shardingsphere/sharding
http://shardingsphere.apache.org/schema/shardingsphere/sharding/sharding.xsd">
<context:component-scan base-package="org.apache.shardingsphere.example.common.mybatis" />
<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?useSSL=false&amp;useUnicode=true&amp;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?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<sharding:inline-strategy id="databaseStrategy" sharding-column="user_id" algorithm-expression="demo_ds_${user_id % 2}" />
<sharding:key-generator id="orderKeyGenerator" type="SNOWFLAKE" column="order_id" />
<sharding:data-source id="shardingDataSource">
<sharding:sharding-rule data-source-names="demo_ds_0, demo_ds_1">
<sharding:table-rules>
<sharding:table-rule logic-table="t_order" database-strategy-ref="databaseStrategy" key-generator-ref="orderKeyGenerator" />
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
</sharding:data-source>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="shardingDataSource" />
</bean>
<tx:annotation-driven />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="shardingDataSource"/>
<property name="mapperLocations" value="classpath*:META-INF/mappers/*.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.apache.shardingsphere.example.common.mybatis.repository"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log.context.name" value="sharding-jdbc-spring-namespace-mybatis-quickstart" />
<property name="log.charset" value="UTF-8" />
<property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
<contextName>${log.context.name}</contextName>
<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>
......@@ -17,11 +17,9 @@
package org.apache.shardingsphere.example.sharding.raw.jdbc;
import org.apache.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl;
import org.apache.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl;
import org.apache.shardingsphere.example.common.jdbc.repository.OrderRepositoryImpl;
import org.apache.shardingsphere.example.common.jdbc.service.CommonServiceImpl;
import org.apache.shardingsphere.example.common.jdbc.service.CountryServiceImpl;
import org.apache.shardingsphere.example.common.service.CommonService;
import org.apache.shardingsphere.example.sharding.raw.jdbc.factory.DataSourceFactory;
import org.apache.shardingsphere.example.type.ShardingType;
......@@ -46,17 +44,9 @@ public class JavaConfigurationExample {
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
CommonService countryService = getCountryService(dataSource);
countryService.initEnvironment();
countryService.processSuccess();
countryService.cleanEnvironment();
}
private static CommonService getCommonService(final DataSource dataSource) {
return new CommonServiceImpl(new OrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource));
}
private static CommonService getCountryService(final DataSource dataSource) {
return new CountryServiceImpl(new CountryRepositroyImpl(dataSource));
}
}
......@@ -17,11 +17,9 @@
package org.apache.shardingsphere.example.sharding.raw.jdbc;
import org.apache.shardingsphere.example.common.jdbc.repository.CountryRepositroyImpl;
import org.apache.shardingsphere.example.common.jdbc.repository.OrderItemRepositoryImpl;
import org.apache.shardingsphere.example.common.jdbc.repository.OrderRepositoryImpl;
import org.apache.shardingsphere.example.common.jdbc.service.CommonServiceImpl;
import org.apache.shardingsphere.example.common.jdbc.service.CountryServiceImpl;
import org.apache.shardingsphere.example.common.service.CommonService;
import org.apache.shardingsphere.example.sharding.raw.jdbc.factory.YamlDataSourceFactory;
import org.apache.shardingsphere.example.type.ShardingType;
......@@ -47,17 +45,9 @@ public class YamlConfigurationExample {
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
CommonService countryService = getCountryService(dataSource);
countryService.initEnvironment();
countryService.processSuccess();
countryService.cleanEnvironment();
}
private static CommonService getCommonService(final DataSource dataSource) {
return new CommonServiceImpl(new OrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource));
}
private static CommonService getCountryService(final DataSource dataSource) {
return new CountryServiceImpl(new CountryRepositroyImpl(dataSource));
}
}
......@@ -41,7 +41,6 @@ public final class ShardingDatabasesAndTablesConfigurationPrecise implements Exa
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new InlineShardingStrategyConfiguration("user_id", "demo_ds_${user_id % 2}"));
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseModuloShardingTableAlgorithm()));
return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new Properties());
......
......@@ -43,7 +43,6 @@ public final class ShardingDatabasesAndTablesConfigurationRange implements Examp
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(
new StandardShardingStrategyConfiguration("user_id", new PreciseModuloShardingDatabaseAlgorithm(), new RangeModuloShardingDatabaseAlgorithm()));
shardingRuleConfig.setDefaultTableShardingStrategyConfig(
......
......@@ -38,7 +38,6 @@ public final class ShardingDatabasesConfigurationPrecise implements ExampleConfi
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new InlineShardingStrategyConfiguration("user_id", "demo_ds_${user_id % 2}"));
return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new Properties());
}
......
......@@ -40,7 +40,6 @@ public final class ShardingDatabasesConfigurationRange implements ExampleConfigu
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(
new StandardShardingStrategyConfiguration("user_id", new PreciseModuloShardingDatabaseAlgorithm(), new RangeModuloShardingDatabaseAlgorithm()));
return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new Properties());
......
......@@ -45,7 +45,6 @@ public final class ShardingMasterSlaveConfigurationPrecise implements ExampleCon
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("user_id", new PreciseModuloShardingDatabaseAlgorithm()));
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseModuloShardingTableAlgorithm()));
shardingRuleConfig.setMasterSlaveRuleConfigs(getMasterSlaveRuleConfigurations());
......
......@@ -47,7 +47,6 @@ public final class ShardingMasterSlaveConfigurationRange implements ExampleConfi
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(
new StandardShardingStrategyConfiguration("user_id", new PreciseModuloShardingDatabaseAlgorithm(), new RangeModuloShardingDatabaseAlgorithm()));
shardingRuleConfig.setDefaultTableShardingStrategyConfig(
......
......@@ -40,7 +40,6 @@ public final class ShardingTablesConfigurationPrecise implements ExampleConfigur
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseModuloShardingTableAlgorithm()));
return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new Properties());
}
......
......@@ -41,7 +41,6 @@ public final class ShardingTablesConfigurationRange implements ExampleConfigurat
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.getBroadcastTables().add("t_country");
shardingRuleConfig.setDefaultTableShardingStrategyConfig(
new StandardShardingStrategyConfiguration("order_id", new PreciseModuloShardingTableAlgorithm(), new RangeModuloShardingTableAlgorithm()));
return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new Properties());
......
......@@ -24,9 +24,6 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
......
......@@ -34,9 +34,6 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
......
......@@ -32,9 +32,6 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
defaultDatabaseStrategy:
inline:
shardingColumn: user_id
......
......@@ -24,9 +24,6 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
defaultDatabaseStrategy:
inline:
shardingColumn: user_id
......
......@@ -54,15 +54,11 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
preciseAlgorithmClassName: org.apache.shardingsphere.example.algorithm.PreciseModuloShardingDatabaseAlgorithm
rangeAlgorithmClassName: org.apache.shardingsphere.example.algorithm.RangeModuloShardingDatabaseAlgorithm
masterSlaveRules:
ds_0:
masterDataSourceName: ds_master_0
......
......@@ -52,14 +52,10 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
defaultDatabaseStrategy:
inline:
shardingColumn: user_id
algorithmExpression: ds_${user_id % 2}
masterSlaveRules:
ds_0:
masterDataSourceName: ds_master_0
......
......@@ -29,8 +29,6 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
props:
sql.show: false
......@@ -27,8 +27,6 @@ shardingRule:
column: order_item_id
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_country
props:
sql.show: false
......@@ -18,7 +18,6 @@
package org.apache.shardingsphere.example.sharding.spring.boot.jpa;
import org.apache.shardingsphere.example.common.jpa.service.JPACommonService;
import org.apache.shardingsphere.example.common.jpa.service.JPACountryService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
......@@ -35,8 +34,6 @@ public class SpringBootExample {
try (ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBootExample.class, args)) {
JPACommonService commonService = applicationContext.getBean(JPACommonService.class);
commonService.processSuccess();
JPACountryService countryService = applicationContext.getBean(JPACountryService.class);
countryService.processSuccess();
}
}
}
......@@ -27,4 +27,3 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
......@@ -21,4 +21,3 @@ sharding.jdbc.config.sharding.tables.t_order.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds_$->{0..1}.t_order_item
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
......@@ -55,7 +55,6 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
sharding.jdbc.config.sharding.master-slave-rules.ds_0.master-data-source-name=ds_master_0
sharding.jdbc.config.sharding.master-slave-rules.ds_0.slave-data-source-names=ds_master_0_slave_0, ds_master_0_slave_1
......
......@@ -17,4 +17,3 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
......@@ -17,7 +17,6 @@
package org.apache.shardingsphere.example.sharding.spring.boot.mybatis;
import org.apache.shardingsphere.example.common.mybatis.service.SpringCountryService;
import org.apache.shardingsphere.example.common.mybatis.service.SpringPojoService;
import org.apache.shardingsphere.example.common.service.CommonService;
import org.mybatis.spring.annotation.MapperScan;
......@@ -38,10 +37,6 @@ public class SpringBootMybatisMain {
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
SpringCountryService countryService = applicationContext.getBean(SpringCountryService.class);
countryService.initEnvironment();
countryService.processSuccess();
countryService.cleanEnvironment();
}
}
}
......@@ -6,6 +6,5 @@
<mappers>
<mapper resource="META-INF/mappers/OrderMapper.xml"/>
<mapper resource="META-INF/mappers/OrderItemMapper.xml"/>
<mapper resource="META-INF/mappers/CountryMapper.xml"/>
</mappers>
</configuration>
......@@ -25,4 +25,3 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
......@@ -21,5 +21,4 @@ sharding.jdbc.config.sharding.tables.t_order.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds_$->{0..1}.t_order_item
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
......@@ -47,7 +47,6 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
sharding.jdbc.config.sharding.master-slave-rules.ds_0.master-data-source-name=ds_master_0
sharding.jdbc.config.sharding.master-slave-rules.ds_0.slave-data-source-names=ds_master_0_slave_0, ds_master_0_slave_1
......
......@@ -16,4 +16,3 @@ sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding
sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.algorithm-expression=t_order_item_$->{order_id % 2}
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.column=order_item_id
sharding.jdbc.config.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE
sharding.jdbc.config.sharding.broadcast-tables=t_country
......@@ -18,7 +18,6 @@
package org.apache.shardingsphere.example.sharding.spring.namespace.jpa;
import org.apache.shardingsphere.example.common.jpa.service.JPACommonService;
import org.apache.shardingsphere.example.common.jpa.service.JPACountryService;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
......@@ -34,8 +33,6 @@ public class SpringNamespaceJPAMain {
try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_FILE)) {
JPACommonService commonService = applicationContext.getBean(JPACommonService.class);
commonService.processSuccess();
JPACountryService countryService = applicationContext.getBean(JPACountryService.class);
countryService.processSuccess();
}
}
}
......@@ -62,9 +62,6 @@
<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-generator-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-generator-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop key="sql.show">false</prop>
......
......@@ -58,9 +58,6 @@
<sharding:table-rule logic-table="t_order" database-strategy-ref="databaseStrategy" key-generator-ref="orderKeyGenerator" />
<sharding:table-rule logic-table="t_order_item" database-strategy-ref="databaseStrategy" key-generator-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
</sharding:data-source>
</beans>
......@@ -100,9 +100,6 @@
<sharding:table-rule logic-table="t_order" actual-data-nodes="demo_ds_ms_${0..1}.t_order_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderTableStrategy" key-generator-ref="orderKeyGenerator" />
<sharding:table-rule logic-table="t_order_item" actual-data-nodes="demo_ds_ms_${0..1}.t_order_item_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderItemTableStrategy" key-generator-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop key="sql.show">false</prop>
......
......@@ -52,9 +52,6 @@
<sharding:table-rule logic-table="t_order" actual-data-nodes="demo_ds.t_order_${0..1}" table-strategy-ref="orderTableStrategy" key-generator-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-generator-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
</sharding:data-source>
</beans>
......@@ -17,7 +17,6 @@
package org.apache.shardingsphere.example.sharding.spring.namespace.mybatis;
import org.apache.shardingsphere.example.common.mybatis.service.SpringCountryService;
import org.apache.shardingsphere.example.common.mybatis.service.SpringPojoService;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
......@@ -36,10 +35,6 @@ public class SpringNamespaceExample {
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
SpringCountryService countryService = applicationContext.getBean(SpringCountryService.class);
countryService.initEnvironment();
countryService.processSuccess();
countryService.cleanEnvironment();
}
}
}
......@@ -41,9 +41,6 @@
<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-generator-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-generator-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop key="sql.show">false</prop>
......
......@@ -39,9 +39,6 @@
<sharding:table-rule logic-table="t_order" database-strategy-ref="databaseStrategy" key-generator-ref="orderKeyGenerator" />
<sharding:table-rule logic-table="t_order_item" database-strategy-ref="databaseStrategy" key-generator-ref="itemKeyGenerator" />
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
</sharding:data-source>
......
......@@ -75,9 +75,6 @@
<sharding:table-rule logic-table="t_order" actual-data-nodes="demo_ds_ms_${0..1}.t_order_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderTableStrategy" key-generator-ref="orderKeyGenerator"/>
<sharding:table-rule logic-table="t_order_item" actual-data-nodes="demo_ds_ms_${0..1}.t_order_item_${0..1}" database-strategy-ref="databaseStrategy" table-strategy-ref="orderItemTableStrategy" key-generator-ref="itemKeyGenerator"/>
</sharding:table-rules>
<sharding:broadcast-table-rules>
<sharding:broadcast-table-rule table="t_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop key="sql.show">false</prop>
......
......@@ -36,9 +36,6 @@
<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_country" />
</sharding:broadcast-table-rules>
</sharding:sharding-rule>
<sharding:props>
<prop key="sql.show">false</prop>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册