use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project sharding-jdbc by dangdangdotcom.
the class ShardingJdbcDataSourceBeanDefinitionParser method parseTableRuleConfig.
private BeanDefinition parseTableRuleConfig(final Element tableElement) {
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(TableRuleConfig.class);
String dynamic = tableElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.DYNAMIC_TABLE_ATTRIBUTE);
if (!Strings.isNullOrEmpty(dynamic)) {
factory.addPropertyValue("dynamic", dynamic);
}
String actualTables = tableElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.ACTUAL_TABLES_ATTRIBUTE);
if (!Strings.isNullOrEmpty(actualTables)) {
factory.addPropertyValue("actualTables", actualTables);
}
String dataSourceNames = tableElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.DATA_SOURCE_NAMES_ATTRIBUTE);
if (!Strings.isNullOrEmpty(dataSourceNames)) {
factory.addPropertyValue("dataSourceNames", dataSourceNames);
}
String databaseStrategy = tableElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.DATABASE_STRATEGY_ATTRIBUTE);
if (!Strings.isNullOrEmpty(databaseStrategy)) {
factory.addPropertyReference("databaseStrategy", databaseStrategy);
}
String tableStrategy = tableElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.TABLE_STRATEGY_ATTRIBUTE);
if (!Strings.isNullOrEmpty(tableStrategy)) {
factory.addPropertyReference("tableStrategy", tableStrategy);
}
List<Element> autoIncrementColumns = DomUtils.getChildElementsByTagName(tableElement, ShardingJdbcDataSourceBeanDefinitionParserTag.AUTO_INCREMENT_COLUMN);
if (null == autoIncrementColumns || autoIncrementColumns.isEmpty()) {
return factory.getBeanDefinition();
}
factory.addPropertyValue("autoIncrementColumns", Lists.transform(autoIncrementColumns, new Function<Element, AutoIncrementColumnConfig>() {
@Override
public AutoIncrementColumnConfig apply(final Element input) {
AutoIncrementColumnConfig result = new AutoIncrementColumnConfig();
result.setColumnName(input.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.COLUMN_NAME));
result.setColumnIdGeneratorClass(input.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.COLUMN_ID_GENERATOR_CLASS));
return result;
}
}));
return factory.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project sharding-jdbc by dangdangdotcom.
the class ShardingJdbcDataSourceBeanDefinitionParser method parseInternal.
@Override
protected //CHECKSTYLE:OFF
AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
//CHECKSTYLE:ON
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SpringShardingDataSource.class);
factory.addConstructorArgValue(parseShardingRuleConfig(element, parserContext));
factory.addConstructorArgValue(parseProperties(element, parserContext));
return factory.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project sharding-jdbc by dangdangdotcom.
the class ShardingJdbcDataSourceBeanDefinitionParser method parseShardingRuleConfig.
private BeanDefinition parseShardingRuleConfig(final Element element, final ParserContext parserContext) {
Element shardingRuleElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.SHARDING_RULE_CONFIG_TAG);
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ShardingRuleConfig.class);
factory.addPropertyValue("dataSource", parseDataSources(shardingRuleElement, parserContext));
parseDefaultDataSource(factory, shardingRuleElement);
factory.addPropertyValue("tables", parseTableRulesConfig(shardingRuleElement));
factory.addPropertyValue("bindingTables", parseBindingTablesConfig(shardingRuleElement));
factory.addPropertyValue("defaultDatabaseStrategy", parseDefaultDatabaseStrategyConfig(shardingRuleElement));
factory.addPropertyValue("defaultTableStrategy", parseDefaultTableStrategyConfig(shardingRuleElement));
parseIdGenerator(factory, shardingRuleElement);
return factory.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project sharding-jdbc by dangdangdotcom.
the class ShardingJdbcDataSourceBeanDefinitionParser method parseBindingTablesConfig.
private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
if (null == bindingTableRulesElement) {
return Collections.emptyList();
}
List<Element> bindingTableRuleElements = DomUtils.getChildElementsByTagName(bindingTableRulesElement, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULE_TAG);
BeanDefinitionBuilder bindingTableRuleFactory = BeanDefinitionBuilder.rootBeanDefinition(BindingTableRuleConfig.class);
List<BeanDefinition> result = new ManagedList<>(bindingTableRuleElements.size());
for (Element bindingTableRuleElement : bindingTableRuleElements) {
bindingTableRuleFactory.addPropertyValue("tableNames", bindingTableRuleElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLES_ATTRIBUTE));
result.add(bindingTableRuleFactory.getBeanDefinition());
}
return result;
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project sharding-jdbc by dangdangdotcom.
the class ShardingJdbcStrategyBeanDefinition method getBeanDefinitionByElement.
static AbstractBeanDefinition getBeanDefinitionByElement(final Element element) {
BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(StrategyConfig.class);
factory.addPropertyValue("shardingColumns", element.getAttribute(ShardingJdbcStrategyBeanDefinitionParserTag.SHARDING_COLUMNS_ATTRIBUTE));
factory.addPropertyValue("algorithmClassName", element.getAttribute(ShardingJdbcStrategyBeanDefinitionParserTag.ALGORITHM_CLASS_ATTRIBUTE));
factory.addPropertyValue("algorithmExpression", element.getAttribute(ShardingJdbcStrategyBeanDefinitionParserTag.ALGORITHM_EXPRESSION_ATTRIBUTE));
return factory.getBeanDefinition();
}
Aggregations