use of com.dangdang.ddframe.rdb.sharding.parser.result.router.Table in project sharding-jdbc by dangdangdotcom.
the class ParseContext method addTable.
/**
* 将表对象加入解析上下文.
*
* @param x 表名表达式, 来源于FROM, INSERT ,UPDATE, DELETE等语句
*/
public Table addTable(final SQLExprTableSource x) {
Table result = new Table(SQLUtil.getExactlyValue(x.getExpr().toString()), SQLUtil.getExactlyValue(x.getAlias()));
parsedResult.getRouteContext().getTables().add(result);
return result;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.router.Table in project sharding-jdbc by dangdangdotcom.
the class ParseContext method setCurrentTable.
/**
* 设置当前正在访问的表.
*
* @param currentTableName 表名称
* @param currentAlias 表别名
*/
public void setCurrentTable(final String currentTableName, final Optional<String> currentAlias) {
Table table = new Table(SQLUtil.getExactlyValue(currentTableName), currentAlias.isPresent() ? Optional.of(SQLUtil.getExactlyValue(currentAlias.get())) : currentAlias);
parsedResult.getRouteContext().getTables().add(table);
currentTable = table;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.router.Table in project sharding-jdbc by dangdangdotcom.
the class AbstractBaseParseTest method getDataParameter.
private static Object[] getDataParameter(final Assert assertObj) {
Object[] result = new Object[6];
result[0] = assertObj.getId();
result[1] = assertObj.getSql();
result[2] = assertObj.getExpectedSQL();
result[3] = Lists.transform(assertObj.getTables(), new Function<com.dangdang.ddframe.rdb.sharding.parser.jaxb.Table, Table>() {
@Override
public Table apply(final com.dangdang.ddframe.rdb.sharding.parser.jaxb.Table input) {
return new Table(input.getName(), input.getAlias());
}
});
if (null == assertObj.getConditionContexts()) {
result[4] = Collections.<ConditionContext>emptyList();
} else {
result[4] = Lists.transform(assertObj.getConditionContexts(), new Function<com.dangdang.ddframe.rdb.sharding.parser.jaxb.ConditionContext, ConditionContext>() {
@Override
public ConditionContext apply(final com.dangdang.ddframe.rdb.sharding.parser.jaxb.ConditionContext input) {
ConditionContext result = new ConditionContext();
if (null == input.getConditions()) {
return result;
}
for (com.dangdang.ddframe.rdb.sharding.parser.jaxb.Condition each : input.getConditions()) {
Condition condition = new Condition(new Column(each.getColumnName(), each.getTableName()), BinaryOperator.valueOf(each.getOperator().toUpperCase()));
condition.getValues().addAll(Lists.transform(each.getValues(), new Function<Value, Comparable<?>>() {
@Override
public Comparable<?> apply(final Value input) {
return input.getValueWithType();
}
}));
if (null != each.getValueIndices()) {
condition.getValueIndices().addAll(each.getValueIndices());
}
result.add(condition);
}
return result;
}
});
}
MergeContext mergeContext = new MergeContext();
if (null != assertObj.getOrderByColumns()) {
mergeContext.getOrderByColumns().addAll(Lists.transform(assertObj.getOrderByColumns(), new Function<com.dangdang.ddframe.rdb.sharding.parser.jaxb.OrderByColumn, OrderByColumn>() {
@Override
public OrderByColumn apply(final com.dangdang.ddframe.rdb.sharding.parser.jaxb.OrderByColumn input) {
return Strings.isNullOrEmpty(input.getName()) ? new OrderByColumn(input.getIndex(), OrderByType.valueOf(input.getOrderByType().toUpperCase())) : new OrderByColumn(Optional.fromNullable(input.getOwner()), input.getName(), Optional.fromNullable(input.getAlias()), OrderByType.valueOf(input.getOrderByType().toUpperCase()));
}
}));
}
if (null != assertObj.getGroupByColumns()) {
mergeContext.getGroupByColumns().addAll(Lists.transform(assertObj.getGroupByColumns(), new Function<com.dangdang.ddframe.rdb.sharding.parser.jaxb.GroupByColumn, GroupByColumn>() {
@Override
public GroupByColumn apply(final com.dangdang.ddframe.rdb.sharding.parser.jaxb.GroupByColumn input) {
return new GroupByColumn(Optional.fromNullable(input.getOwner()), input.getName(), Optional.fromNullable(input.getAlias()), OrderByType.valueOf(input.getOrderByType().toUpperCase()));
}
}));
}
if (null != assertObj.getAggregationColumns()) {
mergeContext.getAggregationColumns().addAll(Lists.transform(assertObj.getAggregationColumns(), new Function<com.dangdang.ddframe.rdb.sharding.parser.jaxb.AggregationColumn, AggregationColumn>() {
@Override
public AggregationColumn apply(final com.dangdang.ddframe.rdb.sharding.parser.jaxb.AggregationColumn input) {
AggregationColumn result = new AggregationColumn(input.getExpression(), AggregationType.valueOf(input.getAggregationType().toUpperCase()), Optional.fromNullable(input.getAlias()), Optional.fromNullable(input.getOption()));
if (null != input.getIndex()) {
result.setColumnIndex(input.getIndex());
}
for (com.dangdang.ddframe.rdb.sharding.parser.jaxb.AggregationColumn each : input.getDerivedColumns()) {
result.getDerivedColumns().add(new AggregationColumn(each.getExpression(), AggregationType.valueOf(each.getAggregationType().toUpperCase()), Optional.fromNullable(each.getAlias()), Optional.fromNullable(each.getOption())));
}
return result;
}
}));
}
if (null != assertObj.getLimit()) {
mergeContext.setLimit(new Limit(assertObj.getLimit().getOffset(), assertObj.getLimit().getRowCount(), assertObj.getLimit().getOffsetParameterIndex(), assertObj.getLimit().getRowCountParameterIndex()));
}
result[5] = mergeContext;
return result;
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.router.Table in project sharding-jdbc by dangdangdotcom.
the class SQLParsedResultTest method generateRouteContext.
private void generateRouteContext(final RouteContext routeContext) throws IOException {
routeContext.getTables().add(new Table("order", Optional.of("o")));
routeContext.getTables().add(new Table("order_item", Optional.<String>absent()));
routeContext.setSqlBuilder(generateSqlBuilder());
}
use of com.dangdang.ddframe.rdb.sharding.parser.result.router.Table in project sharding-jdbc by dangdangdotcom.
the class AbstractBaseParseTest method assertRouteContext.
private void assertRouteContext(final SQLParsedResult actual) {
assertThat(actual.getRouteContext().getSqlBuilder().toString(), is(expectedSQL));
for (Table each : actual.getRouteContext().getTables()) {
assertThat(each, new ReflectionEquals(expectedTables.next()));
}
assertFalse(expectedTables.hasNext());
}
Aggregations