fix(informix): hide empty owners without losing routines
This commit is contained in:
2 files changed
+12
-16
No files matched your search
@@ -24,10 +24,10 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
public final class InformixAgent extends AbstractJdbcAgent {
|
public final class InformixAgent extends AbstractJdbcAgent {
|
||||||
private String loginOwner = "";
|
private String loginOwner = "";
|
||||||
@@ -187,28 +187,25 @@ public final class InformixAgent extends AbstractJdbcAgent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mergeSchemaOwners(catalogOwners, loginOwner);
|
return normalizeSchemaOwners(catalogOwners);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static String schemaCatalogSql() {
|
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 "
|
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";
|
+ "UNION SELECT owner FROM sysprocedures WHERE owner IS NOT NULL ORDER BY owner";
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<String> mergeSchemaOwners(List<String> catalogOwners, String loginOwner) {
|
static List<String> normalizeSchemaOwners(List<String> catalogOwners) {
|
||||||
Set<String> owners = new TreeSet<>();
|
Set<String> owners = new LinkedHashSet<>();
|
||||||
for (String owner : catalogOwners) {
|
for (String owner : catalogOwners) {
|
||||||
String normalized = normalizeOwner(owner);
|
String normalized = normalizeOwner(owner);
|
||||||
if (!normalized.isEmpty()) {
|
if (!normalized.isEmpty()) {
|
||||||
owners.add(normalized);
|
owners.add(normalized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String normalizedLoginOwner = normalizeOwner(loginOwner);
|
|
||||||
if (!normalizedLoginOwner.isEmpty()) {
|
|
||||||
owners.add(normalizedLoginOwner);
|
|
||||||
}
|
|
||||||
return new ArrayList<>(owners);
|
return new ArrayList<>(owners);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ class InformixAgentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void listsSchemasFromTableRoutineAndCurrentLoginOwners() {
|
void listsSchemasFromTableAndRoutineOwnersWithoutLoginFallback() {
|
||||||
InformixAgent agent = new InformixAgent();
|
InformixAgent agent = new InformixAgent();
|
||||||
java.sql.Connection connection = JdbcMetadataSqlFake.connection();
|
java.sql.Connection connection = JdbcMetadataSqlFake.connection();
|
||||||
TestSupport.setPrivateConnection(agent, connection);
|
TestSupport.setPrivateConnection(agent, connection);
|
||||||
@@ -181,7 +181,7 @@ class InformixAgentTest {
|
|||||||
params.setUsername("current_owner");
|
params.setUsername("current_owner");
|
||||||
agent.afterConnect(params, connection);
|
agent.afterConnect(params, connection);
|
||||||
|
|
||||||
Assertions.assertEquals(List.of("current_owner"), agent.listSchemas());
|
Assertions.assertEquals(List.of(), agent.listSchemas());
|
||||||
|
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
List.of("SELECT owner FROM systables WHERE tabid >= 100 AND owner IS NOT NULL "
|
List.of("SELECT owner FROM systables WHERE tabid >= 100 AND owner IS NOT NULL "
|
||||||
@@ -189,12 +189,11 @@ class InformixAgentTest {
|
|||||||
JdbcMetadataSqlFake.statements
|
JdbcMetadataSqlFake.statements
|
||||||
);
|
);
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
List.of("current_owner", "routine_owner", "table_owner"),
|
List.of("table_owner", "routine_owner"),
|
||||||
InformixAgent.mergeSchemaOwners(
|
InformixAgent.normalizeSchemaOwners(List.of("table_owner", "routine_owner", "routine_owner", " "))
|
||||||
List.of("table_owner", "routine_owner", "routine_owner", " "),
|
|
||||||
"current_owner"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
Assertions.assertTrue(InformixAgent.schemaCatalogSql().contains("sysprocedures"));
|
||||||
|
Assertions.assertFalse(InformixAgent.normalizeSchemaOwners(List.of("routine_owner", " ")).contains("current_owner"));
|
||||||
Assertions.assertNotEquals(InformixAgent.databaseCatalogSql(), InformixAgent.schemaCatalogSql());
|
Assertions.assertNotEquals(InformixAgent.databaseCatalogSql(), InformixAgent.schemaCatalogSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user