use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class InsertStatement method appendGenerateKeyToken.
private void appendGenerateKeyToken(final ShardingRule shardingRule, final TableRule tableRule, final ItemsToken valuesToken) {
if (0 == getParametersIndex()) {
Number generatedKey = shardingRule.generateKey(tableRule.getLogicTable());
valuesToken.getItems().add(generatedKey.toString());
getConditions().add(new Condition(new Column(tableRule.getGenerateKeyColumn(), tableRule.getLogicTable()), new SQLNumberExpression(generatedKey)), shardingRule);
this.generatedKey = new GeneratedKey(tableRule.getLogicTable(), -1, generatedKey);
} else {
valuesToken.getItems().add(Symbol.QUESTION.getLiterals());
getConditions().add(new Condition(new Column(tableRule.getGenerateKeyColumn(), tableRule.getLogicTable()), new SQLPlaceholderExpression(getParametersIndex())), shardingRule);
generatedKey = new GeneratedKey(tableRule.getGenerateKeyColumn(), getParametersIndex(), null);
}
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertIsShardingColumnForDatabaseShardingStrategy.
@Test
public void assertIsShardingColumnForDatabaseShardingStrategy() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithAllStrategies());
assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "logic_Table")));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertIsShardingColumnForDefaultDatabaseShardingStrategy.
@Test
public void assertIsShardingColumnForDefaultDatabaseShardingStrategy() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm()));
assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "")));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertIsShardingColumnForDefaultTableShardingStrategy.
@Test
public void assertIsShardingColumnForDefaultTableShardingStrategy() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("column", new TestPreciseShardingAlgorithm()));
assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "")));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Column in project sharding-jdbc by shardingjdbc.
the class ShardingRuleTest method assertIsNotShardingColumn.
@Test
public void assertIsNotShardingColumn() {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(createTableRuleConfigWithAllStrategies());
assertFalse(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn(new Column("column", "other_Table")));
}
Aggregations