提交 770340e8 编写于 作者: T terrymanu

add example-utility module & refactor raw-jdbc-nodep-example

上级 ffeea44d
......@@ -8,7 +8,7 @@
<version>3.0.0.M5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>common-sharding-algorithm</artifactId>
<artifactId>example-utility</artifactId>
<dependencies>
<dependency>
......
......@@ -15,7 +15,7 @@
* </p>
*/
package io.shardingsphere.example.jdbc.orche.util;
package io.shardingsphere.example.config;
import org.apache.commons.dbcp.BasicDataSource;
......
......@@ -15,28 +15,12 @@
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.util;
import org.apache.commons.dbcp.BasicDataSource;
package io.shardingsphere.example.config;
import javax.sql.DataSource;
import java.sql.SQLException;
public class DataSourceUtil {
private static final String HOST = "localhost";
private static final int PORT = 3306;
private static final String USER_NAME = "root";
private static final String PASSWORD = "";
public interface ExampleConfiguration {
public static DataSource createDataSource(final String dataSourceName) {
BasicDataSource result = new BasicDataSource();
result.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
result.setUrl(String.format("jdbc:mysql://%s:%s/%s", HOST, PORT, dataSourceName));
result.setUsername(USER_NAME);
result.setPassword(PASSWORD);
return result;
}
DataSource getDataSource() throws SQLException;
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.example.type;
public enum ShardingType {
SHARDING_DATABASES, SHARDING_TABLES, SHARDING_DATABASES_AND_TABLES, MASTER_SLAVE, SHARDING_MASTER_SLAVE
}
......@@ -7,9 +7,9 @@
<modules>
<module>common-repository</module>
<module>example-utility</module>
<module>sharding-jdbc-example</module>
<module>sharding-proxy-example</module>
<module>common-sharding-algorithm</module>
</modules>
<properties>
......
......@@ -15,7 +15,7 @@
</dependency>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>common-sharding-algorithm</artifactId>
<artifactId>example-utility</artifactId>
<version>${project.version}</version>
</dependency>
......
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.example.jdbc.nodep;
import io.shardingsphere.example.config.ExampleConfiguration;
import io.shardingsphere.example.jdbc.nodep.config.MasterSlaveConfiguration;
import io.shardingsphere.example.jdbc.nodep.config.ShardingDatabasesConfiguration;
import io.shardingsphere.example.jdbc.nodep.config.ShardingDatabasesAndTablesConfiguration;
import io.shardingsphere.example.jdbc.nodep.config.ShardingMasterSlaveConfiguration;
import io.shardingsphere.example.jdbc.nodep.config.ShardingTablesConfiguration;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.example.type.ShardingType;
import javax.sql.DataSource;
import java.sql.SQLException;
public class JavaConfigurationExample {
private static ShardingType type = ShardingType.SHARDING_DATABASES;
// private static ShardingType type = ShardingType.SHARDING_TABLES;
// private static ShardingType type = ShardingType.SHARDING_DATABASES_AND_TABLES;
// private static ShardingType type = ShardingType.MASTER_SLAVE;
// private static ShardingType type = ShardingType.SHARDING_MASTER_SLAVE;
public static void main(final String[] args) throws SQLException {
process(getDataSource());
}
private static DataSource getDataSource() throws SQLException {
ExampleConfiguration exampleConfig;
switch (type) {
case SHARDING_DATABASES:
exampleConfig = new ShardingDatabasesConfiguration();
break;
case SHARDING_TABLES:
exampleConfig = new ShardingTablesConfiguration();
break;
case SHARDING_DATABASES_AND_TABLES:
exampleConfig = new ShardingDatabasesAndTablesConfiguration();
break;
case MASTER_SLAVE:
exampleConfig = new MasterSlaveConfiguration();
break;
case SHARDING_MASTER_SLAVE:
exampleConfig = new ShardingMasterSlaveConfiguration();
break;
default:
throw new UnsupportedOperationException(type.name());
}
return exampleConfig.getDataSource();
}
private static void process(final DataSource dataSource) {
CommonService commonService = getCommonService(dataSource);
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static CommonService getCommonService(final DataSource dataSource) {
return new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
}
}
......@@ -15,31 +15,69 @@
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.yaml;
package io.shardingsphere.example.jdbc.nodep;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.example.type.ShardingType;
import io.shardingsphere.shardingjdbc.api.yaml.YamlMasterSlaveDataSourceFactory;
import io.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
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 MasterSlaveOnly {
public class YamlConfigurationExample {
private static ShardingType type = ShardingType.SHARDING_DATABASES;
// private static ShardingType type = ShardingType.SHARDING_TABLES;
// private static ShardingType type = ShardingType.SHARDING_DATABASES_AND_TABLES;
// private static ShardingType type = ShardingType.MASTER_SLAVE;
// private static ShardingType type = ShardingType.SHARDING_MASTER_SLAVE;
public static void main(final String[] args) throws Exception {
DataSource dataSource = YamlMasterSlaveDataSourceFactory.createDataSource(getYamlFile());
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
public static void main(final String[] args) throws SQLException, IOException {
process(getDataSource());
}
private static DataSource getDataSource() throws IOException, SQLException {
return ShardingType.MASTER_SLAVE == type ? YamlMasterSlaveDataSourceFactory.createDataSource(getYamlFile()) : YamlShardingDataSourceFactory.createDataSource(getYamlFile());
}
private static File getYamlFile() {
String result;
switch (type) {
case SHARDING_DATABASES:
result = "/META-INF/sharding-databases.yaml";
break;
case SHARDING_TABLES:
result = "/META-INF/sharding-tables.yaml";
break;
case SHARDING_DATABASES_AND_TABLES:
result = "/META-INF/sharding-databases-tables.yaml";
break;
case MASTER_SLAVE:
result = "/META-INF/master-slave.yaml";
break;
case SHARDING_MASTER_SLAVE:
result = "/META-INF/sharding-master-slave.yaml";
break;
default:
throw new UnsupportedOperationException(type.name());
}
return new File(YamlConfigurationExample.class.getResource(result).getFile());
}
private static void process(final DataSource dataSource) {
CommonService commonService = getCommonService(dataSource);
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static File getYamlFile() {
return new File(MasterSlaveOnly.class.getResource("/META-INF/master-slave.yaml").getFile());
private static CommonService getCommonService(final DataSource dataSource) {
return new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
}
}
......@@ -15,14 +15,11 @@
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.java;
package io.shardingsphere.example.jdbc.nodep.config;
import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;
import io.shardingsphere.example.jdbc.nodep.util.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.config.ExampleConfiguration;
import io.shardingsphere.shardingjdbc.api.MasterSlaveDataSourceFactory;
import javax.sql.DataSource;
......@@ -36,22 +33,15 @@ import java.util.concurrent.ConcurrentHashMap;
/*
* Please make sure master-slave data sync on MySQL is running correctly. Otherwise this example will query empty data from slave.
*/
public class MasterSlaveOnly {
public class MasterSlaveConfiguration implements ExampleConfiguration {
public static void main(final String[] args) throws SQLException {
DataSource dataSource = getDataSource();
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static DataSource getDataSource() throws SQLException {
@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 ConcurrentHashMap<String, Object>(), new Properties());
}
private static Map<String, DataSource> createDataSourceMap() {
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"));
......
......@@ -15,18 +15,15 @@
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.java;
package io.shardingsphere.example.jdbc.nodep.config;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.InlineShardingStrategyConfiguration;
import io.shardingsphere.api.config.strategy.StandardShardingStrategyConfiguration;
import io.shardingsphere.example.algorithm.ModuloShardingTableAlgorithm;
import io.shardingsphere.example.jdbc.nodep.util.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.config.ExampleConfiguration;
import io.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
import javax.sql.DataSource;
......@@ -35,17 +32,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class ShardingOnlyWithDatabasesAndTables {
public class ShardingDatabasesAndTablesConfiguration implements ExampleConfiguration {
public static void main(final String[] args) throws SQLException {
DataSource dataSource = getDataSource();
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static DataSource getDataSource() throws SQLException {
@Override
public DataSource getDataSource() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
......
......@@ -15,16 +15,13 @@
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.java;
package io.shardingsphere.example.jdbc.nodep.config;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.InlineShardingStrategyConfiguration;
import io.shardingsphere.example.jdbc.nodep.util.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.config.ExampleConfiguration;
import io.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
import javax.sql.DataSource;
......@@ -33,17 +30,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class ShardingOnlyWithDatabases {
public class ShardingDatabasesConfiguration implements ExampleConfiguration {
public static void main(final String[] args) throws SQLException {
DataSource dataSource = getDataSource();
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static DataSource getDataSource() throws SQLException {
@Override
public DataSource getDataSource() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
......
......@@ -15,7 +15,7 @@
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.java;
package io.shardingsphere.example.jdbc.nodep.config;
import com.google.common.collect.Lists;
import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;
......@@ -24,11 +24,8 @@ import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.StandardShardingStrategyConfiguration;
import io.shardingsphere.example.algorithm.ModuloShardingDatabaseAlgorithm;
import io.shardingsphere.example.algorithm.ModuloShardingTableAlgorithm;
import io.shardingsphere.example.jdbc.nodep.util.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.config.ExampleConfiguration;
import io.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
import javax.sql.DataSource;
......@@ -42,17 +39,10 @@ import java.util.Properties;
/*
* Please make sure master-slave data sync on MySQL is running correctly. Otherwise this example will query empty data from slave.
*/
public class ShardingAndMasterSlaveTogether {
public class ShardingMasterSlaveConfiguration implements ExampleConfiguration {
public static void main(final String[] args) throws SQLException {
DataSource dataSource = getDataSource();
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static DataSource getDataSource() throws SQLException {
@Override
public DataSource getDataSource() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
......
......@@ -15,15 +15,12 @@
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.java;
package io.shardingsphere.example.jdbc.nodep.config;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.example.jdbc.nodep.util.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.config.ExampleConfiguration;
import io.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
import javax.sql.DataSource;
......@@ -32,17 +29,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class ShardingOnlyWithTables {
public class ShardingTablesConfiguration implements ExampleConfiguration {
public static void main(final String[] args) throws SQLException {
DataSource dataSource = getDataSource();
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static DataSource getDataSource() throws SQLException {
@Override
public DataSource getDataSource() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
......
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.yaml;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
/*
* Please make sure master-slave data sync on MySQL is running correctly. Otherwise this example will query empty data from slave.
*/
public class ShardingAndMasterSlaveTogether {
public static void main(final String[] args) throws Exception {
DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(getYamlFile());
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static File getYamlFile() {
return new File(ShardingAndMasterSlaveTogether.class.getResource("/META-INF/sharding-master-slave.yaml").getFile());
}
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.yaml;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
public class ShardingOnlyWithDatabases {
public static void main(final String[] args) throws Exception {
DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(getYamlFile());
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static File getYamlFile() {
return new File(ShardingOnlyWithDatabases.class.getResource("/META-INF/sharding-databases.yaml").getFile());
}
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.yaml;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
public class ShardingOnlyWithDatabasesAndTables {
public static void main(final String[] args) throws Exception {
DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(getYamlFile());
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static File getYamlFile() {
return new File(ShardingOnlyWithDatabasesAndTables.class.getResource("/META-INF/sharding-databases-tables.yaml").getFile());
}
}
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package io.shardingsphere.example.jdbc.nodep.main.yaml;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.service.RawPojoService;
import io.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
public class ShardingOnlyWithTables {
public static void main(final String[] args) throws Exception {
DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(getYamlFile());
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
commonService.initEnvironment();
commonService.processSuccess();
commonService.cleanEnvironment();
}
private static File getYamlFile() {
return new File(ShardingOnlyWithTables.class.getResource("/META-INF/sharding-tables.yaml").getFile());
}
}
......@@ -21,4 +21,4 @@ masterSlaveRule:
slaveDataSourceNames: [ds_slave_0, ds_slave_1]
props:
sql.show: true
\ No newline at end of file
sql.show: true
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log.context.name" value="raw-jdbc-yaml-nodep-example" />
<property name="log.context.name" value="raw-jdbc-nodep-example" />
<property name="log.charset" value="UTF-8" />
<property name="log.pattern" value="[%-5level] %date --%thread-- [%logger] %msg %n" />
<contextName>${log.context.name}</contextName>
......
......@@ -18,7 +18,7 @@
</dependency>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>common-sharding-algorithm</artifactId>
<artifactId>example-utility</artifactId>
<version>${project.version}</version>
</dependency>
......
......@@ -18,7 +18,7 @@
package io.shardingsphere.example.jdbc.orche.main.java.etcd;
import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -24,7 +24,7 @@ import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.StandardShardingStrategyConfiguration;
import io.shardingsphere.example.algorithm.ModuloShardingDatabaseAlgorithm;
import io.shardingsphere.example.algorithm.ModuloShardingTableAlgorithm;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -20,7 +20,7 @@ package io.shardingsphere.example.jdbc.orche.main.java.etcd;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.InlineShardingStrategyConfiguration;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -22,7 +22,7 @@ import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.InlineShardingStrategyConfiguration;
import io.shardingsphere.api.config.strategy.StandardShardingStrategyConfiguration;
import io.shardingsphere.example.algorithm.ModuloShardingTableAlgorithm;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -19,7 +19,7 @@ package io.shardingsphere.example.jdbc.orche.main.java.etcd;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -18,7 +18,7 @@
package io.shardingsphere.example.jdbc.orche.main.java.zookeeper;
import io.shardingsphere.api.config.MasterSlaveRuleConfiguration;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -24,7 +24,7 @@ import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.StandardShardingStrategyConfiguration;
import io.shardingsphere.example.algorithm.ModuloShardingDatabaseAlgorithm;
import io.shardingsphere.example.algorithm.ModuloShardingTableAlgorithm;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -20,7 +20,7 @@ package io.shardingsphere.example.jdbc.orche.main.java.zookeeper;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.InlineShardingStrategyConfiguration;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -22,7 +22,7 @@ import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.api.config.strategy.InlineShardingStrategyConfiguration;
import io.shardingsphere.api.config.strategy.StandardShardingStrategyConfiguration;
import io.shardingsphere.example.algorithm.ModuloShardingTableAlgorithm;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -19,7 +19,7 @@ package io.shardingsphere.example.jdbc.orche.main.java.zookeeper;
import io.shardingsphere.api.config.ShardingRuleConfiguration;
import io.shardingsphere.api.config.TableRuleConfiguration;
import io.shardingsphere.example.jdbc.orche.util.DataSourceUtil;
import io.shardingsphere.example.config.DataSourceUtil;
import io.shardingsphere.example.repository.api.service.CommonService;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderItemRepositoryImpl;
import io.shardingsphere.example.repository.jdbc.repository.JDBCOrderRepositoryImpl;
......
......@@ -22,4 +22,4 @@ spring.profiles.active=etcd-sharding-local
#spring.profiles.active=zookeeper-masterslave-local
#spring.profiles.active=zookeeper-masterslave-cloud
#spring.profiles.active=zookeeper-sharding-masterslave-local
#spring.profiles.active=zookeeper-sharding-masterslave-cloud
\ No newline at end of file
#spring.profiles.active=zookeeper-sharding-masterslave-cloud
......@@ -16,7 +16,7 @@
<dependencies>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>common-sharding-algorithm</artifactId>
<artifactId>example-utility</artifactId>
<version>${project.version}</version>
</dependency>
......
......@@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>common-sharding-algorithm</artifactId>
<artifactId>example-utility</artifactId>
<version>${project.version}</version>
</dependency>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册