提交 fc1a9fb8 编写于 作者: T terrymanu

refactor SQLContext

上级 735f5da6
......@@ -20,13 +20,13 @@ package com.dangdang.ddframe.rdb.sharding.parser.sql.context;
import com.dangdang.ddframe.rdb.sharding.parser.result.router.Condition;
import com.dangdang.ddframe.rdb.sharding.parser.result.router.ConditionContext;
import com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLBuilder;
import com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLStatementType;
import com.dangdang.ddframe.rdb.sharding.parser.sql.expr.SQLExpr;
import com.dangdang.ddframe.rdb.sharding.parser.sql.expr.SQLIdentifierExpr;
import com.dangdang.ddframe.rdb.sharding.parser.sql.expr.SQLPropertyExpr;
import com.dangdang.ddframe.rdb.sharding.util.SQLUtil;
import com.google.common.base.Optional;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
import java.util.ArrayList;
......@@ -41,18 +41,29 @@ import java.util.List;
*
* @author zhangliang
*/
@RequiredArgsConstructor
@Getter
public abstract class AbstractSQLContext implements SQLContext {
private final String originalSQL;
private List<TableContext> tables = new ArrayList<>();
private final SQLStatementType type;
private final List<TableContext> tables = new ArrayList<>();
private final Collection<ConditionContext> conditionContexts = new LinkedList<>();
private final List<SQLToken> sqlTokens = new LinkedList<>();
public AbstractSQLContext(final String originalSQL, final SQLStatementType type) {
this.originalSQL = originalSQL;
this.type = type;
}
@Override
public final SQLStatementType getType() {
return type;
}
@Override
public Optional<Condition.Column> findColumn(final SQLExpr expr) {
if (expr instanceof SQLPropertyExpr) {
......
......@@ -29,11 +29,6 @@ import lombok.Getter;
public final class DeleteSQLContext extends AbstractSQLContext {
public DeleteSQLContext(final String originalSQL) {
super(originalSQL);
}
@Override
public SQLStatementType getType() {
return SQLStatementType.DELETE;
super(originalSQL, SQLStatementType.DELETE);
}
}
......@@ -32,12 +32,7 @@ public final class InsertSQLContext extends AbstractSQLContext {
private final GeneratedKeyContext generatedKeyContext;
public InsertSQLContext(final String originalSQL) {
super(originalSQL);
super(originalSQL, SQLStatementType.INSERT);
generatedKeyContext = new GeneratedKeyContext();
}
@Override
public SQLStatementType getType() {
return SQLStatementType.INSERT;
}
}
......@@ -47,16 +47,7 @@ public final class SelectSQLContext extends AbstractSQLContext {
private LimitContext limitContext;
private SelectSQLContext parent;
private List<SelectSQLContext> children = new LinkedList<>();
public SelectSQLContext(final String originalSQL) {
super(originalSQL);
}
@Override
public SQLStatementType getType() {
return SQLStatementType.SELECT;
super(originalSQL, SQLStatementType.SELECT);
}
}
......@@ -27,11 +27,6 @@ import com.dangdang.ddframe.rdb.sharding.parser.result.router.SQLStatementType;
public final class UpdateSQLContext extends AbstractSQLContext {
public UpdateSQLContext(final String originalSQL) {
super(originalSQL);
}
@Override
public SQLStatementType getType() {
return SQLStatementType.UPDATE;
super(originalSQL, SQLStatementType.UPDATE);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册