use of io.shardingjdbc.core.parsing.parser.context.condition.Condition in project sharding-jdbc by shardingjdbc.
the class UpdateStatementParserTest method assertUpdateStatementWitParameter.
private void assertUpdateStatementWitParameter(final DMLStatement updateStatement) {
assertThat(updateStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
assertThat(updateStatement.getTables().find("TABLE_XXX").get().getAlias().get(), is("xxx"));
List<Object> actualParameters = Arrays.<Object>asList(0, 10, 20, 30, 40, 50, 60, 70, 80);
Condition condition1 = updateStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get();
assertThat(condition1.getOperator(), is(ShardingOperator.EQUAL));
assertThat(((ListShardingValue<? extends Comparable>) condition1.getShardingValue(actualParameters)).getValues().iterator().next(), is((Comparable) 20));
Condition condition2 = updateStatement.getConditions().find(new Column("field2", "TABLE_XXX")).get();
assertThat(condition2.getOperator(), is(ShardingOperator.IN));
Iterator<?> shardingValue2 = ((ListShardingValue) condition2.getShardingValue(actualParameters)).getValues().iterator();
assertThat(shardingValue2.next(), is((Object) 40));
assertThat(shardingValue2.next(), is((Object) 50));
assertFalse(shardingValue2.hasNext());
Condition condition3 = updateStatement.getConditions().find(new Column("field3", "TABLE_XXX")).get();
assertThat(condition3.getOperator(), is(ShardingOperator.BETWEEN));
Range shardingValue3 = ((RangeShardingValue) condition3.getShardingValue(actualParameters)).getValueRange();
assertThat(shardingValue3.lowerEndpoint(), is((Comparable) 70));
assertThat(shardingValue3.upperEndpoint(), is((Comparable) 80));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Condition in project sharding-jdbc by shardingjdbc.
the class UpdateStatementParserTest method parseWithSpecialSyntax.
private void parseWithSpecialSyntax(final DatabaseType dbType, final String actualSQL) {
ShardingRule shardingRule = createShardingRule();
DMLStatement updateStatement = (DMLStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse();
assertThat(updateStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
assertFalse(updateStatement.getTables().find("TABLE_XXX").get().getAlias().isPresent());
Condition condition = updateStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get();
assertThat(condition.getOperator(), is(ShardingOperator.EQUAL));
assertThat(((ListShardingValue<? extends Comparable>) condition.getShardingValue(Collections.emptyList())).getValues().iterator().next(), is((Object) 1));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Condition in project sharding-jdbc by shardingjdbc.
the class DeleteStatementParserTest method assertDeleteStatementWithParameter.
private void assertDeleteStatementWithParameter(final DMLStatement deleteStatement) {
assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
assertThat(deleteStatement.getTables().find("xxx").get().getAlias().get(), is("xxx"));
List<Object> actualParameters = Arrays.<Object>asList(0, 10, 20, 30, 40, 50, 60, 70, 80);
Condition condition1 = deleteStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get();
assertThat(condition1.getOperator(), is(ShardingOperator.EQUAL));
assertThat(((ListShardingValue) condition1.getShardingValue(actualParameters)).getValues().iterator().next(), is((Object) 10));
Condition condition2 = deleteStatement.getConditions().find(new Column("field2", "TABLE_XXX")).get();
assertThat(condition2.getOperator(), is(ShardingOperator.IN));
Iterator<?> shardingValues2 = ((ListShardingValue) condition2.getShardingValue(actualParameters)).getValues().iterator();
assertThat(shardingValues2.next(), is((Object) 30));
assertThat(shardingValues2.next(), is((Object) 40));
Condition condition3 = deleteStatement.getConditions().find(new Column("field3", "TABLE_XXX")).get();
assertThat(condition3.getOperator(), is(ShardingOperator.BETWEEN));
Range shardingValues3 = ((RangeShardingValue) condition3.getShardingValue(actualParameters)).getValueRange();
assertThat(shardingValues3.lowerEndpoint(), is((Comparable) 60));
assertThat(shardingValues3.upperEndpoint(), is((Comparable) 70));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Condition in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method parseWithSpecialSyntax.
@SuppressWarnings("unchecked")
private void parseWithSpecialSyntax(final DatabaseType dbType, final String actualSQL) {
ShardingRule shardingRule = createShardingRule();
InsertStatement insertStatement = (InsertStatement) new SQLParsingEngine(dbType, actualSQL, shardingRule).parse();
assertThat(insertStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
assertFalse(insertStatement.getTables().find("TABLE_XXX").get().getAlias().isPresent());
Condition condition = insertStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get();
assertThat(condition.getOperator(), is(ShardingOperator.EQUAL));
assertThat(((ListShardingValue<? extends Comparable>) condition.getShardingValue(Collections.emptyList())).getValues().iterator().next(), is((Comparable) 1));
}
use of io.shardingjdbc.core.parsing.parser.context.condition.Condition in project sharding-jdbc by shardingjdbc.
the class InsertStatementParserTest method assertInsertStatementWithoutParameter.
@SuppressWarnings("unchecked")
private void assertInsertStatementWithoutParameter(final InsertStatement insertStatement) {
assertThat(insertStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
Condition condition = insertStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get();
assertThat(condition.getOperator(), is(ShardingOperator.EQUAL));
assertThat(((ListShardingValue<? extends Comparable>) condition.getShardingValue(Collections.emptyList())).getValues().iterator().next(), is((Comparable) 10));
}
Aggregations