fix(oracle): apply visible schema filter
This commit is contained in:
1 parent
1ded7e8332
commit
b2edf7cad6
20 files changed
+469
-102
No files matched your search
@@ -3,7 +3,10 @@ package com.dbx.agent;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface DatabaseAgent {
|
||||
void connect(ConnectParams params);
|
||||
@@ -14,6 +17,14 @@ public interface DatabaseAgent {
|
||||
|
||||
List<String> listSchemas();
|
||||
|
||||
default List<String> listSchemas(List<String> visibleSchemas) {
|
||||
if (visibleSchemas == null) {
|
||||
return listSchemas();
|
||||
}
|
||||
Set<String> visible = new HashSet<>(visibleSchemas);
|
||||
return listSchemas().stream().filter(visible::contains).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<TableInfo> listTables(String schema);
|
||||
|
||||
default List<ObjectInfo> listObjects(String schema) {
|
||||
|
||||
@@ -105,7 +105,7 @@ public final class JsonRpcServer {
|
||||
}
|
||||
if (AgentProtocol.METHOD_LIST_SCHEMAS.equals(method)) {
|
||||
switchCatalog(params);
|
||||
return agent.listSchemas();
|
||||
return agent.listSchemas(stringListOrNull(params, "visible_schemas"));
|
||||
}
|
||||
if (AgentProtocol.METHOD_LIST_TABLES.equals(method)) {
|
||||
switchCatalog(params);
|
||||
@@ -289,6 +289,15 @@ public final class JsonRpcServer {
|
||||
return element.getAsString();
|
||||
}
|
||||
|
||||
private List<String> stringListOrNull(JsonObject object, String key) {
|
||||
JsonElement element = object.get(key);
|
||||
if (element == null || element instanceof JsonNull) {
|
||||
return null;
|
||||
}
|
||||
Type listType = new TypeToken<List<String>>() {}.getType();
|
||||
return gson.fromJson(element, listType);
|
||||
}
|
||||
|
||||
private static Integer intOrNull(JsonObject object, String key) {
|
||||
JsonElement element = object.get(key);
|
||||
if (element == null || element instanceof JsonNull) {
|
||||
|
||||
Reference in new issue
Block a user