當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerConnection.getSchema方法代碼示例

本文整理匯總了Java中com.alibaba.cobar.server.ServerConnection.getSchema方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerConnection.getSchema方法的具體用法?Java ServerConnection.getSchema怎麽用?Java ServerConnection.getSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.cobar.server.ServerConnection的用法示例。


在下文中一共展示了ServerConnection.getSchema方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRouteResultset

import com.alibaba.cobar.server.ServerConnection; //導入方法依賴的package包/類
private static RouteResultset getRouteResultset(ServerConnection c, String stmt) {
    String db = c.getSchema();
    if (db == null) {
        c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
        return null;
    }
    SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
    if (schema == null) {
        c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
        return null;
    }
    try {
        return ServerRouter.route(schema, stmt, c.getCharset(), c);
    } catch (SQLNonTransientException e) {
        StringBuilder s = new StringBuilder();
        logger.warn(s.append(c).append(stmt).toString(), e);
        String msg = e.getMessage();
        c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
        return null;
    }
}
 
開發者ID:alibaba,項目名稱:cobar,代碼行數:22,代碼來源:ExplainHandler.java

示例2: execute

import com.alibaba.cobar.server.ServerConnection; //導入方法依賴的package包/類
public static void execute(ServerConnection c) {
    // 取得SCHEMA
    String db = c.getSchema();
    if (db == null) {
        c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
        return;
    }

    SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
    if (schema == null) {
        c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
        return;
    }
    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
    byte packetId = eof.packetId;

    SQLRecord[] records = schema.getDataSource().getRecorder().getRecords();
    for (int i = records.length - 1; i >= 0; i--) {
        if (records[i] != null) {
            RowDataPacket row = getRow(records[i], 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);

    // write buffer
    c.write(buffer);
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:47,代碼來源:ShowPhysicalSQLSlow.java

示例3: execute

import com.alibaba.cobar.server.ServerConnection; //導入方法依賴的package包/類
public static void execute(ServerConnection c) {
    // 取得SCHEMA
    String db = c.getSchema();
    if (db == null) {
        c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
        return;
    }

    SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
    if (schema == null) {
        c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
        return;
    }
    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
    byte packetId = eof.packetId;

    SQLRecord[] records = schema.getRecorder().getRecords();
    for (int i = records.length - 1; i >= 0; i--) {
        if (records[i] != null) {
            RowDataPacket row = getRow(records[i], 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);

    // write buffer
    c.write(buffer);
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:47,代碼來源:ShowSQLSlow.java


注:本文中的com.alibaba.cobar.server.ServerConnection.getSchema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。