Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
7630b243
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7630b243
编写于
8月 23, 2012
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
go on refactor
上级
4a57504a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
62 deletion
+14
-62
bee-engine/src/main/java/com/dianping/bee/server/mysql/SelectResponse.java
...in/java/com/dianping/bee/server/mysql/SelectResponse.java
+11
-58
bee-engine/src/test/java/com/dianping/bee/engine/spi/SpiTest.java
...ne/src/test/java/com/dianping/bee/engine/spi/SpiTest.java
+3
-4
未找到文件。
bee-engine/src/main/java/com/dianping/bee/server/mysql/SelectResponse.java
浏览文件 @
7630b243
...
...
@@ -19,8 +19,6 @@ import java.sql.SQLException;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.sql.RowSet
;
import
org.apache.log4j.Logger
;
import
com.alibaba.cobar.ErrorCode
;
...
...
@@ -35,6 +33,9 @@ import com.alibaba.cobar.protocol.mysql.RowDataPacket;
import
com.alibaba.cobar.server.ServerConnection
;
import
com.alibaba.cobar.util.IntegerUtil
;
import
com.alibaba.cobar.util.StringUtil
;
import
com.dianping.bee.engine.spi.RowSet
;
import
com.dianping.bee.engine.spi.Statement
;
import
com.dianping.bee.engine.spi.StatementManager
;
/**
* @author <a href="mailto:yiming.liu@dianping.com">Yiming Liu</a>
...
...
@@ -43,42 +44,6 @@ public class SelectResponse {
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
SelectResponse
.
class
);
private
static
final
Map
<
String
,
IQueryInterface
>
queryInterfaces
=
new
HashMap
<
String
,
IQueryInterface
>();
/**
* find Query Engine by schema
*
* @param c
* @return
*/
private
static
IQueryInterface
getQueryInterface
(
ServerConnection
c
)
{
String
schema
=
c
.
getSchema
();
SchemaConfig
schemaConfig
=
WhaleServer
.
getInstance
().
getConfig
().
getSchemas
().
get
(
schema
);
if
(
schemaConfig
!=
null
)
{
String
dataNode
=
schemaConfig
.
getDataNode
();
String
dataSourceName
=
WhaleServer
.
getInstance
().
getConfig
().
getDataNodes
().
get
(
dataNode
).
getSource
()
.
getName
();
DataSourceConfig
dataSourceConfig
=
WhaleServer
.
getInstance
().
getConfig
().
getDataSources
().
get
(
dataSourceName
);
String
type
=
dataSourceConfig
.
getType
();
if
(
"whale"
.
equals
(
type
))
{
String
classPath
=
dataSourceConfig
.
getSqlMode
();
IQueryInterface
queryInstance
=
queryInterfaces
.
get
(
classPath
);
if
(
queryInstance
==
null
)
{
try
{
queryInstance
=
(
IQueryInterface
)
Class
.
forName
(
classPath
).
newInstance
();
queryInterfaces
.
put
(
classPath
,
queryInstance
);
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"Instance Query Interface Failed"
,
e
);
return
null
;
}
}
return
queryInstance
;
}
else
if
(
"mysql"
.
equals
(
type
))
{
}
}
return
null
;
}
/**
*
* @param rowData
...
...
@@ -133,28 +98,17 @@ public class SelectResponse {
* @param c
* @param stmt
*/
public
static
void
response
(
ServerConnection
c
,
String
stmt
)
{
IQueryInterface
queryInterface
=
getQueryInterface
(
c
);
if
(
queryInterface
==
null
)
{
LOGGER
.
warn
(
"No Query Interface Found"
);
c
.
writeErrMessage
(
ErrorCode
.
ER_BAD_DB_ERROR
,
stmt
);
return
;
}
public
static
void
response
(
ServerConnection
c
,
String
sql
)
{
StatementManager
statementManager
=
lookup
(
StatementManager
.
class
);
Statement
stmt
=
statementManager
.
parse
(
sql
);
RowSet
result
=
null
;
try
{
result
=
queryInterface
.
query
(
stmt
);
}
catch
(
SQLException
e
)
{
LOGGER
.
warn
(
stmt
,
e
);
c
.
writeErrMessage
(
ErrorCode
.
ER_PARSE_ERROR
,
stmt
);
return
;
}
RowSet
result
=
stmt
.
query
();
byte
packetId
=
0
;
EOFPacket
eof
=
new
EOFPacket
();
ByteBuffer
buffer
=
c
.
allocate
();
// write header
int
fieldCount
=
result
.
get
MetaData
().
getColumnCount
();
int
fieldCount
=
result
.
get
Columns
();
ResultSetHeaderPacket
header
=
PacketUtil
.
getHeader
(
fieldCount
);
header
.
packetId
=
++
packetId
;
buffer
=
header
.
write
(
buffer
,
c
);
...
...
@@ -163,8 +117,7 @@ public class SelectResponse {
int
columnIndex
=
0
;
FieldPacket
[]
fields
=
new
FieldPacket
[
fieldCount
];
for
(
int
i
=
0
;
i
<
fieldCount
;
i
++)
{
fields
[
columnIndex
]
=
PacketUtil
.
getField
(
result
.
getMetaData
().
getColumnNames
()[
i
],
result
.
getMetaData
()
.
getColumnTypes
()[
i
]);
fields
[
columnIndex
]
=
PacketUtil
.
getField
(
result
.
getColumn
(
i
).
getName
(),
result
.
getColumn
(
i
).
getType
());
fields
[
columnIndex
++].
packetId
=
++
packetId
;
}
eof
.
packetId
=
++
packetId
;
...
...
@@ -175,8 +128,8 @@ public class SelectResponse {
buffer
=
eof
.
write
(
buffer
,
c
);
// write rows
for
(
int
rowIndex
=
0
;
rowIndex
<
result
.
get
Data
().
length
;
rowIndex
++)
{
RowDataPacket
row
=
getRow
(
result
.
get
Data
()[
rowIndex
]
,
result
.
getMetaData
().
getColumnTypes
(),
c
.
getCharset
());
for
(
int
rowIndex
=
0
;
rowIndex
<
result
.
get
Rows
()
;
rowIndex
++)
{
RowDataPacket
row
=
getRow
(
result
.
get
Row
(
rowIndex
)
,
result
.
getMetaData
().
getColumnTypes
(),
c
.
getCharset
());
row
.
packetId
=
++
packetId
;
buffer
=
row
.
write
(
buffer
,
c
);
}
...
...
bee-engine/src/test/java/com/dianping/bee/engine/spi/SpiTest.java
浏览文件 @
7630b243
...
...
@@ -11,11 +11,10 @@ import com.site.lookup.ComponentTestCase;
public
class
SpiTest
extends
ComponentTestCase
{
@Test
public
void
sample
()
throws
Exception
{
TableProviderManager
tableProviderManager
=
lookup
(
TableProviderManager
.
class
);
StatementManager
statementManager
=
lookup
(
StatementManager
.
class
);
Statement
stmt
=
statementManager
.
parse
(
"select type, sum(failures) from transaction where domain=? and starttime=?"
);
TableProvider
table
=
tableProviderManager
.
getTableProvider
(
stmt
.
getTableName
()
);
RowSet
rowset
=
table
.
query
(
stmt
);
Statement
stmt
=
statementManager
.
parse
(
"select type, sum(failures) from transaction where domain=? and starttime=?"
);
RowSet
rowset
=
stmt
.
query
(
);
display
(
rowset
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录