Search in sources :

Example 16 with Column

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);
    }
}
Also used : Condition(io.shardingjdbc.core.parsing.parser.context.condition.Condition) SQLNumberExpression(io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression) GeneratedKey(io.shardingjdbc.core.parsing.parser.context.GeneratedKey) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) SQLPlaceholderExpression(io.shardingjdbc.core.parsing.parser.expression.SQLPlaceholderExpression)

Example 17 with Column

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")));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Example 18 with Column

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", "")));
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Example 19 with 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", "")));
}
Also used : StandardShardingStrategyConfiguration(io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration) TestPreciseShardingAlgorithm(io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm) ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Example 20 with 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")));
}
Also used : ShardingRuleConfiguration(io.shardingjdbc.core.api.config.ShardingRuleConfiguration) Column(io.shardingjdbc.core.parsing.parser.context.condition.Column) Test(org.junit.Test)

Aggregations

Column (io.shardingjdbc.core.parsing.parser.context.condition.Column)21 Condition (io.shardingjdbc.core.parsing.parser.context.condition.Condition)15 ShardingRuleConfiguration (io.shardingjdbc.core.api.config.ShardingRuleConfiguration)5 Test (org.junit.Test)5 Range (com.google.common.collect.Range)4 RangeShardingValue (io.shardingjdbc.core.api.algorithm.sharding.RangeShardingValue)4 SQLExpression (io.shardingjdbc.core.parsing.parser.expression.SQLExpression)4 LinkedList (java.util.LinkedList)4 SQLParsingEngine (io.shardingjdbc.core.parsing.SQLParsingEngine)3 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)3 TestPreciseShardingAlgorithm (io.shardingjdbc.core.api.algorithm.fixture.TestPreciseShardingAlgorithm)2 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)2 SQLNumberExpression (io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression)2 SQLPlaceholderExpression (io.shardingjdbc.core.parsing.parser.expression.SQLPlaceholderExpression)2 DMLStatement (io.shardingjdbc.core.parsing.parser.sql.dml.DMLStatement)2 ExpectedCondition (io.shardingjdbc.core.parsing.integrate.jaxb.condition.ExpectedCondition)1 GeneratedKey (io.shardingjdbc.core.parsing.parser.context.GeneratedKey)1 SQLIgnoreExpression (io.shardingjdbc.core.parsing.parser.expression.SQLIgnoreExpression)1 SQLTextExpression (io.shardingjdbc.core.parsing.parser.expression.SQLTextExpression)1 InsertStatement (io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement)1