From 9592a96bc773354e93b048df7183cc6accfe5229 Mon Sep 17 00:00:00 2001
From: 吴学文 <wuxuewen@wuxuewendeMacBook-Pro.local>
Date: 星期四, 16 五月 2019 00:27:21 +0800
Subject: [PATCH] 数据库分片未开发完成
---
java110-db/src/main/java/com/java110/db/DataSourceConfig.java | 80 ++++++++++++++++------------------------
1 files changed, 32 insertions(+), 48 deletions(-)
diff --git a/java110-db/src/main/java/com/java110/db/DataSourceConfig.java b/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
index e3bef6d..d65e9b8 100644
--- a/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
+++ b/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
@@ -1,24 +1,8 @@
package com.java110.db;
-import com.alibaba.druid.filter.Filter;
-import com.alibaba.druid.pool.DruidDataSource;
-import com.google.common.collect.Lists;
-import io.shardingsphere.core.yaml.sharding.YamlShardingConfiguration;
-import io.shardingsphere.core.yaml.sharding.YamlShardingRuleConfiguration;
-import io.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-import javax.sql.DataSource;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
/**
@@ -27,10 +11,10 @@
@Configuration
public class DataSourceConfig {
- @Autowired
- private Filter statFilter;
-
- private static final String SHARDING_YML_PATH = "dataSource.yml";
+// @Autowired
+// private Filter statFilter;
+//
+// private static final String SHARDING_YML_PATH = "dataSource.yml";
/**
* 鏋勫缓dataSource
@@ -42,32 +26,32 @@
* @throws IOException IO 寮傚父
* @since 1.8
*/
- @Bean
- public DataSource dataSource() throws SQLException, IOException {
- YamlShardingConfiguration config = parse();
- YamlShardingRuleConfiguration rule = config.getShardingRule();
- for (String key : config.getDataSources().keySet()) {
- DruidDataSource d = (DruidDataSource) config.getDataSources().get(key);
- d.setProxyFilters(Lists.newArrayList(statFilter));
- }
- return ShardingDataSourceFactory.createDataSource(config.getDataSources(),
- rule.getShardingRuleConfiguration(), config.getConfigMap(), config.getProps());
- }
-
- /**
- * 瑙f瀽yml
- *
- * @return yaml 閰嶇疆鏂囦欢
- * @throws IOException IO 寮傚父
- * @throws FileNotFoundException 鏂囦欢鏈彂鐜板紓甯�
- * @throws UnsupportedEncodingException 涓嶆敮鎸佺紪鐮佸紓甯�
- */
- private YamlShardingConfiguration parse() throws IOException, FileNotFoundException, UnsupportedEncodingException {
- Resource certResource = new ClassPathResource(SHARDING_YML_PATH);
- try (
- InputStreamReader inputStreamReader = new InputStreamReader(certResource.getInputStream(), "UTF-8")
- ) {
- return new Yaml(new Constructor(YamlShardingConfiguration.class)).loadAs(inputStreamReader, YamlShardingConfiguration.class);
- }
- }
+// @Bean
+// public DataSource dataSource() throws SQLException, IOException {
+// YamlShardingConfiguration config = parse();
+// YamlShardingRuleConfiguration rule = config.getShardingRule();
+// for (String key : config.getDataSources().keySet()) {
+// DruidDataSource d = (DruidDataSource) config.getDataSources().get(key);
+// d.setProxyFilters(Lists.newArrayList(statFilter));
+// }
+// return ShardingDataSourceFactory.createDataSource(config.getDataSources(),
+// rule.getShardingRuleConfiguration(), config.getConfigMap(), config.getProps());
+// }
+//
+// /**
+// * 瑙f瀽yml
+// *
+// * @return yaml 閰嶇疆鏂囦欢
+// * @throws IOException IO 寮傚父
+// * @throws FileNotFoundException 鏂囦欢鏈彂鐜板紓甯�
+// * @throws UnsupportedEncodingException 涓嶆敮鎸佺紪鐮佸紓甯�
+// */
+// private MasterSlaveDataSourceFactory parse() throws IOException, FileNotFoundException, UnsupportedEncodingException {
+// Resource certResource = new ClassPathResource(SHARDING_YML_PATH);
+// try (
+// InputStreamReader inputStreamReader = new InputStreamReader(certResource.getInputStream(), "UTF-8")
+// ) {
+// return YamlMasterSlaveDataSourceFactory;
+// }
+// }
}
--
Gitblit v1.8.0