fix(informix): hide empty owners without losing routines
This commit is contained in:
parent
336fbe094b
commit
5bd9f41abe
|
|
@ -24,10 +24,10 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public final class InformixAgent extends AbstractJdbcAgent {
|
||||
private String loginOwner = "";
|
||||
|
|
@ -187,28 +187,25 @@ public final class InformixAgent extends AbstractJdbcAgent {
|
|||
}
|
||||
}
|
||||
}
|
||||
return mergeSchemaOwners(catalogOwners, loginOwner);
|
||||
return normalizeSchemaOwners(catalogOwners);
|
||||
});
|
||||
}
|
||||
|
||||
static String schemaCatalogSql() {
|
||||
// Informix JDBC catalogs are databases; schemas are the object owners in the current database.
|
||||
// Informix schemas are object owners. Include routine-only owners because
|
||||
// the same sidebar node also exposes procedures and functions.
|
||||
return "SELECT owner FROM systables WHERE tabid >= 100 AND owner IS NOT NULL "
|
||||
+ "UNION SELECT owner FROM sysprocedures WHERE owner IS NOT NULL ORDER BY owner";
|
||||
}
|
||||
|
||||
static List<String> mergeSchemaOwners(List<String> catalogOwners, String loginOwner) {
|
||||
Set<String> owners = new TreeSet<>();
|
||||
static List<String> normalizeSchemaOwners(List<String> catalogOwners) {
|
||||
Set<String> owners = new LinkedHashSet<>();
|
||||
for (String owner : catalogOwners) {
|
||||
String normalized = normalizeOwner(owner);
|
||||
if (!normalized.isEmpty()) {
|
||||
owners.add(normalized);
|
||||
}
|
||||
}
|
||||
String normalizedLoginOwner = normalizeOwner(loginOwner);
|
||||
if (!normalizedLoginOwner.isEmpty()) {
|
||||
owners.add(normalizedLoginOwner);
|
||||
}
|
||||
return new ArrayList<>(owners);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ class InformixAgentTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void listsSchemasFromTableRoutineAndCurrentLoginOwners() {
|
||||
void listsSchemasFromTableAndRoutineOwnersWithoutLoginFallback() {
|
||||
InformixAgent agent = new InformixAgent();
|
||||
java.sql.Connection connection = JdbcMetadataSqlFake.connection();
|
||||
TestSupport.setPrivateConnection(agent, connection);
|
||||
|
|
@ -181,7 +181,7 @@ class InformixAgentTest {
|
|||
params.setUsername("current_owner");
|
||||
agent.afterConnect(params, connection);
|
||||
|
||||
Assertions.assertEquals(List.of("current_owner"), agent.listSchemas());
|
||||
Assertions.assertEquals(List.of(), agent.listSchemas());
|
||||
|
||||
Assertions.assertEquals(
|
||||
List.of("SELECT owner FROM systables WHERE tabid >= 100 AND owner IS NOT NULL "
|
||||
|
|
@ -189,12 +189,11 @@ class InformixAgentTest {
|
|||
JdbcMetadataSqlFake.statements
|
||||
);
|
||||
Assertions.assertEquals(
|
||||
List.of("current_owner", "routine_owner", "table_owner"),
|
||||
InformixAgent.mergeSchemaOwners(
|
||||
List.of("table_owner", "routine_owner", "routine_owner", " "),
|
||||
"current_owner"
|
||||
)
|
||||
List.of("table_owner", "routine_owner"),
|
||||
InformixAgent.normalizeSchemaOwners(List.of("table_owner", "routine_owner", "routine_owner", " "))
|
||||
);
|
||||
Assertions.assertTrue(InformixAgent.schemaCatalogSql().contains("sysprocedures"));
|
||||
Assertions.assertFalse(InformixAgent.normalizeSchemaOwners(List.of("routine_owner", " ")).contains("current_owner"));
|
||||
Assertions.assertNotEquals(InformixAgent.databaseCatalogSql(), InformixAgent.schemaCatalogSql());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue