Search in sources :

Example 6 with UserConfig

use of com.alibaba.cobar.config.model.UserConfig in project cobar by alibaba.

the class ShowDatabases method response.

public static void response(ServerConnection c) {
    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;
    CobarConfig conf = CobarServer.getInstance().getConfig();
    Map<String, UserConfig> users = conf.getUsers();
    UserConfig user = users == null ? null : users.get(c.getUser());
    if (user != null) {
        TreeSet<String> schemaSet = new TreeSet<String>();
        Set<String> schemaList = user.getSchemas();
        if (schemaList == null || schemaList.size() == 0) {
            schemaSet.addAll(conf.getSchemas().keySet());
        } else {
            for (String schema : schemaList) {
                schemaSet.add(schema);
            }
        }
        for (String name : schemaSet) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, 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);
}
Also used : TreeSet(java.util.TreeSet) RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) CobarConfig(com.alibaba.cobar.CobarConfig) UserConfig(com.alibaba.cobar.config.model.UserConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Aggregations

UserConfig (com.alibaba.cobar.config.model.UserConfig)6 CobarConfig (com.alibaba.cobar.CobarConfig)3 CobarCluster (com.alibaba.cobar.CobarCluster)2 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)2 QuarantineConfig (com.alibaba.cobar.config.model.QuarantineConfig)2 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)2 ConfigException (com.alibaba.cobar.config.util.ConfigException)2 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)2 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ConfigInitializer (com.alibaba.cobar.ConfigInitializer)1 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)1 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)1 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)1 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1