use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ShowVariables method response.
public static void response(ServerConnection c, String stmt) {
String db = c.getSchema() != null ? c.getSchema() : SchemaUtil.getRandomDb();
SchemaConfig schema = DbleServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
c.writeErrMessage("42000", "Unknown database '" + db + "'", ErrorCode.ER_BAD_DB_ERROR);
return;
}
RouteResultset rrs = new RouteResultset(stmt, ServerParse.SHOW);
try {
RouterUtil.routeToSingleNode(rrs, schema.getRandomDataNode());
ShowVariablesHandler handler = new ShowVariablesHandler(rrs, c.getSession2());
handler.execute();
} catch (Exception e) {
// Could this only be ER_PARSE_ERROR?
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, e.toString());
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class GlobalTableUtil method getGlobalTable.
private static void getGlobalTable() {
ServerConfig config = DbleServer.getInstance().getConfig();
for (Map.Entry<String, SchemaConfig> entry : config.getSchemas().entrySet()) {
for (TableConfig table : entry.getValue().getTables().values()) {
if (table.isGlobalTable()) {
String tableName = table.getName();
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
tableName = tableName.toLowerCase();
}
globalTableMap.put(entry.getKey() + "." + tableName, table);
}
}
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class SchemaUtil method getSchemaInfo.
public static SchemaInfo getSchemaInfo(String user, String schema, SQLExpr expr, String tableAlias) throws SQLException {
SchemaInfo schemaInfo = new SchemaInfo();
if (expr instanceof SQLPropertyExpr) {
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) expr;
schemaInfo.schema = StringUtil.removeBackQuote(propertyExpr.getOwner().toString());
schemaInfo.table = StringUtil.removeBackQuote(propertyExpr.getName());
} else if (expr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr identifierExpr = (SQLIdentifierExpr) expr;
schemaInfo.schema = schema;
schemaInfo.table = StringUtil.removeBackQuote(identifierExpr.getName());
if (identifierExpr.getName().equalsIgnoreCase("dual") && tableAlias == null) {
schemaInfo.dual = true;
return schemaInfo;
}
}
schemaInfo.tableAlias = tableAlias == null ? schemaInfo.table : tableAlias;
if (schemaInfo.schema == null) {
String msg = "No database selected";
throw new SQLException(msg, "3D000", ErrorCode.ER_NO_DB_ERROR);
}
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
schemaInfo.table = schemaInfo.table.toLowerCase();
schemaInfo.schema = schemaInfo.schema.toLowerCase();
}
if (MYSQL_SCHEMA.equalsIgnoreCase(schemaInfo.schema) || INFORMATION_SCHEMA.equalsIgnoreCase(schemaInfo.schema)) {
return schemaInfo;
} else {
SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(schemaInfo.schema);
if (schemaConfig == null) {
String msg = "Table " + StringUtil.getFullName(schemaInfo.schema, schemaInfo.table) + " doesn't exist";
throw new SQLException(msg, "42S02", ErrorCode.ER_NO_SUCH_TABLE);
}
if (user != null) {
UserConfig userConfig = DbleServer.getInstance().getConfig().getUsers().get(user);
if (!userConfig.getSchemas().contains(schemaInfo.schema)) {
String msg = " Access denied for user '" + user + "' to database '" + schemaInfo.schema + "'";
throw new SQLException(msg, "HY000", ErrorCode.ER_DBACCESS_DENIED_ERROR);
}
}
schemaInfo.schemaConfig = schemaConfig;
return schemaInfo;
}
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class ShowTableAlgorithm method execute.
public static void execute(ManagerConnection c, String tableInfo) {
Matcher ma = PATTERN_FOR_TABLE_INFO.matcher(tableInfo);
if (!ma.matches()) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "The Correct Query Format Is:show @@algorithm where schema=? and table =?");
return;
}
String schemaName = ma.group(2);
String tableName = ma.group(4);
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
schemaName = schemaName.toLowerCase();
tableName = tableName.toLowerCase();
}
SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(schemaName);
TableType tableType;
TableConfig tableConfig = null;
if (schemaConfig == null) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "the schema [" + schemaName + "] does not exists");
return;
} else if (schemaConfig.isNoSharding()) {
tableType = TableType.BASE;
} else {
tableConfig = schemaConfig.getTables().get(tableName);
if (tableConfig == null) {
if (schemaConfig.getDataNode() == null) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "the table [" + tableName + "] in schema [" + schemaName + "] does not exists");
return;
} else {
tableType = TableType.BASE;
}
} else if (tableConfig.isGlobalTable()) {
tableType = TableType.GLOBAL;
} else if (tableConfig.getParentTC() != null) {
tableType = TableType.CHILD;
} else if (tableConfig.getRule() == null) {
tableType = TableType.SHARDING_SINGLE;
} else {
tableType = TableType.SHARDING;
}
}
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();
for (RowDataPacket row : getRows(tableConfig, tableType, c.getCharset().getResults())) {
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);
// post write
c.write(buffer);
}
use of com.actiontech.dble.config.model.SchemaConfig in project dble by actiontech.
the class MergeBuilder method constructByStatement.
public RouteResultset constructByStatement(String sql, SQLSelectStatement select) throws SQLException {
ServerSchemaStatVisitor visitor = new ServerSchemaStatVisitor();
DruidParser druidParser = new DruidSingleUnitSelectParser();
RouteResultset rrs = new RouteResultset(sql, ServerParse.SELECT);
LayerCachePool pool = DbleServer.getInstance().getRouterService().getTableId2DataNodeCache();
SchemaConfig schemaConfig = schemaConfigMap.get(node.getReferedTableNodes().get(0).getSchema());
return RouterUtil.routeFromParser(druidParser, schemaConfig, rrs, select, sql, pool, visitor, session.getSource());
}
Aggregations