Search in sources :

Example 1 with SingleNodeHandler

use of com.actiontech.dble.backend.mysql.nio.handler.SingleNodeHandler in project dble by actiontech.

the class Explain2Handler method handle.

public static void handle(String stmt, ServerConnection c, int offset) {
    try {
        stmt = stmt.substring(offset);
        if (!stmt.toLowerCase().contains("datanode=") || !stmt.toLowerCase().contains("sql=")) {
            showError(stmt, c, "explain2 datanode=? sql=?");
            return;
        }
        String dataNode = stmt.substring(stmt.indexOf("=") + 1, stmt.indexOf("sql=")).trim();
        String sql = "explain " + stmt.substring(stmt.indexOf("sql=") + 4, stmt.length()).trim();
        if (dataNode == null || dataNode.isEmpty() || sql == null || sql.isEmpty()) {
            showError(stmt, c, "dataNode or sql is null or empty");
            return;
        }
        RouteResultsetNode node = new RouteResultsetNode(dataNode, ServerParse.SELECT, sql);
        RouteResultset rrs = new RouteResultset(sql, ServerParse.SELECT);
        EMPTY_ARRAY[0] = node;
        rrs.setNodes(EMPTY_ARRAY);
        SingleNodeHandler singleNodeHandler = new SingleNodeHandler(rrs, c.getSession2());
        singleNodeHandler.execute();
    } catch (Exception e) {
        LOGGER.info(e.getMessage(), e.getCause());
        showError(stmt, c, e.getMessage());
    }
}
Also used : SingleNodeHandler(com.actiontech.dble.backend.mysql.nio.handler.SingleNodeHandler) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) RouteResultset(com.actiontech.dble.route.RouteResultset)

Aggregations

SingleNodeHandler (com.actiontech.dble.backend.mysql.nio.handler.SingleNodeHandler)1 RouteResultset (com.actiontech.dble.route.RouteResultset)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1