提交 33b45925 编写于 作者: T terrymanu

refactor api 4th version

上级 94745411
/*
* Copyright 1999-2015 dangdang.com.
* <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 com.dangdang.ddframe.rdb.sharding.spring.datasource;
import com.dangdang.ddframe.rdb.sharding.api.rule.MasterSlaveRule;
import com.dangdang.ddframe.rdb.sharding.api.strategy.slave.MasterSlaveLoadBalanceStrategy;
import com.dangdang.ddframe.rdb.sharding.api.strategy.slave.MasterSlaveLoadBalanceStrategyType;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.datasource.MasterSlaveDataSource;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Map;
/**
* Sharding datasource for spring namespace.
*
* @author zhangliang
*/
public class SpringMasterSlaveDataSource extends MasterSlaveDataSource {
public SpringMasterSlaveDataSource(final String name, final String masterDataSourceName,
final DataSource masterDataSource, final Map<String, DataSource> slaveDataSourceMap) throws SQLException {
super(new MasterSlaveRule(name, masterDataSourceName, masterDataSource, slaveDataSourceMap));
}
public SpringMasterSlaveDataSource(final String name, final String masterDataSourceName,
final DataSource masterDataSource, final Map<String, DataSource> slaveDataSourceMap, final MasterSlaveLoadBalanceStrategy strategy) throws SQLException {
super(new MasterSlaveRule(name, masterDataSourceName, masterDataSource, slaveDataSourceMap, strategy));
}
public SpringMasterSlaveDataSource(final String name, final String masterDataSourceName,
final DataSource masterDataSource, final Map<String, DataSource> slaveDataSourceMap, final MasterSlaveLoadBalanceStrategyType strategyType) throws SQLException {
super(new MasterSlaveRule(name, masterDataSourceName, masterDataSource, slaveDataSourceMap, strategyType.getStrategy()));
}
}
......@@ -18,7 +18,7 @@
package com.dangdang.ddframe.rdb.sharding.spring.namespace.parser;
import com.dangdang.ddframe.rdb.sharding.api.strategy.slave.MasterSlaveLoadBalanceStrategyType;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.datasource.MasterSlaveDataSource;
import com.dangdang.ddframe.rdb.sharding.spring.datasource.SpringMasterSlaveDataSource;
import com.dangdang.ddframe.rdb.sharding.spring.namespace.constants.MasterSlaveDataSourceBeanDefinitionParserTag;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
......@@ -44,7 +44,7 @@ public class MasterSlaveDataSourceBeanDefinitionParser extends AbstractBeanDefin
//CHECKSTYLE:OFF
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
//CHECKSTYLE:ON
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(MasterSlaveDataSource.class);
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SpringMasterSlaveDataSource.class);
factory.addConstructorArgValue(parseId(element));
String masterDataSourceName = parseMasterDataSourceRef(element);
factory.addConstructorArgValue(masterDataSourceName);
......
......@@ -40,7 +40,7 @@ import java.util.Map;
* @author zhangliang
*/
@Getter
public final class MasterSlaveDataSource extends AbstractDataSourceAdapter {
public class MasterSlaveDataSource extends AbstractDataSourceAdapter {
private static final ThreadLocal<Boolean> DML_FLAG = new ThreadLocal<Boolean>() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册