Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
735f5da6
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
735f5da6
编写于
4月 26, 2017
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove ParserContext
上级
d0503268
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
55 deletion
+18
-55
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parser/SQLParseEngine.java
.../dangdang/ddframe/rdb/sharding/parser/SQLParseEngine.java
+18
-23
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parser/visitor/ParseContext.java
...ang/ddframe/rdb/sharding/parser/visitor/ParseContext.java
+0
-32
未找到文件。
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parser/SQLParseEngine.java
浏览文件 @
735f5da6
...
...
@@ -29,7 +29,6 @@ import com.dangdang.ddframe.rdb.sharding.parser.sql.context.SQLContext;
import
com.dangdang.ddframe.rdb.sharding.parser.sql.context.SelectItemContext
;
import
com.dangdang.ddframe.rdb.sharding.parser.sql.context.SelectSQLContext
;
import
com.dangdang.ddframe.rdb.sharding.parser.sql.context.TableContext
;
import
com.dangdang.ddframe.rdb.sharding.parser.visitor.ParseContext
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -52,39 +51,35 @@ public final class SQLParseEngine {
* @return SQL解析结果
*/
public
SQLParsedResult
parse
()
{
ParseContext
parseContext
=
getParseContex
t
(
sqlContext
);
SQLParsedResult
result
=
getSQLParsedResul
t
(
sqlContext
);
if
(
sqlContext
instanceof
SelectSQLContext
)
{
parseSelect
(
parseContex
t
,
(
SelectSQLContext
)
sqlContext
);
parseSelect
(
resul
t
,
(
SelectSQLContext
)
sqlContext
);
}
else
if
(
sqlContext
instanceof
InsertSQLContext
)
{
parseInsert
(
parseContex
t
,
(
InsertSQLContext
)
sqlContext
);
parseInsert
(
resul
t
,
(
InsertSQLContext
)
sqlContext
);
}
parseContext
.
getParsedResult
()
.
getRouteContext
().
setSqlBuilder
(
sqlContext
.
toSqlBuilder
());
return
parseContext
.
getParsedResult
()
;
result
.
getRouteContext
().
setSqlBuilder
(
sqlContext
.
toSqlBuilder
());
return
result
;
}
private
ParseContext
getParseContext
(
final
SQLContext
sqlContext
)
{
ParseContext
result
=
new
ParseContext
();
SQLParsedResult
sqlParsedResult
=
result
.
getParsedResult
();
private
SQLParsedResult
getSQLParsedResult
(
final
SQLContext
sqlContext
)
{
SQLParsedResult
result
=
new
SQLParsedResult
();
if
(
sqlContext
.
getConditionContexts
().
isEmpty
())
{
sqlParsedR
esult
.
getConditionContexts
().
add
(
new
ConditionContext
());
r
esult
.
getConditionContexts
().
add
(
new
ConditionContext
());
}
else
{
sqlParsedR
esult
.
getConditionContexts
().
addAll
(
sqlContext
.
getConditionContexts
());
r
esult
.
getConditionContexts
().
addAll
(
sqlContext
.
getConditionContexts
());
}
for
(
TableContext
each
:
sqlContext
.
getTables
())
{
sqlParsedR
esult
.
getRouteContext
().
getTables
().
add
(
each
);
r
esult
.
getRouteContext
().
getTables
().
add
(
each
);
}
sqlParsedR
esult
.
getRouteContext
().
setSqlStatementType
(
sqlContext
.
getType
());
r
esult
.
getRouteContext
().
setSqlStatementType
(
sqlContext
.
getType
());
return
result
;
}
private
void
parseInsert
(
final
ParseContext
parseContex
t
,
final
InsertSQLContext
sqlContext
)
{
parseContext
.
getParsedResult
()
.
setGeneratedKeyContext
(
sqlContext
.
getGeneratedKeyContext
());
private
void
parseInsert
(
final
SQLParsedResult
sqlParsedResul
t
,
final
InsertSQLContext
sqlContext
)
{
sqlParsedResult
.
setGeneratedKeyContext
(
sqlContext
.
getGeneratedKeyContext
());
}
private
void
parseSelect
(
final
ParseContext
parseContext
,
final
SelectSQLContext
sqlContext
)
{
SQLParsedResult
sqlParsedResult
=
parseContext
.
getParsedResult
();
private
void
parseSelect
(
final
SQLParsedResult
sqlParsedResult
,
final
SelectSQLContext
sqlContext
)
{
for
(
SelectItemContext
each
:
sqlContext
.
getItemContexts
())
{
if
(
each
instanceof
AggregationSelectItemContext
)
{
AggregationSelectItemContext
aggregationSelectItemContext
=
(
AggregationSelectItemContext
)
each
;
...
...
@@ -105,22 +100,22 @@ public final class SQLParseEngine {
if
(!
sqlContext
.
getGroupByContexts
().
isEmpty
())
{
for
(
GroupByContext
each
:
sqlContext
.
getGroupByContexts
())
{
parseContext
.
getParsedResult
()
.
getMergeContext
().
getGroupByContexts
().
add
(
each
);
sqlParsedResult
.
getMergeContext
().
getGroupByContexts
().
add
(
each
);
}
}
if
(!
sqlContext
.
getOrderByContexts
().
isEmpty
())
{
for
(
OrderByContext
each
:
sqlContext
.
getOrderByContexts
())
{
if
(
each
.
getIndex
().
isPresent
())
{
parseContext
.
getParsedResult
()
.
getMergeContext
().
getOrderByContexts
().
add
(
new
OrderByContext
(
each
.
getIndex
().
get
(),
each
.
getOrderByType
()));
sqlParsedResult
.
getMergeContext
().
getOrderByContexts
().
add
(
new
OrderByContext
(
each
.
getIndex
().
get
(),
each
.
getOrderByType
()));
}
else
{
parseContext
.
getParsedResult
()
.
getMergeContext
().
getOrderByContexts
().
add
(
each
);
sqlParsedResult
.
getMergeContext
().
getOrderByContexts
().
add
(
each
);
}
}
}
if
(
null
!=
sqlContext
.
getLimitContext
())
{
parseContext
.
getParsedResult
()
.
getMergeContext
().
setLimit
(
sqlParsedResult
.
getMergeContext
().
setLimit
(
new
Limit
(
sqlContext
.
getLimitContext
().
getOffset
().
isPresent
()
?
sqlContext
.
getLimitContext
().
getOffset
().
get
()
:
0
,
sqlContext
.
getLimitContext
().
getRowCount
(),
sqlContext
.
getLimitContext
().
getOffsetParameterIndex
(),
sqlContext
.
getLimitContext
().
getRowCountParameterIndex
()));
}
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parser/visitor/ParseContext.java
已删除
100644 → 0
浏览文件 @
d0503268
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/
package
com.dangdang.ddframe.rdb.sharding.parser.visitor
;
import
com.dangdang.ddframe.rdb.sharding.parser.result.SQLParsedResult
;
import
lombok.Getter
;
/**
* 解析过程的上下文对象.
*
* @author zhangliang
*/
@Getter
public
final
class
ParseContext
{
private
final
SQLParsedResult
parsedResult
=
new
SQLParsedResult
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录