use of com.dangdang.ddframe.rdb.sharding.config.common.api.config.AutoIncrementColumnConfig 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 com.dangdang.ddframe.rdb.sharding.config.common.api.config.AutoIncrementColumnConfig in project sharding-jdbc by dangdangdotcom.
the class ShardingRuleBuilderTest method createTableRuleConfig.
private TableRuleConfig createTableRuleConfig(final String logicTable) {
TableRuleConfig result = new TableRuleConfig();
result.setActualTables(logicTable + "_${[0, 1]}");
result.setDataSourceNames("ds_${0..1}");
result.setDatabaseStrategy(getDatabaseStrategyConfig(SingleAlgorithm.class.getName()));
result.setTableStrategy(getTableStrategyConfigForExpression());
Map<String, String> autoIncrementColumnMap = new HashMap<>();
autoIncrementColumnMap.put("order_id", null);
AutoIncrementColumnConfig orderIdConfig = new AutoIncrementColumnConfig();
orderIdConfig.setColumnName("order_id");
autoIncrementColumnMap.put("order_item_id", "com.dangdang.ddframe.rdb.sharding.config.common.fixture.DecrementIdGenerator");
AutoIncrementColumnConfig orderItemIdConfig = new AutoIncrementColumnConfig();
orderItemIdConfig.setColumnName("order_item_id");
orderItemIdConfig.setColumnIdGeneratorClass(DecrementIdGenerator.class.getName());
result.setAutoIncrementColumns(Arrays.asList(orderIdConfig, orderItemIdConfig));
return result;
}
Aggregations