当前位置: 首页>>代码示例>>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;未经允许,请勿转载。