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;
}
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);
}
Aggregations