提交 704dab8a 编写于 作者: Y youyong

Merge branch 'master' of ssh://192.168.8.22:58422/cat

......@@ -20,12 +20,12 @@ import com.dianping.bee.engine.spi.internal.MultiTableStatementVisitor;
import com.dianping.bee.engine.spi.internal.SingleTableStatementVisitor;
import com.dianping.bee.engine.spi.internal.TableHelper;
import com.dianping.bee.server.InformationSchemaDatabase;
import com.dianping.bee.server.SimpleDescHandler;
import com.dianping.bee.server.SimpleSelectHandler;
import com.dianping.bee.server.SimpleServer;
import com.dianping.bee.server.SimpleServerQueryHandler;
import com.dianping.bee.server.SimpleShowHandler;
import com.dianping.bee.server.SimpleUseHandler;
import com.dianping.bee.server.handler.SimpleDescHandler;
import com.dianping.bee.server.handler.SimpleSelectHandler;
import com.dianping.bee.server.handler.SimpleServerQueryHandler;
import com.dianping.bee.server.handler.SimpleShowHandler;
import com.dianping.bee.server.handler.SimpleUseHandler;
import com.site.lookup.configuration.AbstractResourceConfigurator;
import com.site.lookup.configuration.Component;
......
......@@ -36,7 +36,9 @@ public class DefaultStatementVisitor extends EmptySQLASTVisitor {
@Override
public void visit(DMLSelectStatement node) {
TableReference tr = node.getTables();
tr.accept(this);
if (tr != null) {
tr.accept(this);
}
}
@Override
......
......@@ -22,7 +22,11 @@ public class SimpleServer implements LogEnabled {
private Logger m_logger;
public static final String VERSION = "bee-0.0.1-cobar-1.3.0";
/**
* The mysql version can not be changed, JDBC Driver will parse mysql major
* and minor version information
*/
public static final String VERSION = "5.1.48-bee-0.0.1";
@Override
public void enableLogging(Logger logger) {
......
......@@ -12,6 +12,7 @@ import com.alibaba.cobar.net.factory.FrontendConnectionFactory;
import com.alibaba.cobar.server.ServerConnection;
import com.alibaba.cobar.server.session.BlockingSession;
import com.alibaba.cobar.server.session.NonBlockingSession;
import com.dianping.bee.server.handler.SimpleServerQueryHandler;
/**
* @author <a href="mailto:yiming.liu@dianping.com">Yiming Liu</a>
......
......@@ -12,7 +12,7 @@
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package com.dianping.bee.server;
package com.dianping.bee.server.handler;
import java.nio.ByteBuffer;
......
......@@ -12,7 +12,7 @@
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package com.dianping.bee.server;
package com.dianping.bee.server.handler;
import java.nio.ByteBuffer;
import java.sql.SQLSyntaxErrorException;
......@@ -26,7 +26,6 @@ import com.alibaba.cobar.protocol.mysql.FieldPacket;
import com.alibaba.cobar.protocol.mysql.ResultSetHeaderPacket;
import com.alibaba.cobar.protocol.mysql.RowDataPacket;
import com.alibaba.cobar.server.ServerConnection;
import com.alibaba.cobar.server.parser.ServerParseSelect;
import com.alibaba.cobar.server.response.SelectDatabase;
import com.alibaba.cobar.server.response.SelectIdentity;
import com.alibaba.cobar.server.response.SelectLastInsertId;
......@@ -42,6 +41,7 @@ import com.dianping.bee.engine.spi.meta.ColumnMeta;
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.dianping.bee.server.parse.SimpleServerParseSelect;
import com.site.lookup.annotation.Inject;
/**
......@@ -103,20 +103,23 @@ public class SimpleSelectHandler {
public void handle(String stmt, ServerConnection c, int offs) {
int offset = offs;
switch (ServerParseSelect.parse(stmt, offs)) {
case ServerParseSelect.VERSION_COMMENT:
switch (SimpleServerParseSelect.parse(stmt, offs)) {
case SimpleServerParseSelect.VERSION_COMMENT:
SelectVersionComment.response(c);
break;
case ServerParseSelect.DATABASE:
case SimpleServerParseSelect.DATABASE:
SelectDatabase.response(c);
break;
case ServerParseSelect.USER:
case SimpleServerParseSelect.USER:
SelectUser.response(c);
break;
case ServerParseSelect.VERSION:
case SimpleServerParseSelect.VERSION:
SelectVersion.response(c);
break;
case ServerParseSelect.LAST_INSERT_ID:
case SimpleServerParseSelect.SESSION:
selectSession(c, stmt);
break;
case SimpleServerParseSelect.LAST_INSERT_ID:
// offset = ParseUtil.move(stmt, 0, "select".length());
loop: for (; offset < stmt.length(); ++offset) {
switch (stmt.charAt(offset)) {
......@@ -131,11 +134,11 @@ public class SimpleSelectHandler {
break loop;
}
}
offset = ServerParseSelect.indexAfterLastInsertIdFunc(stmt, offset);
offset = ServerParseSelect.skipAs(stmt, offset);
offset = SimpleServerParseSelect.indexAfterLastInsertIdFunc(stmt, offset);
offset = SimpleServerParseSelect.skipAs(stmt, offset);
SelectLastInsertId.response(c, stmt, offset);
break;
case ServerParseSelect.IDENTITY:
case SimpleServerParseSelect.IDENTITY:
// offset = ParseUtil.move(stmt, 0, "select".length());
loop: for (; offset < stmt.length(); ++offset) {
switch (stmt.charAt(offset)) {
......@@ -151,9 +154,9 @@ public class SimpleSelectHandler {
}
int indexOfAtAt = offset;
offset += 2;
offset = ServerParseSelect.indexAfterIdentity(stmt, offset);
offset = SimpleServerParseSelect.indexAfterIdentity(stmt, offset);
String orgName = stmt.substring(indexOfAtAt, offset);
offset = ServerParseSelect.skipAs(stmt, offset);
offset = SimpleServerParseSelect.skipAs(stmt, offset);
SelectIdentity.response(c, stmt, offset, orgName);
break;
default:
......@@ -165,6 +168,55 @@ public class SimpleSelectHandler {
}
}
/**
* @param c
* @param stmt
*/
private void selectSession(ServerConnection c, String stmt) {
String sessionVariable = stmt.substring(stmt.indexOf("@@session"));
int FIELD_COUNT = 1;
ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
FieldPacket[] fields = new FieldPacket[FIELD_COUNT];
EOFPacket eof = new EOFPacket();
int i = 0;
byte packetId = 0;
header.packetId = ++packetId;
fields[i] = PacketUtil.getField(sessionVariable, Fields.FIELD_TYPE_VAR_STRING);
fields[i++].packetId = ++packetId;
eof.packetId = ++packetId;
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
packetId = eof.packetId;
// TODO: sample result currently
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode("1", c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
/**
*
* @param c
......
......@@ -12,7 +12,7 @@
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package com.dianping.bee.server;
package com.dianping.bee.server.handler;
import org.apache.log4j.Logger;
......@@ -25,6 +25,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.server.parse.SimpleServerParse;
import com.site.lookup.annotation.Inject;
/**
......
......@@ -12,7 +12,7 @@
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package com.dianping.bee.server;
package com.dianping.bee.server.handler;
import java.nio.ByteBuffer;
import java.util.HashMap;
......@@ -35,6 +35,7 @@ import com.alibaba.cobar.util.StringUtil;
import com.dianping.bee.engine.spi.DatabaseProvider;
import com.dianping.bee.engine.spi.TableProvider;
import com.dianping.bee.engine.spi.TableProviderManager;
import com.dianping.bee.server.parse.SimpleServerParseShow;
import com.site.lookup.ContainerLoader;
import com.site.lookup.annotation.Inject;
......@@ -67,11 +68,86 @@ public class SimpleShowHandler {
case SimpleServerParseShow.VARIABLES:
showVariables(c, stmt);
break;
case SimpleServerParseShow.COLLATION:
showCollation(c, stmt);
break;
default:
c.writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Unsupported show command");
}
}
/**
* @param c
* @param stmt
*/
private void showCollation(ServerConnection c, String stmt) {
int FIELD_COUNT = 6;
ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
FieldPacket[] fields = new FieldPacket[FIELD_COUNT];
EOFPacket eof = new EOFPacket();
int i = 0;
byte packetId = 0;
header.packetId = ++packetId;
fields[i] = PacketUtil.getField("Collation", Fields.FIELD_TYPE_VAR_STRING);
fields[i++].packetId = ++packetId;
fields[i] = PacketUtil.getField("Charset", Fields.FIELD_TYPE_VAR_STRING);
fields[i++].packetId = ++packetId;
fields[i] = PacketUtil.getField("Id", Fields.FIELD_TYPE_LONG);
fields[i++].packetId = ++packetId;
fields[i] = PacketUtil.getField("Default", Fields.FIELD_TYPE_VAR_STRING);
fields[i++].packetId = ++packetId;
fields[i] = PacketUtil.getField("Compiled", Fields.FIELD_TYPE_VAR_STRING);
fields[i++].packetId = ++packetId;
fields[i] = PacketUtil.getField("Sortlen", Fields.FIELD_TYPE_LONG);
fields[i++].packetId = ++packetId;
eof.packetId = ++packetId;
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
packetId = eof.packetId;
// TODO: sample result currently
// RowDataPacket row = new RowDataPacket(FIELD_COUNT);
// row.add(StringUtil.encode("utf8_general_ci", c.getCharset()));
// row.add(StringUtil.encode("utf8", c.getCharset()));
// row.add(LongUtil.toBytes(33L));
// row.add(StringUtil.encode("Yes", c.getCharset()));
// row.add(StringUtil.encode("Yes", c.getCharset()));
// row.add(LongUtil.toBytes(1));
// row.packetId = ++packetId;
// buffer = row.write(buffer, c);
//
// row = new RowDataPacket(FIELD_COUNT);
// row.add(StringUtil.encode("utf8_bin", c.getCharset()));
// row.add(StringUtil.encode("utf8", c.getCharset()));
// row.add(LongUtil.toBytes(83L));
// row.add(StringUtil.encode("", c.getCharset()));
// row.add(StringUtil.encode("Yes", c.getCharset()));
// row.add(LongUtil.toBytes(1));
// row.packetId = ++packetId;
// buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
/**
* @param c
* @param stmt
......@@ -100,6 +176,7 @@ public class SimpleShowHandler {
int i = 0;
byte packetId = 0;
header.packetId = ++packetId;
// FIXME field type need to be updated
fields[i] = PacketUtil.getField("Name", Fields.FIELD_TYPE_VAR_STRING);
fields[i++].packetId = ++packetId;
fields[i] = PacketUtil.getField("Engine", Fields.FIELD_TYPE_VAR_STRING);
......
......@@ -12,7 +12,7 @@
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package com.dianping.bee.server;
package com.dianping.bee.server.handler;
import java.nio.ByteBuffer;
import java.util.Set;
......
......@@ -12,7 +12,7 @@
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package com.dianping.bee.server;
package com.dianping.bee.server.parse;
import com.alibaba.cobar.parser.util.ParseUtil;
......
/**
* Project: bee-engine
*
* File Created at 2012-8-27
*
* 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.server.parse;
import com.alibaba.cobar.parser.util.CharTypes;
import com.alibaba.cobar.parser.util.ParseUtil;
/**
* @author <a href="mailto:yiming.liu@dianping.com">Yiming Liu</a>
*/
public class SimpleServerParseSelect {
public static final int OTHER = -1;
public static final int VERSION_COMMENT = 1;
public static final int DATABASE = 2;
public static final int USER = 3;
public static final int LAST_INSERT_ID = 4;
public static final int IDENTITY = 5;
public static final int VERSION = 6;
public static final int SESSION = 7;
private static final char[] _SESSION = "SESSION".toCharArray();
private static final char[] _VERSION_COMMENT = "VERSION_COMMENT".toCharArray();
private static final char[] _IDENTITY = "IDENTITY".toCharArray();
private static final char[] _LAST_INSERT_ID = "LAST_INSERT_ID".toCharArray();
private static final char[] _DATABASE = "DATABASE()".toCharArray();
/**
* SELECT DATABASE()
*/
static int databaseCheck(String stmt, int offset) {
int length = offset + _DATABASE.length;
if (stmt.length() >= length && ParseUtil.compare(stmt, offset, _DATABASE)) {
if (stmt.length() > length && stmt.charAt(length) != ' ') {
return OTHER;
} else {
return DATABASE;
}
}
return OTHER;
}
/**
* select @@identity<br/>
* select @@identiTy aS iD
*/
static int identityCheck(String stmt, int offset) {
offset = indexAfterIdentity(stmt, offset);
if (offset < 0) {
return OTHER;
}
offset = skipAs(stmt, offset);
offset = skipAlias(stmt, offset);
if (offset < 0) {
return OTHER;
}
offset = ParseUtil.move(stmt, offset, 0);
if (offset < stmt.length()) {
return OTHER;
}
return IDENTITY;
}
/**
* @param offset
* <code>stmt.charAt(offset) == first '`' OR 'i' OR 'I' OR '\'' OR '"'</code>
* @return index after identity or `identity` or "identity" or 'identity',
* might equals to length. -1 if not identity or `identity` or
* "identity" or 'identity'
*/
public static int indexAfterIdentity(String stmt, int offset) {
char first = stmt.charAt(offset);
switch (first) {
case '`':
case '\'':
case '"':
if (stmt.length() < offset + "identity".length() + 2) {
return -1;
}
if (stmt.charAt(offset + "identity".length() + 1) != first) {
return -1;
}
++offset;
break;
case 'i':
case 'I':
if (stmt.length() < offset + "identity".length()) {
return -1;
}
break;
default:
return -1;
}
if (ParseUtil.compare(stmt, offset, _IDENTITY)) {
offset += _IDENTITY.length;
switch (first) {
case '`':
case '\'':
case '"':
return ++offset;
}
return offset;
}
return -1;
}
/**
* @param offset
* <code>stmt.charAt(offset) == first 'L' OR 'l'</code>
* @return index after LAST_INSERT_ID(), might equals to length. -1 if not
* LAST_INSERT_ID
*/
public static int indexAfterLastInsertIdFunc(String stmt, int offset) {
if (stmt.length() >= offset + "LAST_INSERT_ID()".length()) {
if (ParseUtil.compare(stmt, offset, _LAST_INSERT_ID)) {
offset = ParseUtil.move(stmt, offset + _LAST_INSERT_ID.length, 0);
if (offset + 1 < stmt.length() && stmt.charAt(offset) == '(') {
offset = ParseUtil.move(stmt, offset + 1, 0);
if (offset < stmt.length() && stmt.charAt(offset) == ')') {
return ++offset;
}
}
}
}
return -1;
}
/**
* SELECT LAST_INSERT_ID()
*/
static int lastInsertCheck(String stmt, int offset) {
offset = indexAfterLastInsertIdFunc(stmt, offset);
if (offset < 0) {
return OTHER;
}
offset = skipAs(stmt, offset);
offset = skipAlias(stmt, offset);
if (offset < 0) {
return OTHER;
}
offset = ParseUtil.move(stmt, offset, 0);
if (offset < stmt.length()) {
return OTHER;
}
return LAST_INSERT_ID;
}
public static int parse(String stmt, int offset) {
int i = offset;
for (; i < stmt.length(); ++i) {
switch (stmt.charAt(i)) {
case ' ':
continue;
case '/':
case '#':
i = ParseUtil.comment(stmt, i);
continue;
case '@':
return select2Check(stmt, i);
case 'D':
case 'd':
return databaseCheck(stmt, i);
case 'L':
case 'l':
return lastInsertCheck(stmt, i);
case 'U':
case 'u':
return userCheck(stmt, i);
case 'V':
case 'v':
return versionCheck(stmt, i);
default:
return OTHER;
}
}
return OTHER;
}
static int select2Check(String stmt, int offset) {
if (stmt.length() > ++offset && stmt.charAt(offset) == '@') {
if (stmt.length() > ++offset) {
switch (stmt.charAt(offset)) {
case 'V':
case 'v':
return versionCommentCheck(stmt, offset);
case 'i':
case 'I':
return identityCheck(stmt, offset);
case 'S':
case 's':
return sessionCheck(stmt, offset);
default:
return OTHER;
}
}
}
return OTHER;
}
/**
* SELECT @@SESSION.[AUTO_INCREMENT_INCREMENT]
*
* @param stmt
* @param offset
* @return
*/
static int sessionCheck(String stmt, int offset) {
int length = offset + _SESSION.length;
if (stmt.length() > length && ParseUtil.compare(stmt, offset, _SESSION)) {
if (stmt.length() > length && stmt.charAt(length) != '.') {
return OTHER;
} else {
return SESSION;
}
}
return OTHER;
}
/**
* <code>SELECT LAST_INSERT_ID() AS id, </code>
*
* @param offset
* index of 'i', offset == stmt.length() is possible
* @return index of ','. return stmt.length() is possible. -1 if not alias
*/
private static int skipAlias(String stmt, int offset) {
offset = ParseUtil.move(stmt, offset, 0);
if (offset >= stmt.length())
return offset;
switch (stmt.charAt(offset)) {
case '\'':
return skipString(stmt, offset);
case '"':
return skipString2(stmt, offset);
case '`':
return skipIdentifierEscape(stmt, offset);
default:
if (CharTypes.isIdentifierChar(stmt.charAt(offset))) {
for (; offset < stmt.length() && CharTypes.isIdentifierChar(stmt.charAt(offset)); ++offset)
;
return offset;
}
}
return -1;
}
/**
* <code>SELECT LAST_INSERT_ID() AS id</code>
*
* @param offset
* index of first ' ' after LAST_INSERT_ID(), offset ==
* stmt.length() is possible
* @return index of 'i'. return stmt.length() is possible
*/
public static int skipAs(String stmt, int offset) {
offset = ParseUtil.move(stmt, offset, 0);
if (stmt.length() > offset + "AS".length()
&& (stmt.charAt(offset) == 'A' || stmt.charAt(offset) == 'a')
&& (stmt.charAt(offset + 1) == 'S' || stmt.charAt(offset + 1) == 's')
&& (stmt.charAt(offset + 2) == ' ' || stmt.charAt(offset + 2) == '\r' || stmt.charAt(offset + 2) == '\n'
|| stmt.charAt(offset + 2) == '\t' || stmt.charAt(offset + 2) == '/' || stmt.charAt(offset + 2) == '#')) {
offset = ParseUtil.move(stmt, offset + 2, 0);
}
return offset;
}
/**
* <code>`abc`d</code>
*
* @param offset
* index of first <code>`</code>
* @return index of 'd'. return stmt.length() is possible. -1 if string
* invalid
*/
private static int skipIdentifierEscape(String stmt, int offset) {
for (++offset; offset < stmt.length(); ++offset) {
if (stmt.charAt(offset) == '`') {
if (++offset >= stmt.length() || stmt.charAt(offset) != '`') {
return offset;
}
}
}
return -1;
}
/**
* <code>'abc'd</code>
*
* @param offset
* index of first <code>'</code>
* @return index of 'd'. return stmt.length() is possible. -1 if string
* invalid
*/
private static int skipString(String stmt, int offset) {
int state = 0;
for (++offset; offset < stmt.length(); ++offset) {
char c = stmt.charAt(offset);
switch (state) {
case 0:
switch (c) {
case '\\':
state = 1;
break;
case '\'':
state = 2;
break;
}
break;
case 1:
state = 0;
break;
case 2:
switch (c) {
case '\'':
state = 0;
break;
default:
return offset;
}
break;
}
}
if (offset == stmt.length() && state == 2) {
return stmt.length();
}
return -1;
}
/**
* <code>"abc"d</code>
*
* @param offset
* index of first <code>"</code>
* @return index of 'd'. return stmt.length() is possible. -1 if string
* invalid
*/
private static int skipString2(String stmt, int offset) {
int state = 0;
for (++offset; offset < stmt.length(); ++offset) {
char c = stmt.charAt(offset);
switch (state) {
case 0:
switch (c) {
case '\\':
state = 1;
break;
case '"':
state = 2;
break;
}
break;
case 1:
state = 0;
break;
case 2:
switch (c) {
case '"':
state = 0;
break;
default:
return offset;
}
break;
}
}
if (offset == stmt.length() && state == 2) {
return stmt.length();
}
return -1;
}
/**
* SELECT USER()
*/
static int userCheck(String stmt, int offset) {
if (stmt.length() > offset + 5) {
char c1 = stmt.charAt(++offset);
char c2 = stmt.charAt(++offset);
char c3 = stmt.charAt(++offset);
char c4 = stmt.charAt(++offset);
char c5 = stmt.charAt(++offset);
if ((c1 == 'S' || c1 == 's') && (c2 == 'E' || c2 == 'e') && (c3 == 'R' || c3 == 'r') && (c4 == '(')
&& (c5 == ')') && (stmt.length() == ++offset || ParseUtil.isEOF(stmt.charAt(offset)))) {
return USER;
}
}
return OTHER;
}
// SELECT VERSION
private static int versionCheck(String stmt, int offset) {
if (stmt.length() > offset + "ERSION".length()) {
char c1 = stmt.charAt(++offset);
char c2 = stmt.charAt(++offset);
char c3 = stmt.charAt(++offset);
char c4 = stmt.charAt(++offset);
char c5 = stmt.charAt(++offset);
char c6 = stmt.charAt(++offset);
if ((c1 == 'E' || c1 == 'e') && (c2 == 'R' || c2 == 'r') && (c3 == 'S' || c3 == 's')
&& (c4 == 'I' || c4 == 'i') && (c5 == 'O' || c5 == 'o') && (c6 == 'N' || c6 == 'n')) {
while (stmt.length() > ++offset) {
switch (stmt.charAt(offset)) {
case ' ':
case '\t':
case '\r':
case '\n':
continue;
case '(':
return versionParenthesisCheck(stmt, offset);
default:
return OTHER;
}
}
}
}
return OTHER;
}
/**
* SELECT @@VERSION_COMMENT
*/
static int versionCommentCheck(String stmt, int offset) {
int length = offset + _VERSION_COMMENT.length;
if (stmt.length() >= length && ParseUtil.compare(stmt, offset, _VERSION_COMMENT)) {
if (stmt.length() > length && stmt.charAt(length) != ' ') {
return OTHER;
} else {
return VERSION_COMMENT;
}
}
return OTHER;
}
// SELECT VERSION (
private static int versionParenthesisCheck(String stmt, int offset) {
while (stmt.length() > ++offset) {
switch (stmt.charAt(offset)) {
case ' ':
case '\t':
case '\r':
case '\n':
continue;
case ')':
while (stmt.length() > ++offset) {
switch (stmt.charAt(offset)) {
case ' ':
case '\t':
case '\r':
case '\n':
continue;
default:
return OTHER;
}
}
return VERSION;
default:
return OTHER;
}
}
return OTHER;
}
}
......@@ -12,7 +12,7 @@
* accordance with the terms of the license agreement you entered into
* with dianping.com.
*/
package com.dianping.bee.server;
package com.dianping.bee.server.parse;
import com.alibaba.cobar.parser.util.ParseUtil;
......@@ -32,6 +32,8 @@ public class SimpleServerParseShow {
public static final int TABLESTATUS = 5;
public static final int COLLATION = 6;
public static int parse(String stmt, int offset) {
int i = offset;
for (; i < stmt.length(); i++) {
......@@ -54,6 +56,9 @@ public class SimpleServerParseShow {
case 'V':
case 'v':
return showVariablesCheck(stmt, i);
case 'C':
case 'c':
return showCollation(stmt, i);
default:
return OTHER;
}
......@@ -61,9 +66,9 @@ public class SimpleServerParseShow {
return OTHER;
}
// SHOW VARIABLES
private static int showVariablesCheck(String stmt, int offset) {
if (stmt.length() > offset + "ariables".length()) {
// SHOW COLLATION
static int showCollation(String stmt, int offset) {
if (stmt.length() > offset + "ollation".length()) {
char c1 = stmt.charAt(++offset);
char c2 = stmt.charAt(++offset);
char c3 = stmt.charAt(++offset);
......@@ -72,49 +77,49 @@ public class SimpleServerParseShow {
char c6 = stmt.charAt(++offset);
char c7 = stmt.charAt(++offset);
char c8 = stmt.charAt(++offset);
if ((c1 == 'A' || c1 == 'a') && (c2 == 'R' || c2 == 'r') && (c3 == 'I' || c3 == 'i')
&& (c4 == 'A' || c4 == 'a') && (c5 == 'B' || c5 == 'b') && (c6 == 'L' || c6 == 'l')
&& (c7 == 'E' || c7 == 'e') && (c8 == 'S' || c8 == 's')
if ((c1 == 'O' || c1 == 'o') && (c2 == 'L' || c2 == 'l') && (c3 == 'L' || c3 == 'l')
&& (c4 == 'A' || c4 == 'a') && (c5 == 'T' || c5 == 't') && (c6 == 'I' || c6 == 'i')
&& (c7 == 'O' || c7 == 'o') && (c8 == 'N' || c8 == 'n')
&& (stmt.length() == ++offset || ParseUtil.isEOF(stmt.charAt(offset)))) {
return VARIABLES;
return COLLATION;
}
}
return OTHER;
}
// SHOW STATUS
static int showStatusCheck(String stmt, int offset) {
if (stmt.length() > offset + "tatus".length()) {
// SHOW DATABASES
static int showDatabasesCheck(String stmt, int offset) {
if (stmt.length() > offset + "atabases".length()) {
char c1 = stmt.charAt(++offset);
char c2 = stmt.charAt(++offset);
char c3 = stmt.charAt(++offset);
char c4 = stmt.charAt(++offset);
char c5 = stmt.charAt(++offset);
if ((c1 == 'T' || c1 == 't') && (c2 == 'A' || c2 == 'a') && (c3 == 'T' || c3 == 't')
&& (c4 == 'U' || c4 == 'u') && (c5 == 'S' || c5 == 's')
char c6 = stmt.charAt(++offset);
char c7 = stmt.charAt(++offset);
char c8 = stmt.charAt(++offset);
if ((c1 == 'A' || c1 == 'a') && (c2 == 'T' || c2 == 't') && (c3 == 'A' || c3 == 'a')
&& (c4 == 'B' || c4 == 'b') && (c5 == 'A' || c5 == 'a') && (c6 == 'S' || c6 == 's')
&& (c7 == 'E' || c7 == 'e') && (c8 == 'S' || c8 == 's')
&& (stmt.length() == ++offset || ParseUtil.isEOF(stmt.charAt(offset)))) {
return STATUS;
return DATABASES;
}
}
return OTHER;
}
// SHOW DATABASES
static int showDatabasesCheck(String stmt, int offset) {
if (stmt.length() > offset + "atabases".length()) {
// SHOW STATUS
static int showStatusCheck(String stmt, int offset) {
if (stmt.length() > offset + "tatus".length()) {
char c1 = stmt.charAt(++offset);
char c2 = stmt.charAt(++offset);
char c3 = stmt.charAt(++offset);
char c4 = stmt.charAt(++offset);
char c5 = stmt.charAt(++offset);
char c6 = stmt.charAt(++offset);
char c7 = stmt.charAt(++offset);
char c8 = stmt.charAt(++offset);
if ((c1 == 'A' || c1 == 'a') && (c2 == 'T' || c2 == 't') && (c3 == 'A' || c3 == 'a')
&& (c4 == 'B' || c4 == 'b') && (c5 == 'A' || c5 == 'a') && (c6 == 'S' || c6 == 's')
&& (c7 == 'E' || c7 == 'e') && (c8 == 'S' || c8 == 's')
if ((c1 == 'T' || c1 == 't') && (c2 == 'A' || c2 == 'a') && (c3 == 'T' || c3 == 't')
&& (c4 == 'U' || c4 == 'u') && (c5 == 'S' || c5 == 's')
&& (stmt.length() == ++offset || ParseUtil.isEOF(stmt.charAt(offset)))) {
return DATABASES;
return STATUS;
}
}
return OTHER;
......@@ -167,4 +172,25 @@ public class SimpleServerParseShow {
}
return OTHER;
}
// SHOW VARIABLES
static int showVariablesCheck(String stmt, int offset) {
if (stmt.length() > offset + "ariables".length()) {
char c1 = stmt.charAt(++offset);
char c2 = stmt.charAt(++offset);
char c3 = stmt.charAt(++offset);
char c4 = stmt.charAt(++offset);
char c5 = stmt.charAt(++offset);
char c6 = stmt.charAt(++offset);
char c7 = stmt.charAt(++offset);
char c8 = stmt.charAt(++offset);
if ((c1 == 'A' || c1 == 'a') && (c2 == 'R' || c2 == 'r') && (c3 == 'I' || c3 == 'i')
&& (c4 == 'A' || c4 == 'a') && (c5 == 'B' || c5 == 'b') && (c6 == 'L' || c6 == 'l')
&& (c7 == 'E' || c7 == 'e') && (c8 == 'S' || c8 == 's')
&& (stmt.length() == ++offset || ParseUtil.isEOF(stmt.charAt(offset)))) {
return VARIABLES;
}
}
return OTHER;
}
}
......@@ -89,8 +89,8 @@
</requirements>
</component>
<component>
<role>com.dianping.bee.server.SimpleShowHandler</role>
<implementation>com.dianping.bee.server.SimpleShowHandler</implementation>
<role>com.dianping.bee.server.handler.SimpleShowHandler</role>
<implementation>com.dianping.bee.server.handler.SimpleShowHandler</implementation>
<requirements>
<requirement>
<role>com.dianping.bee.engine.spi.TableProviderManager</role>
......@@ -98,12 +98,12 @@
</requirements>
</component>
<component>
<role>com.dianping.bee.server.SimpleUseHandler</role>
<implementation>com.dianping.bee.server.SimpleUseHandler</implementation>
<role>com.dianping.bee.server.handler.SimpleUseHandler</role>
<implementation>com.dianping.bee.server.handler.SimpleUseHandler</implementation>
</component>
<component>
<role>com.dianping.bee.server.SimpleDescHandler</role>
<implementation>com.dianping.bee.server.SimpleDescHandler</implementation>
<role>com.dianping.bee.server.handler.SimpleDescHandler</role>
<implementation>com.dianping.bee.server.handler.SimpleDescHandler</implementation>
<requirements>
<requirement>
<role>com.dianping.bee.engine.spi.TableProviderManager</role>
......@@ -111,8 +111,8 @@
</requirements>
</component>
<component>
<role>com.dianping.bee.server.SimpleSelectHandler</role>
<implementation>com.dianping.bee.server.SimpleSelectHandler</implementation>
<role>com.dianping.bee.server.handler.SimpleSelectHandler</role>
<implementation>com.dianping.bee.server.handler.SimpleSelectHandler</implementation>
<requirements>
<requirement>
<role>com.dianping.bee.engine.spi.StatementManager</role>
......@@ -120,21 +120,21 @@
</requirements>
</component>
<component>
<role>com.dianping.bee.server.SimpleServerQueryHandler</role>
<implementation>com.dianping.bee.server.SimpleServerQueryHandler</implementation>
<role>com.dianping.bee.server.handler.SimpleServerQueryHandler</role>
<implementation>com.dianping.bee.server.handler.SimpleServerQueryHandler</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<requirements>
<requirement>
<role>com.dianping.bee.server.SimpleSelectHandler</role>
<role>com.dianping.bee.server.handler.SimpleSelectHandler</role>
</requirement>
<requirement>
<role>com.dianping.bee.server.SimpleShowHandler</role>
<role>com.dianping.bee.server.handler.SimpleShowHandler</role>
</requirement>
<requirement>
<role>com.dianping.bee.server.SimpleDescHandler</role>
<role>com.dianping.bee.server.handler.SimpleDescHandler</role>
</requirement>
<requirement>
<role>com.dianping.bee.server.SimpleUseHandler</role>
<role>com.dianping.bee.server.handler.SimpleUseHandler</role>
</requirement>
</requirements>
</component>
......
......@@ -35,8 +35,9 @@ public class ServerTest extends ComponentTestCase {
server.startup();
System.out.println(CobarServer.getInstance().getConfig().getUsers());
System.out.println("Press any key to continue ...");
System.in.read();
}
}
......@@ -20,7 +20,7 @@ public class SpiTest extends ComponentTestCase {
display(rowset);
}
private void display(RowSet rowset) {
StringBuilder sb = new StringBuilder(1024);
int cols = rowset.getColumns();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册