use of io.mycat.MysqlVariableService in project Mycat2 by MyCATApache.
the class PrototypeHandlerImpl method showVariants.
@Override
public List<Object[]> showVariants(MySqlShowVariantsStatement statement) {
return onJdbc(statement.toString()).orElseGet(() -> {
if (MetaClusterCurrent.exist(MysqlVariableService.class)) {
MysqlVariableService mysqlVariableService = MetaClusterCurrent.wrapper(MysqlVariableService.class);
List<Object[]> globalVariables = Collections.emptyList();
List<Object[]> sessionVariables = Collections.emptyList();
if (statement.isGlobal()) {
globalVariables = mysqlVariableService.getGlobalVariables();
}
if (statement.isSession()) {
sessionVariables = mysqlVariableService.getSessionVariables();
}
Set<String> variableKeys = new HashSet<>();
List<Object[]> resVariables = new ArrayList<>(globalVariables.size() + sessionVariables.size());
resVariables.addAll(globalVariables);
for (Object[] globalVariable : globalVariables) {
variableKeys.add(Objects.toString(globalVariable[0]));
}
for (Object[] sessionVariable : sessionVariables) {
String key = Objects.toString(sessionVariable[0]);
if (variableKeys.add(key)) {
resVariables.add(sessionVariable);
}
}
return resVariables;
}
return Collections.emptyList();
});
}
Aggregations