Search in sources :

Example 1 with SchemaMeta

use of com.actiontech.dble.meta.SchemaMeta in project dble by actiontech.

the class ShowTables method getTableSet.

public static Map<String, String> getTableSet(String cSchema, ShowCreateStmtInfo info) {
    // remove the table which is not created but configured
    SchemaMeta schemata = DbleServer.getInstance().getTmManager().getCatalogs().get(cSchema);
    if (schemata == null) {
        return new HashMap<>();
    }
    Map meta = schemata.getTableMetas();
    TreeMap<String, String> tableMap = new TreeMap<>();
    Map<String, SchemaConfig> schemas = DbleServer.getInstance().getConfig().getSchemas();
    if (null != info.getLike()) {
        String p = "^" + info.getLike().replaceAll("%", ".*");
        Pattern pattern = Pattern.compile(p, Pattern.CASE_INSENSITIVE);
        Matcher maLike;
        for (TableConfig tbConfig : schemas.get(cSchema).getTables().values()) {
            String tbName = tbConfig.getName();
            maLike = pattern.matcher(tbName);
            if (maLike.matches() && meta.get(tbName) != null) {
                String tbType = tbConfig.getTableType() == TableConfig.TableTypeEnum.TYPE_GLOBAL_TABLE ? "GLOBAL TABLE" : "SHARDING TABLE";
                tableMap.put(tbName, tbType);
            }
        }
    } else {
        for (TableConfig tbConfig : schemas.get(cSchema).getTables().values()) {
            String tbName = tbConfig.getName();
            if (meta.get(tbName) != null) {
                String tbType = tbConfig.getTableType() == TableConfig.TableTypeEnum.TYPE_GLOBAL_TABLE ? "GLOBAL TABLE" : "SHARDING TABLE";
                tableMap.put(tbName, tbType);
            }
        }
    }
    return tableMap;
}
Also used : Pattern(java.util.regex.Pattern) SchemaConfig(com.actiontech.dble.config.model.SchemaConfig) Matcher(java.util.regex.Matcher) SchemaMeta(com.actiontech.dble.meta.SchemaMeta) TableConfig(com.actiontech.dble.config.model.TableConfig)

Example 2 with SchemaMeta

use of com.actiontech.dble.meta.SchemaMeta in project dble by actiontech.

the class ShowCreateView method sendOutTheViewInfo.

public static void sendOutTheViewInfo(ServerConnection c, String schema, String viewName) throws Exception {
    // check if the view or schema is not exists
    if (schema == null || "".equals(schema)) {
        throw new Exception(" No database selected");
    }
    SchemaMeta schemaMeta = DbleServer.getInstance().getTmManager().getCatalogs().get(schema);
    if (schemaMeta == null) {
        throw new Exception("Table '" + schema + "." + viewName + "' doesn't exist");
    }
    ViewMeta view = schemaMeta.getViewMetas().get(viewName);
    if (view == null) {
        throw new Exception("Table '" + schema + "." + viewName + "' doesn't exist");
    }
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    RowDataPacket row = getRow(view, c.getCharset().getResults(), c.getCharset().getCollation());
    row.setPacketId(++packetId);
    buffer = row.write(buffer, c, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : ViewMeta(com.actiontech.dble.meta.ViewMeta) SchemaMeta(com.actiontech.dble.meta.SchemaMeta) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Aggregations

SchemaMeta (com.actiontech.dble.meta.SchemaMeta)2 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)1 TableConfig (com.actiontech.dble.config.model.TableConfig)1 ViewMeta (com.actiontech.dble.meta.ViewMeta)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)1 ByteBuffer (java.nio.ByteBuffer)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1