Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
57906a52
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,发现更多精彩内容 >>
提交
57906a52
编写于
9月 05, 2012
作者:
Y
yanchun.yang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
ssh://192.168.8.22:58422/cat
上级
557e037e
7337e088
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
349 addition
and
131 deletion
+349
-131
bee-engine/src/main/java/com/dianping/bee/engine/build/ComponentsConfigurator.java
...com/dianping/bee/engine/build/ComponentsConfigurator.java
+7
-14
bee-engine/src/main/java/com/dianping/bee/engine/spi/PreparedStatement.java
...n/java/com/dianping/bee/engine/spi/PreparedStatement.java
+28
-0
bee-engine/src/main/java/com/dianping/bee/engine/spi/Statement.java
.../src/main/java/com/dianping/bee/engine/spi/Statement.java
+0
-1
bee-engine/src/main/java/com/dianping/bee/engine/spi/StatementManager.java
...in/java/com/dianping/bee/engine/spi/StatementManager.java
+3
-3
bee-engine/src/main/java/com/dianping/bee/engine/spi/handler/internal/PrepareHandler.java
...nping/bee/engine/spi/handler/internal/PrepareHandler.java
+53
-19
bee-engine/src/main/java/com/dianping/bee/engine/spi/handler/internal/PreparePacket.java
...anping/bee/engine/spi/handler/internal/PreparePacket.java
+18
-1
bee-engine/src/main/java/com/dianping/bee/engine/spi/handler/internal/PrepareParameterPacket.java
...e/engine/spi/handler/internal/PrepareParameterPacket.java
+5
-0
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/DefaultStatementManager.java
...ping/bee/engine/spi/internal/DefaultStatementManager.java
+15
-9
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/QueryDetector.java
...a/com/dianping/bee/engine/spi/internal/QueryDetector.java
+31
-0
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTablePreparedStatement.java
...bee/engine/spi/internal/SingleTablePreparedStatement.java
+23
-0
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTablePreparedStatementBuilder.java
...ine/spi/internal/SingleTablePreparedStatementBuilder.java
+50
-0
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTableStatement.java
...ianping/bee/engine/spi/internal/SingleTableStatement.java
+0
-11
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTableStatementBuilder.java
.../bee/engine/spi/internal/SingleTableStatementBuilder.java
+1
-16
bee-engine/src/main/java/com/dianping/bee/server/SimpleServerConnection.java
.../java/com/dianping/bee/server/SimpleServerConnection.java
+37
-25
bee-engine/src/main/java/com/dianping/bee/server/SimpleServerQueryHandler.java
...ava/com/dianping/bee/server/SimpleServerQueryHandler.java
+13
-5
bee-engine/src/main/resources/META-INF/plexus/components.xml
bee-engine/src/main/resources/META-INF/plexus/components.xml
+21
-18
bee-engine/src/test/java/com/dianping/bee/db/cat/EventIndexer.java
...e/src/test/java/com/dianping/bee/db/cat/EventIndexer.java
+9
-2
bee-engine/src/test/java/com/dianping/bee/db/cat/TransactionIndexer.java
...test/java/com/dianping/bee/db/cat/TransactionIndexer.java
+9
-2
bee-engine/src/test/java/com/dianping/bee/engine/spi/ServerTestConfigurator.java
...a/com/dianping/bee/engine/spi/ServerTestConfigurator.java
+4
-5
bee-engine/src/test/resources/com/dianping/bee/engine/spi/ServerTest.xml
...test/resources/com/dianping/bee/engine/spi/ServerTest.xml
+22
-0
未找到文件。
bee-engine/src/main/java/com/dianping/bee/engine/build/ComponentsConfigurator.java
浏览文件 @
57906a52
...
...
@@ -3,10 +3,6 @@ package com.dianping.bee.engine.build;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.dianping.bee.db.cat.CatDatabase
;
import
com.dianping.bee.db.cat.EventIndexer
;
import
com.dianping.bee.db.cat.TransactionIndexer
;
import
com.dianping.bee.db.dog.DogDatabase
;
import
com.dianping.bee.engine.spi.DatabaseProvider
;
import
com.dianping.bee.engine.spi.StatementManager
;
import
com.dianping.bee.engine.spi.TableProviderManager
;
...
...
@@ -34,6 +30,8 @@ import com.dianping.bee.engine.spi.handler.internal.ShowHandler;
import
com.dianping.bee.engine.spi.handler.internal.UseHandler
;
import
com.dianping.bee.engine.spi.internal.DefaultStatementManager
;
import
com.dianping.bee.engine.spi.internal.DefaultTableProviderManager
;
import
com.dianping.bee.engine.spi.internal.SingleTablePreparedStatement
;
import
com.dianping.bee.engine.spi.internal.SingleTablePreparedStatementBuilder
;
import
com.dianping.bee.engine.spi.internal.SingleTableRowFilter
;
import
com.dianping.bee.engine.spi.internal.SingleTableStatement
;
import
com.dianping.bee.engine.spi.internal.SingleTableStatementBuilder
;
...
...
@@ -74,22 +72,17 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
SingleTableStatementBuilder
.
class
).
is
(
PER_LOOKUP
)
//
.
req
(
TableHelper
.
class
,
SingleTableStatement
.
class
,
SingleTableRowFilter
.
class
));
all
.
add
(
C
(
SingleTablePreparedStatement
.
class
).
is
(
PER_LOOKUP
));
all
.
add
(
C
(
SingleTablePreparedStatementBuilder
.
class
).
is
(
PER_LOOKUP
)
//
.
req
(
TableHelper
.
class
,
SingleTablePreparedStatement
.
class
,
SingleTableRowFilter
.
class
));
defineHandlers
(
all
);
defineLogicalEvaluators
(
all
);
defineFunctionEvaluators
(
all
);
defineDatabaseProvider
(
all
);
return
all
;
}
// FIXME: need dependency reverse
private
void
defineDatabaseProvider
(
List
<
Component
>
all
)
{
all
.
add
(
C
(
DatabaseProvider
.
class
,
"cat"
,
CatDatabase
.
class
));
all
.
add
(
C
(
TransactionIndexer
.
class
));
all
.
add
(
C
(
EventIndexer
.
class
));
all
.
add
(
C
(
DatabaseProvider
.
class
,
"dog"
,
DogDatabase
.
class
));
}
private
void
defineFunctionEvaluators
(
List
<
Component
>
all
)
{
all
.
add
(
C
(
Evaluator
.
class
,
ConcatEvaluator
.
ID
,
ConcatEvaluator
.
class
));
}
...
...
@@ -125,7 +118,7 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
Evaluator
.
class
,
IdentifierEvaluator
.
ID
,
IdentifierEvaluator
.
class
));
all
.
add
(
C
(
Evaluator
.
class
,
ParamMarkerEvaluator
.
ID
,
ParamMarkerEvaluator
.
class
));
all
.
add
(
C
(
Evaluator
.
class
,
LiteralStringEvaluator
.
ID
,
LiteralStringEvaluator
.
class
));
all
.
add
(
C
(
Evaluator
.
class
,
LiteralNumberEvaluator
.
ID
,
LiteralNumberEvaluator
.
class
));
all
.
add
(
C
(
Evaluator
.
class
,
LiteralBooleanEvaluator
.
ID
,
LiteralBooleanEvaluator
.
class
));
...
...
bee-engine/src/main/java/com/dianping/bee/engine/spi/PreparedStatement.java
0 → 100644
浏览文件 @
57906a52
/**
* Project: bee-engine
*
* File Created at 2012-9-4
*
* Copyright 2012 dianping.com.
* All rights reserved.
*
* This software is the confidential and proprietary information of
* Dianping Company. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package
com.dianping.bee.engine.spi
;
import
java.util.List
;
/**
* @author <a href="mailto:yiming.liu@dianping.com">Yiming Liu</a>
*/
public
interface
PreparedStatement
extends
Statement
{
public
int
getParameterSize
();
public
void
setParameterSize
(
int
size
);
public
void
setParameters
(
List
<
Object
>
params
);
}
bee-engine/src/main/java/com/dianping/bee/engine/spi/Statement.java
浏览文件 @
57906a52
...
...
@@ -3,7 +3,6 @@ package com.dianping.bee.engine.spi;
import
com.dianping.bee.engine.spi.meta.RowSet
;
public
interface
Statement
{
public
int
getParameterSize
();
public
int
getColumnSize
();
...
...
bee-engine/src/main/java/com/dianping/bee/engine/spi/StatementManager.java
浏览文件 @
57906a52
...
...
@@ -7,9 +7,9 @@ public interface StatementManager {
public
Statement
build
(
String
sql
)
throws
SQLSyntaxErrorException
;
public
long
stmtPrepare
(
Statement
stmt
);
public
Statement
stmtExecute
(
long
stmtId
);
public
long
stmtPrepare
(
PreparedStatement
stmt
);
public
void
stmtClose
(
long
stmtId
);
public
PreparedStatement
getStatement
(
Long
stmtId
);
}
bee-engine/src/main/java/com/dianping/bee/engine/spi/handler/internal/PrepareHandler.java
浏览文件 @
57906a52
...
...
@@ -19,10 +19,15 @@ import java.util.List;
import
com.alibaba.cobar.ErrorCode
;
import
com.alibaba.cobar.Fields
;
import
com.alibaba.cobar.protocol.mysql.FieldPacket
;
import
com.alibaba.cobar.server.ServerConnection
;
import
com.dianping.bee.engine.spi.PreparedStatement
;
import
com.dianping.bee.engine.spi.Statement
;
import
com.dianping.bee.engine.spi.StatementManager
;
import
com.dianping.bee.engine.spi.handler.AbstractCommandHandler
;
import
com.dianping.bee.engine.spi.meta.Row
;
import
com.dianping.bee.engine.spi.meta.RowSet
;
import
com.dianping.bee.engine.spi.meta.internal.TypeUtils
;
import
com.site.lookup.annotation.Inject
;
/**
...
...
@@ -34,38 +39,59 @@ public class PrepareHandler extends AbstractCommandHandler {
@Override
protected
void
handle
(
ServerConnection
c
,
List
<
String
>
parts
)
{
// String stmt = Joiners.by(' ').join(parts);
// try {
// m_manager.stmtPrepare(stmt);
// } catch (SQLSyntaxErrorException e) {
// error(c, ErrorCode.ER_SYNTAX_ERROR, e.getMessage());
// }
}
/**
* @param s
ql
* @param s
tmtId
* @param c
* @param offset
*/
public
void
close
(
String
sql
,
ServerConnection
c
,
int
offset
)
{
public
void
close
(
Long
stmtId
,
ServerConnection
c
)
{
}
/**
* @param sql
* @param stmtId
* @param parameters
* @param c
* @param offset
*/
public
void
execute
(
String
sql
,
ServerConnection
c
,
int
offset
)
{
public
void
execute
(
Long
stmtId
,
List
<
Object
>
parameters
,
ServerConnection
c
)
{
PreparedStatement
stmt
=
m_manager
.
getStatement
(
stmtId
);
stmt
.
setParameters
(
parameters
);
RowSet
rowset
=
stmt
.
query
();
CommandContext
ctx
=
new
CommandContext
(
c
);
String
[]
names
=
new
String
[
rowset
.
getColumnSize
()];
for
(
int
colIndex
=
0
;
colIndex
<
names
.
length
;
colIndex
++)
{
names
[
colIndex
]
=
rowset
.
getColumn
(
colIndex
).
getName
();
}
ctx
.
writeHeader
(
names
.
length
);
for
(
int
colIndex
=
0
;
colIndex
<
names
.
length
;
colIndex
++)
{
ctx
.
writeField
(
names
[
colIndex
],
TypeUtils
.
convertJavaTypeToFieldType
(
rowset
.
getColumn
(
colIndex
).
getType
()));
}
ctx
.
writeEOF
();
for
(
int
rowIndex
=
0
;
rowIndex
<
rowset
.
getRowSize
();
rowIndex
++)
{
Row
row
=
rowset
.
getRow
(
rowIndex
);
ctx
.
writeRow
(
row
);
}
ctx
.
writeEOF
();
ctx
.
complete
();
}
public
PreparedStatement
getStatement
(
Long
stmtId
)
{
return
m_manager
.
getStatement
(
stmtId
);
}
/**
* @param sql
* @param c
* @param offset
*/
public
void
prepare
(
String
sql
,
ServerConnection
c
,
int
offset
)
{
public
void
prepare
(
String
sql
,
ServerConnection
c
)
{
Statement
stmt
=
null
;
try
{
stmt
=
m_manager
.
parseSQL
(
sql
);
...
...
@@ -73,21 +99,29 @@ public class PrepareHandler extends AbstractCommandHandler {
error
(
c
,
ErrorCode
.
ER_SYNTAX_ERROR
,
e
.
getMessage
());
}
long
stmtId
=
m_manager
.
stmtPrepare
(
stmt
);
long
stmtId
=
m_manager
.
stmtPrepare
(
(
PreparedStatement
)
stmt
);
CommandContext
ctx
=
new
CommandContext
(
c
);
int
columnSize
=
stmt
.
getColumnSize
();
int
parameterSize
=
stmt
.
getParameterSize
();
int
parameterSize
=
((
PreparedStatement
)
stmt
)
.
getParameterSize
();
PreparePacket
packet
=
new
PreparePacket
(
stmtId
,
columnSize
,
parameterSize
);
ctx
.
write
(
packet
);
// FIXME: just some sample code here
for
(
int
i
=
0
;
i
<
parameterSize
;
i
++)
{
PrepareParameterPacket
parameterPacket
=
new
PrepareParameterPacket
(
Fields
.
FIELD_TYPE_STRING
,
Fields
.
NOT_NULL_FLAG
,
(
byte
)
0
,
50
);
ctx
.
write
(
parameterPacket
);
// PrepareParameterPacket parameterPacket = new
// PrepareParameterPacket(Fields.FIELD_TYPE_STRING,
// Fields.NOT_NULL_FLAG, (byte) 0, 50);
FieldPacket
field
=
new
FieldPacket
();
field
.
type
=
Fields
.
FIELD_TYPE_STRING
;
field
.
flags
=
Fields
.
NOT_NULL_FLAG
;
field
.
decimals
=
(
byte
)
0
;
field
.
length
=
50
;
// ctx.write(parameterPacket);
ctx
.
write
(
field
);
}
ctx
.
writeEOF
();
ctx
.
complete
();
}
}
\ No newline at end of file
bee-engine/src/main/java/com/dianping/bee/engine/spi/handler/internal/PreparePacket.java
浏览文件 @
57906a52
...
...
@@ -40,7 +40,22 @@ public class PreparePacket extends MySQLPacket {
this
.
m_columnSize
=
columnSize
;
this
.
m_parameterSize
=
parameterSize
;
}
/**
* Bytes Name
----- ----
1 field_count
4 statement_handler_id
2 columns
2 parameters
field_count: Always = 0, as with OK Packet.
statement_handler_id: ID of statement handler.
columns: Number of columns in result set.
parameters: Number of parameters in query.
*/
@Override
public
ByteBuffer
write
(
ByteBuffer
buffer
,
FrontendConnection
c
)
{
int
size
=
calcPacketSize
();
...
...
@@ -49,7 +64,9 @@ public class PreparePacket extends MySQLPacket {
buffer
.
put
(
packetId
);
buffer
.
put
(
m_fieldCount
);
BufferUtil
.
writeUB4
(
buffer
,
m_statementId
);
BufferUtil
.
writeUB2
(
buffer
,
m_columnSize
);
//FIXME: not compatible with document
// BufferUtil.writeUB2(buffer, m_columnSize);
BufferUtil
.
writeUB2
(
buffer
,
m_fieldCount
);
BufferUtil
.
writeUB2
(
buffer
,
m_parameterSize
);
return
buffer
;
}
...
...
bee-engine/src/main/java/com/dianping/bee/engine/spi/handler/internal/PrepareParameterPacket.java
浏览文件 @
57906a52
...
...
@@ -25,6 +25,10 @@ import com.alibaba.cobar.protocol.MySQLPacket;
*/
public
class
PrepareParameterPacket
extends
MySQLPacket
{
public
static
final
byte
FIELD_COUNT
=
0x04
;
private
byte
m_fieldCount
=
FIELD_COUNT
;
private
int
m_fieldType
;
private
int
m_columnFlag
;
...
...
@@ -46,6 +50,7 @@ public class PrepareParameterPacket extends MySQLPacket {
buffer
=
c
.
checkWriteBuffer
(
buffer
,
c
.
getPacketHeaderSize
()
+
size
);
BufferUtil
.
writeUB3
(
buffer
,
size
);
buffer
.
put
(
packetId
);
buffer
.
put
(
m_fieldCount
);
BufferUtil
.
writeUB2
(
buffer
,
m_fieldType
);
BufferUtil
.
writeUB2
(
buffer
,
m_columnFlag
);
buffer
.
put
(
m_decimal
);
...
...
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/DefaultStatementManager.java
浏览文件 @
57906a52
...
...
@@ -6,6 +6,7 @@ import java.util.Map;
import
com.alibaba.cobar.parser.ast.stmt.SQLStatement
;
import
com.alibaba.cobar.parser.recognizer.SQLParserDelegate
;
import
com.dianping.bee.engine.spi.PreparedStatement
;
import
com.dianping.bee.engine.spi.Statement
;
import
com.dianping.bee.engine.spi.StatementManager
;
import
com.site.lookup.ContainerHolder
;
...
...
@@ -13,7 +14,7 @@ import com.site.lookup.ContainerHolder;
public
class
DefaultStatementManager
extends
ContainerHolder
implements
StatementManager
{
private
Map
<
String
,
Statement
>
m_statements
=
new
HashMap
<
String
,
Statement
>();
private
Map
<
Long
,
Statement
>
m_prepares
=
new
HashMap
<
Long
,
Statement
>();
private
Map
<
Long
,
PreparedStatement
>
m_prepares
=
new
HashMap
<
Long
,
Prepared
Statement
>();
private
static
long
stmtId
=
0
;
...
...
@@ -42,7 +43,12 @@ public class DefaultStatementManager extends ContainerHolder implements Statemen
statement
.
accept
(
detector
);
if
(
detector
.
isSingleTable
())
{
SingleTableStatementBuilder
builder
=
lookup
(
SingleTableStatementBuilder
.
class
);
SingleTableStatementBuilder
builder
=
null
;
if
(
detector
.
isPrepared
())
{
builder
=
lookup
(
SingleTablePreparedStatementBuilder
.
class
);
}
else
{
builder
=
lookup
(
SingleTableStatementBuilder
.
class
);
}
try
{
statement
.
accept
(
builder
);
...
...
@@ -56,17 +62,12 @@ public class DefaultStatementManager extends ContainerHolder implements Statemen
}
@Override
public
long
stmtPrepare
(
Statement
stmt
)
{
public
long
stmtPrepare
(
Prepared
Statement
stmt
)
{
synchronized
(
m_prepares
)
{
m_prepares
.
put
(
stmtId
++
%
Long
.
MAX_VALUE
,
stmt
);
}
return
stmtId
;
}
@Override
public
Statement
stmtExecute
(
long
stmtId
)
{
return
m_prepares
.
get
(
stmtId
);
return
stmtId
-
1
;
}
@Override
...
...
@@ -75,4 +76,9 @@ public class DefaultStatementManager extends ContainerHolder implements Statemen
m_prepares
.
remove
(
stmtId
);
}
}
@Override
public
PreparedStatement
getStatement
(
Long
stmtId
)
{
return
m_prepares
.
get
(
stmtId
);
}
}
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/QueryDetector.java
浏览文件 @
57906a52
package
com.dianping.bee.engine.spi.internal
;
import
com.alibaba.cobar.parser.ast.expression.Expression
;
import
com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression
;
import
com.alibaba.cobar.parser.ast.expression.primary.Identifier
;
import
com.alibaba.cobar.parser.ast.expression.primary.ParamMarker
;
import
com.alibaba.cobar.parser.ast.fragment.tableref.TableReferences
;
import
com.alibaba.cobar.parser.ast.stmt.dml.DMLSelectStatement
;
import
com.alibaba.cobar.parser.visitor.EmptySQLASTVisitor
;
...
...
@@ -7,6 +11,12 @@ import com.alibaba.cobar.parser.visitor.EmptySQLASTVisitor;
public
class
QueryDetector
extends
EmptySQLASTVisitor
{
private
boolean
m_singleTable
;
private
boolean
m_isPrepared
;
public
boolean
isPrepared
()
{
return
m_isPrepared
;
}
public
boolean
isSingleTable
()
{
return
m_singleTable
;
}
...
...
@@ -16,5 +26,26 @@ public class QueryDetector extends EmptySQLASTVisitor {
TableReferences
tables
=
node
.
getTables
();
m_singleTable
=
tables
.
isSingleTable
();
Expression
where
=
node
.
getWhere
();
if
(
where
!=
null
)
{
where
.
accept
(
this
);
}
}
@Override
public
void
visit
(
ComparisionEqualsExpression
node
)
{
Expression
left
=
node
.
getLeftOprand
();
if
(
left
instanceof
Identifier
)
{
Expression
right
=
node
.
getRightOprand
();
if
(
right
instanceof
ParamMarker
)
{
m_isPrepared
=
true
;
}
}
super
.
visit
(
node
);
}
}
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTablePreparedStatement.java
0 → 100644
浏览文件 @
57906a52
package
com.dianping.bee.engine.spi.internal
;
import
java.util.List
;
import
com.dianping.bee.engine.spi.PreparedStatement
;
public
class
SingleTablePreparedStatement
extends
SingleTableStatement
implements
PreparedStatement
{
private
int
m_parameterSize
;
@Override
public
int
getParameterSize
()
{
return
m_parameterSize
;
}
public
void
setParameterSize
(
int
parameterSize
)
{
m_parameterSize
=
parameterSize
;
}
@Override
public
void
setParameters
(
List
<
Object
>
params
)
{
}
}
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTablePreparedStatementBuilder.java
0 → 100644
浏览文件 @
57906a52
package
com.dianping.bee.engine.spi.internal
;
import
com.alibaba.cobar.parser.ast.expression.Expression
;
import
com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression
;
import
com.alibaba.cobar.parser.ast.expression.primary.Identifier
;
import
com.alibaba.cobar.parser.ast.expression.primary.ParamMarker
;
import
com.alibaba.cobar.parser.ast.stmt.dml.DMLSelectStatement
;
public
class
SingleTablePreparedStatementBuilder
extends
SingleTableStatementBuilder
{
private
int
m_parameterSize
;
public
SingleTablePreparedStatement
getStatement
()
{
return
(
SingleTablePreparedStatement
)
super
.
getStatement
();
}
@Override
public
void
visit
(
DMLSelectStatement
node
)
{
super
.
visit
(
node
);
Expression
where
=
node
.
getWhere
();
if
(
where
!=
null
)
{
getStatement
().
setParameterSize
(
m_parameterSize
);
}
}
@Override
public
void
visit
(
ParamMarker
node
)
{
m_parameterSize
++;
}
@Override
public
void
visit
(
ComparisionEqualsExpression
node
)
{
Expression
left
=
node
.
getLeftOprand
();
if
(
left
instanceof
Identifier
)
{
Expression
right
=
node
.
getRightOprand
();
if
(
right
instanceof
ParamMarker
)
{
// FIXME
String
name
=
((
Identifier
)
left
).
getIdText
();
String
value
=
"?"
;
getStatement
().
addAttribute
(
name
,
value
);
}
}
super
.
visit
(
node
);
}
}
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTableStatement.java
浏览文件 @
57906a52
...
...
@@ -23,8 +23,6 @@ public class SingleTableStatement extends ContainerHolder implements Statement {
private
ColumnMeta
[]
m_selectColumns
;
private
int
m_parameterSize
;
private
Map
<
ColumnMeta
,
Integer
>
m_allColumns
=
new
LinkedHashMap
<
ColumnMeta
,
Integer
>();
private
Map
<
String
,
List
<
Object
>>
m_attributes
=
new
HashMap
<
String
,
List
<
Object
>>();
...
...
@@ -34,11 +32,6 @@ public class SingleTableStatement extends ContainerHolder implements Statement {
return
m_selectColumns
.
length
;
}
@Override
public
int
getParameterSize
()
{
return
m_parameterSize
;
}
@Override
public
RowSet
query
()
{
Index
index
=
lookup
(
m_index
.
getIndexClass
());
...
...
@@ -65,10 +58,6 @@ public class SingleTableStatement extends ContainerHolder implements Statement {
m_index
=
index
;
}
public
void
setParameterSize
(
int
parameterSize
)
{
m_parameterSize
=
parameterSize
;
}
public
void
setRowFilter
(
RowFilter
rowFilter
)
{
m_rowFilter
=
rowFilter
;
}
...
...
bee-engine/src/main/java/com/dianping/bee/engine/spi/internal/SingleTableStatementBuilder.java
浏览文件 @
57906a52
...
...
@@ -6,7 +6,6 @@ import java.util.List;
import
com.alibaba.cobar.parser.ast.expression.Expression
;
import
com.alibaba.cobar.parser.ast.expression.comparison.ComparisionEqualsExpression
;
import
com.alibaba.cobar.parser.ast.expression.primary.Identifier
;
import
com.alibaba.cobar.parser.ast.expression.primary.ParamMarker
;
import
com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralNumber
;
import
com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString
;
import
com.alibaba.cobar.parser.ast.fragment.tableref.TableRefFactor
;
...
...
@@ -34,8 +33,6 @@ public class SingleTableStatementBuilder extends EmptySQLASTVisitor {
private
String
m_databaseName
;
private
int
m_parameterSize
;
private
Clause
m_clause
;
private
List
<
ColumnMeta
>
m_selectColumns
=
new
ArrayList
<
ColumnMeta
>();
...
...
@@ -102,7 +99,6 @@ public class SingleTableStatementBuilder extends EmptySQLASTVisitor {
m_stmt
.
setWhereColumns
(
m_whereColumns
);
m_stmt
.
setRowFilter
(
m_rowFilter
.
setExpression
(
where
));
m_stmt
.
setIndex
(
m_helper
.
findIndex
(
m_databaseName
,
m_tableName
,
m_whereColumns
));
m_stmt
.
setParameterSize
(
m_parameterSize
);
}
else
{
m_stmt
.
setIndex
(
m_helper
.
findDefaultIndex
(
m_databaseName
,
m_tableName
));
}
...
...
@@ -144,11 +140,6 @@ public class SingleTableStatementBuilder extends EmptySQLASTVisitor {
}
}
@Override
public
void
visit
(
ParamMarker
node
)
{
m_parameterSize
++;
}
@Override
public
void
visit
(
ComparisionEqualsExpression
node
)
{
Expression
left
=
node
.
getLeftOprand
();
...
...
@@ -166,13 +157,7 @@ public class SingleTableStatementBuilder extends EmptySQLASTVisitor {
Number
value
=
((
LiteralNumber
)
right
).
getNumber
();
m_stmt
.
addAttribute
(
name
,
value
);
}
else
if
(
right
instanceof
ParamMarker
)
{
// FIXME
String
name
=
((
Identifier
)
left
).
getIdText
();
String
value
=
"?"
;
m_stmt
.
addAttribute
(
name
,
value
);
}
}
}
super
.
visit
(
node
);
...
...
bee-engine/src/main/java/com/dianping/bee/server/SimpleServerConnection.java
浏览文件 @
57906a52
...
...
@@ -16,12 +16,15 @@ package com.dianping.bee.server;
import
java.io.UnsupportedEncodingException
;
import
java.nio.channels.SocketChannel
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Set
;
import
com.alibaba.cobar.ErrorCode
;
import
com.alibaba.cobar.net.util.MySQLMessage
;
import
com.alibaba.cobar.protocol.mysql.OkPacket
;
import
com.alibaba.cobar.server.ServerConnection
;
import
com.dianping.bee.engine.spi.PreparedStatement
;
import
com.dianping.bee.engine.spi.session.SessionManager
;
/**
...
...
@@ -108,22 +111,40 @@ public class SimpleServerConnection extends ServerConnection {
try
{
// 取得查询语句
MySQLMessage
mm
=
new
MySQLMessage
(
data
);
Long
stmtId
;
mm
.
position
(
5
);
String
sql
=
null
;
try
{
sql
=
mm
.
readString
(
charset
);
}
catch
(
UnsupportedEncodingException
e
)
{
writeErrMessage
(
ErrorCode
.
ER_UNKNOWN_CHARACTER_SET
,
"Unknown charset '"
+
charset
+
"'"
);
return
;
}
if
(
sql
==
null
||
sql
.
length
()
==
0
)
{
writeErrMessage
(
ErrorCode
.
ER_NOT_ALLOWED_COMMAND
,
"Empty Prepared SQL"
);
return
;
}
stmtId
=
(
long
)
mm
.
readInt
();
byte
flag
=
mm
.
read
();
int
iterationCount
=
mm
.
readInt
();
// 执行查询
if
(
queryHandler
!=
null
)
{
((
SimpleServerQueryHandler
)
queryHandler
).
stmtExecute
(
sql
);
PreparedStatement
stmt
=
((
SimpleServerQueryHandler
)
queryHandler
).
getStatement
(
stmtId
);
if
(
stmt
==
null
)
{
writeErrMessage
(
ErrorCode
.
ER_YES
,
"Invalid Statement Identifier"
);
}
int
parameterSize
=
stmt
.
getParameterSize
();
List
<
Object
>
parameters
=
new
ArrayList
<
Object
>(
parameterSize
);
int
nullBitMapSize
=
(
parameterSize
+
7
)
/
8
;
for
(
int
i
=
0
;
i
<
nullBitMapSize
;
i
++)
{
// TODO
byte
null_bits_map
=
mm
.
read
();
}
byte
new_bound
=
mm
.
read
();
for
(
int
i
=
0
;
i
<
parameterSize
;
i
++)
{
byte
[]
typeArray
=
mm
.
readBytes
(
2
);
// TODO determine type
}
for
(
int
i
=
0
;
i
<
parameterSize
;
i
++)
{
byte
length
=
mm
.
read
();
byte
[]
value
=
mm
.
readBytes
(
length
);
parameters
.
add
(
new
String
(
value
));
}
((
SimpleServerQueryHandler
)
queryHandler
).
stmtExecute
(
stmtId
,
parameters
);
}
else
{
writeErrMessage
(
ErrorCode
.
ER_YES
,
"Empty QueryHandler"
);
}
...
...
@@ -138,22 +159,13 @@ public class SimpleServerConnection extends ServerConnection {
try
{
// 取得查询语句
MySQLMessage
mm
=
new
MySQLMessage
(
data
);
mm
.
position
(
5
);
String
sql
=
null
;
try
{
sql
=
mm
.
readString
(
charset
);
}
catch
(
UnsupportedEncodingException
e
)
{
writeErrMessage
(
ErrorCode
.
ER_UNKNOWN_CHARACTER_SET
,
"Unknown charset '"
+
charset
+
"'"
);
return
;
}
if
(
sql
==
null
||
sql
.
length
()
==
0
)
{
writeErrMessage
(
ErrorCode
.
ER_NOT_ALLOWED_COMMAND
,
"Empty Prepared SQL"
);
return
;
}
Long
stmtId
;
mm
.
position
(
1
);
stmtId
=
mm
.
readLong
();
// 执行查询
if
(
queryHandler
!=
null
)
{
((
SimpleServerQueryHandler
)
queryHandler
).
stmtClose
(
s
ql
);
((
SimpleServerQueryHandler
)
queryHandler
).
stmtClose
(
s
tmtId
);
}
else
{
writeErrMessage
(
ErrorCode
.
ER_YES
,
"Empty QueryHandler"
);
}
...
...
bee-engine/src/main/java/com/dianping/bee/server/SimpleServerQueryHandler.java
浏览文件 @
57906a52
package
com.dianping.bee.server
;
import
java.util.List
;
import
com.alibaba.cobar.ErrorCode
;
import
com.alibaba.cobar.net.handler.FrontendQueryHandler
;
import
com.alibaba.cobar.server.ServerConnection
;
...
...
@@ -9,6 +11,7 @@ import com.alibaba.cobar.server.handler.KillHandler;
import
com.alibaba.cobar.server.handler.SavepointHandler
;
import
com.alibaba.cobar.server.handler.SetHandler
;
import
com.alibaba.cobar.server.handler.StartHandler
;
import
com.dianping.bee.engine.spi.PreparedStatement
;
import
com.dianping.bee.engine.spi.handler.internal.DescHandler
;
import
com.dianping.bee.engine.spi.handler.internal.PrepareHandler
;
import
com.dianping.bee.engine.spi.handler.internal.SelectHandler
;
...
...
@@ -91,21 +94,26 @@ public class SimpleServerQueryHandler implements FrontendQueryHandler {
/**
* @param sql
*/
public
void
stmtClose
(
String
sql
)
{
public
void
stmtClose
(
Long
stmtId
)
{
ServerConnection
c
=
m_conn
;
m_prepareHandler
.
close
(
s
ql
,
c
,
-
1
);
m_prepareHandler
.
close
(
s
tmtId
,
c
);
}
/**
* @param sql
* @param parameters
*/
public
void
stmtExecute
(
String
sql
)
{
public
void
stmtExecute
(
Long
stmtId
,
List
<
Object
>
parameters
)
{
ServerConnection
c
=
m_conn
;
m_prepareHandler
.
execute
(
s
ql
,
c
,
-
1
);
m_prepareHandler
.
execute
(
s
tmtId
,
parameters
,
c
);
}
public
void
stmtPrepare
(
String
sql
)
{
ServerConnection
c
=
m_conn
;
m_prepareHandler
.
prepare
(
sql
,
c
,
-
1
);
m_prepareHandler
.
prepare
(
sql
,
c
);
}
public
PreparedStatement
getStatement
(
Long
stmtId
)
{
return
m_prepareHandler
.
getStatement
(
stmtId
);
}
}
bee-engine/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
57906a52
...
...
@@ -65,6 +65,27 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.bee.engine.spi.internal.SingleTablePreparedStatement
</role>
<implementation>
com.dianping.bee.engine.spi.internal.SingleTablePreparedStatement
</implementation>
<instantiation-strategy>
per-lookup
</instantiation-strategy>
</component>
<component>
<role>
com.dianping.bee.engine.spi.internal.SingleTablePreparedStatementBuilder
</role>
<implementation>
com.dianping.bee.engine.spi.internal.SingleTablePreparedStatementBuilder
</implementation>
<instantiation-strategy>
per-lookup
</instantiation-strategy>
<requirements>
<requirement>
<role>
com.dianping.bee.engine.spi.internal.TableHelper
</role>
</requirement>
<requirement>
<role>
com.dianping.bee.engine.spi.internal.SingleTablePreparedStatement
</role>
</requirement>
<requirement>
<role>
com.dianping.bee.engine.spi.internal.SingleTableRowFilter
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.bee.server.SimpleServerQueryHandler
</role>
<implementation>
com.dianping.bee.server.SimpleServerQueryHandler
</implementation>
...
...
@@ -202,23 +223,5 @@
<role-hint>
com.alibaba.cobar.parser.ast.expression.primary.function.string.Concat
</role-hint>
<implementation>
com.dianping.bee.engine.spi.evaluator.function.ConcatEvaluator
</implementation>
</component>
<component>
<role>
com.dianping.bee.engine.spi.DatabaseProvider
</role>
<role-hint>
cat
</role-hint>
<implementation>
com.dianping.bee.db.cat.CatDatabase
</implementation>
</component>
<component>
<role>
com.dianping.bee.db.cat.TransactionIndexer
</role>
<implementation>
com.dianping.bee.db.cat.TransactionIndexer
</implementation>
</component>
<component>
<role>
com.dianping.bee.db.cat.EventIndexer
</role>
<implementation>
com.dianping.bee.db.cat.EventIndexer
</implementation>
</component>
<component>
<role>
com.dianping.bee.engine.spi.DatabaseProvider
</role>
<role-hint>
dog
</role-hint>
<implementation>
com.dianping.bee.db.dog.DogDatabase
</implementation>
</component>
</components>
</plexus>
bee-engine/src/test/java/com/dianping/bee/db/cat/EventIndexer.java
浏览文件 @
57906a52
...
...
@@ -66,6 +66,12 @@ public class EventIndexer implements Index {
case
TotalCount:
ctx
.
setColumnValue
(
i
,
row
[
4
]);
break
;
case
SumDuration:
ctx
.
setColumnValue
(
i
,
row
[
9
]);
break
;
case
Sum2Duration:
ctx
.
setColumnValue
(
i
,
row
[
10
]);
break
;
case
Line95:
ctx
.
setColumnValue
(
i
,
row
[
11
]);
break
;
...
...
@@ -100,9 +106,10 @@ public class EventIndexer implements Index {
if
(
EventColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"String"
))
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomAlphabetic
(
5
);
}
else
if
(
EventColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Integer"
)
||
EventColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Long"
))
{
}
else
if
(
EventColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Integer"
))
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomNumeric
(
3
);
}
else
if
(
EventColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Long"
))
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomNumeric
(
6
);
}
else
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomAlphanumeric
(
5
);
}
...
...
bee-engine/src/test/java/com/dianping/bee/db/cat/TransactionIndexer.java
浏览文件 @
57906a52
...
...
@@ -66,6 +66,12 @@ public class TransactionIndexer implements Index {
case
TotalCount:
ctx
.
setColumnValue
(
i
,
row
[
4
]);
break
;
case
SumDuration:
ctx
.
setColumnValue
(
i
,
row
[
9
]);
break
;
case
Sum2Duration:
ctx
.
setColumnValue
(
i
,
row
[
10
]);
break
;
case
Line95:
ctx
.
setColumnValue
(
i
,
row
[
11
]);
break
;
...
...
@@ -100,9 +106,10 @@ public class TransactionIndexer implements Index {
if
(
TransactionColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"String"
))
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomAlphabetic
(
5
);
}
else
if
(
TransactionColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Integer"
)
||
TransactionColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Long"
))
{
}
else
if
(
TransactionColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Integer"
))
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomNumeric
(
3
);
}
else
if
(
TransactionColumn
.
values
()[
j
].
getType
().
getSimpleName
().
equals
(
"Long"
))
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomNumeric
(
6
);
}
else
{
sampleData
[
i
][
j
]
=
RandomStringUtils
.
randomAlphanumeric
(
5
);
}
...
...
bee-engine/src/test/java/com/dianping/bee/
jdbc/JDBC
TestConfigurator.java
→
bee-engine/src/test/java/com/dianping/bee/
engine/spi/Server
TestConfigurator.java
浏览文件 @
57906a52
package
com.dianping.bee.
jdbc
;
package
com.dianping.bee.
engine.spi
;
import
java.io.File
;
import
java.util.ArrayList
;
...
...
@@ -8,13 +8,12 @@ import com.dianping.bee.db.cat.CatDatabase;
import
com.dianping.bee.db.cat.EventIndexer
;
import
com.dianping.bee.db.cat.TransactionIndexer
;
import
com.dianping.bee.db.dog.DogDatabase
;
import
com.dianping.bee.engine.spi.DatabaseProvider
;
import
com.site.lookup.configuration.AbstractResourceConfigurator
;
import
com.site.lookup.configuration.Component
;
public
class
JDBC
TestConfigurator
extends
AbstractResourceConfigurator
{
public
class
Server
TestConfigurator
extends
AbstractResourceConfigurator
{
public
static
void
main
(
String
[]
args
)
{
generatePlexusComponentsXmlFile
(
new
JDBC
TestConfigurator
());
generatePlexusComponentsXmlFile
(
new
Server
TestConfigurator
());
}
@Override
...
...
@@ -31,6 +30,6 @@ public class JDBCTestConfigurator extends AbstractResourceConfigurator {
@Override
protected
File
getConfigurationFile
()
{
return
new
File
(
"src/test/resources/"
+
JDBC
Test
.
class
.
getName
().
replace
(
'.'
,
'/'
)
+
".xml"
);
return
new
File
(
"src/test/resources/"
+
Server
Test
.
class
.
getName
().
replace
(
'.'
,
'/'
)
+
".xml"
);
}
}
bee-engine/src/test/resources/com/dianping/bee/engine/spi/ServerTest.xml
0 → 100644
浏览文件 @
57906a52
<plexus>
<components>
<component>
<role>
com.dianping.bee.engine.spi.DatabaseProvider
</role>
<role-hint>
cat
</role-hint>
<implementation>
com.dianping.bee.db.cat.CatDatabase
</implementation>
</component>
<component>
<role>
com.dianping.bee.db.cat.EventIndexer
</role>
<implementation>
com.dianping.bee.db.cat.EventIndexer
</implementation>
</component>
<component>
<role>
com.dianping.bee.db.cat.TransactionIndexer
</role>
<implementation>
com.dianping.bee.db.cat.TransactionIndexer
</implementation>
</component>
<component>
<role>
com.dianping.bee.engine.spi.DatabaseProvider
</role>
<role-hint>
dog
</role-hint>
<implementation>
com.dianping.bee.db.dog.DogDatabase
</implementation>
</component>
</components>
</plexus>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录