feat(objects): show functions and procedures in sidebar tree

Add list_objects support for agent-driven databases (Dameng, Oracle, etc.)
and ExternalDriver plugin connections. SQL Server dbo schema now uses
listObjects to display grouped object nodes including routines.

- Add list_objects RPC to JDBC agent plugin
- Add extract_agent and ExternalDriver branches in list_objects_core
- Add get_object_source support for agent connections
- Click function/procedure nodes to view source via object browser
- Fix duplicate tree node IDs when same name exists as view and function
This commit is contained in:
t8y2
2026-05-15 13:02:19 +08:00
parent c8ba3dad69
commit c2da1f866c
7 changed files with 151 additions and 36 deletions
@@ -104,6 +104,7 @@ public final class DbxJdbcPlugin {
case "listDatabases" -> listDatabases(connection);
case "listSchemas" -> listSchemas(connection, optionalText(params, "database"));
case "listTables" -> listTables(connection, optionalText(params, "database"), optionalText(params, "schema"));
case "list_objects" -> listObjects(connection, optionalText(params, "database"), optionalText(params, "schema"));
case "getColumns" -> getColumns(
connection,
optionalText(params, "database"),
@@ -285,6 +286,61 @@ public final class DbxJdbcPlugin {
return result;
}
private static JsonNode listObjects(JsonNode connection, String database, String schema) throws SQLException {
ArrayNode result = MAPPER.createArrayNode();
Connection conn = openConnection(connection);
DatabaseMetaData meta = conn.getMetaData();
String catalog = emptyToNull(database);
String schemaPattern = emptyToNull(schema);
String[] tableTypes = new String[] {"TABLE", "VIEW", "MATERIALIZED VIEW", "SYSTEM TABLE", "SYSTEM VIEW"};
try (ResultSet rs = meta.getTables(catalog, schemaPattern, "%", tableTypes)) {
while (rs.next()) {
ObjectNode item = MAPPER.createObjectNode();
item.put("name", rs.getString("TABLE_NAME"));
item.put("object_type", rs.getString("TABLE_TYPE"));
putNullable(item, "schema", schema);
putNullable(item, "comment", rs.getString("REMARKS"));
result.add(item);
}
}
try (ResultSet rs = meta.getProcedures(catalog, schemaPattern, "%")) {
while (rs.next()) {
ObjectNode item = MAPPER.createObjectNode();
item.put("name", rs.getString("PROCEDURE_NAME"));
item.put("object_type", "PROCEDURE");
putNullable(item, "schema", schema);
putNullable(item, "comment", rs.getString("REMARKS"));
result.add(item);
}
} catch (SQLException ignored) {
}
Set<String> procedureNames = new HashSet<>();
for (JsonNode node : result) {
if ("PROCEDURE".equals(node.path("object_type").asText())) {
procedureNames.add(node.path("name").asText());
}
}
try (ResultSet rs = meta.getFunctions(catalog, schemaPattern, "%")) {
while (rs.next()) {
String name = rs.getString("FUNCTION_NAME");
if (!procedureNames.contains(name)) {
ObjectNode item = MAPPER.createObjectNode();
item.put("name", name);
item.put("object_type", "FUNCTION");
putNullable(item, "schema", schema);
putNullable(item, "comment", rs.getString("REMARKS"));
result.add(item);
}
}
} catch (SQLException ignored) {
}
return result;
}
private static JsonNode getColumns(JsonNode connection, String database, String schema, String table) throws SQLException {
ArrayNode result = MAPPER.createArrayNode();
Connection conn = openConnection(connection);