/*
* Copyright 2012-2015 org.opencloudb.
*
* 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.
*/
package org.opencloudb.handler;
import org.opencloudb.config.ErrorCode;
import org.opencloudb.manager.ManagerConnection;
import org.opencloudb.parser.ManagerParseShow;
import org.opencloudb.parser.util.ParseUtil;
import org.opencloudb.response.ShowBackend;
import org.opencloudb.response.ShowCollation;
import org.opencloudb.response.ShowCommand;
import org.opencloudb.response.ShowConnection;
import org.opencloudb.response.ShowConnectionSQL;
import org.opencloudb.response.ShowDataNode;
import org.opencloudb.response.ShowDataSource;
import org.opencloudb.response.ShowDatabase;
import org.opencloudb.response.ShowHeartbeat;
import org.opencloudb.response.ShowHelp;
import org.opencloudb.response.ShowParser;
import org.opencloudb.response.ShowProcessor;
import org.opencloudb.response.ShowRouter;
import org.opencloudb.response.ShowSQL;
import org.opencloudb.response.ShowSQLDetail;
import org.opencloudb.response.ShowSQLExecute;
import org.opencloudb.response.ShowSQLSlow;
import org.opencloudb.response.ShowServer;
import org.opencloudb.response.ShowThreadPool;
import org.opencloudb.response.ShowTime;
import org.opencloudb.response.ShowVariables;
import org.opencloudb.response.ShowVersion;
import org.opencloudb.util.StringUtil;
/**
* @author mycat
*/
public final class ShowHandler {
public static void handle(String stmt, ManagerConnection c, int offset) {
int rs = ManagerParseShow.parse(stmt, offset);
switch (rs & 0xff) {
case ManagerParseShow.COMMAND:
ShowCommand.execute(c);
break;
case ManagerParseShow.COLLATION:
ShowCollation.execute(c);
break;
case ManagerParseShow.CONNECTION:
ShowConnection.execute(c);
break;
case ManagerParseShow.BACKEND:
ShowBackend.execute(c);
break;
case ManagerParseShow.CONNECTION_SQL:
ShowConnectionSQL.execute(c);
break;
case ManagerParseShow.DATABASE:
ShowDatabase.execute(c);
break;
case ManagerParseShow.DATANODE:
ShowDataNode.execute(c, null);
break;
case ManagerParseShow.DATANODE_WHERE: {
String name = stmt.substring(rs >>> 8).trim();
if (StringUtil.isEmpty(name)) {
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
} else {
ShowDataNode.execute(c, name);
}
break;
}
case ManagerParseShow.DATASOURCE:
ShowDataSource.execute(c, null);
break;
case ManagerParseShow.DATASOURCE_WHERE: {
String name = stmt.substring(rs >>> 8).trim();
if (StringUtil.isEmpty(name)) {
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
} else {
ShowDataSource.execute(c, name);
}
break;
}
case ManagerParseShow.HELP:
ShowHelp.execute(c);
break;
case ManagerParseShow.HEARTBEAT:
ShowHeartbeat.response(c);
break;
case ManagerParseShow.PARSER:
ShowParser.execute(c);
break;
case ManagerParseShow.PROCESSOR:
ShowProcessor.execute(c);
break;
case ManagerParseShow.ROUTER:
ShowRouter.execute(c);
break;
case ManagerParseShow.SERVER:
ShowServer.execute(c);
break;
case ManagerParseShow.SQL:
ShowSQL.execute(c, ParseUtil.getSQLId(stmt));
break;
case ManagerParseShow.SQL_DETAIL:
ShowSQLDetail.execute(c, ParseUtil.getSQLId(stmt));
break;
case ManagerParseShow.SQL_EXECUTE:
ShowSQLExecute.execute(c);
break;
case ManagerParseShow.SQL_SLOW:
ShowSQLSlow.execute(c);
break;
case ManagerParseShow.SLOW_DATANODE: {
String name = stmt.substring(rs >>> 8).trim();
if (StringUtil.isEmpty(name)) {
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
} else {
// ShowSlow.dataNode(c, name);
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
}
break;
}
case ManagerParseShow.SLOW_SCHEMA: {
String name = stmt.substring(rs >>> 8).trim();
if (StringUtil.isEmpty(name)) {
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
} else {
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
// ShowSlow.schema(c, name);
}
break;
}
case ManagerParseShow.THREADPOOL:
ShowThreadPool.execute(c);
break;
case ManagerParseShow.TIME_CURRENT:
ShowTime.execute(c, ManagerParseShow.TIME_CURRENT);
break;
case ManagerParseShow.TIME_STARTUP:
ShowTime.execute(c, ManagerParseShow.TIME_STARTUP);
break;
case ManagerParseShow.VARIABLES:
ShowVariables.execute(c);
break;
case ManagerParseShow.VERSION:
ShowVersion.execute(c);
break;
default:
c.writeErrMessage(ErrorCode.ER_YES, "Unsupported statement");
}
}
}