2 files changed
+63
-5
No files matched your search
+35
@@ -722,6 +722,9 @@ public final class OceanBaseOracleAgent extends ConfiguredJdbcAgent {
|
|||||||
String owner = normalizeSchema(schema);
|
String owner = normalizeSchema(schema);
|
||||||
String objectName = normalizeObjectName(name);
|
String objectName = normalizeObjectName(name);
|
||||||
String normalizedType = normalizeObjectSourceType(objectType);
|
String normalizedType = normalizeObjectSourceType(objectType);
|
||||||
|
if (prefersDictionarySource(normalizedType)) {
|
||||||
|
return getDictionaryFirstObjectSource(owner, objectName, normalizedType);
|
||||||
|
}
|
||||||
String source;
|
String source;
|
||||||
SQLException metadataError = null;
|
SQLException metadataError = null;
|
||||||
try {
|
try {
|
||||||
@@ -751,6 +754,30 @@ public final class OceanBaseOracleAgent extends ConfiguredJdbcAgent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ObjectSource getDictionaryFirstObjectSource(String owner, String name, String objectType) throws SQLException {
|
||||||
|
String source;
|
||||||
|
SQLException dictionaryError = null;
|
||||||
|
try {
|
||||||
|
source = queryDictionarySource(owner, name, objectType);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
dictionaryError = e;
|
||||||
|
source = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source == null || source.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
source = queryDbmsMetadataSource(owner, name, objectType);
|
||||||
|
} catch (SQLException metadataError) {
|
||||||
|
if (dictionaryError != null) {
|
||||||
|
dictionaryError.addSuppressed(metadataError);
|
||||||
|
throw dictionaryError;
|
||||||
|
}
|
||||||
|
throw metadataError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ObjectSource(name, objectType, owner, source == null ? "" : source);
|
||||||
|
}
|
||||||
|
|
||||||
private String queryDbmsMetadataSource(String owner, String name, String objectType) throws SQLException {
|
private String queryDbmsMetadataSource(String owner, String name, String objectType) throws SQLException {
|
||||||
if ("SYNONYM".equals(objectType)) {
|
if ("SYNONYM".equals(objectType)) {
|
||||||
// GET_DDL does not cover synonyms on every supported OB version.
|
// GET_DDL does not cover synonyms on every supported OB version.
|
||||||
@@ -794,6 +821,7 @@ public final class OceanBaseOracleAgent extends ConfiguredJdbcAgent {
|
|||||||
stmt.setString(1, owner);
|
stmt.setString(1, owner);
|
||||||
stmt.setString(2, name);
|
stmt.setString(2, name);
|
||||||
stmt.setString(3, sourceType);
|
stmt.setString(3, sourceType);
|
||||||
|
stmt.setFetchSize(256);
|
||||||
try (ResultSet rs = stmt.executeQuery()) {
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
String line = rs.getString(1);
|
String line = rs.getString(1);
|
||||||
@@ -824,6 +852,13 @@ public final class OceanBaseOracleAgent extends ConfiguredJdbcAgent {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean prefersDictionarySource(String objectType) {
|
||||||
|
return switch (objectType) {
|
||||||
|
case "PROCEDURE", "FUNCTION", "PACKAGE", "PACKAGE_BODY", "TRIGGER", "TYPE", "TYPE_BODY" -> true;
|
||||||
|
default -> false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private static String editableOracleSource(String source) {
|
private static String editableOracleSource(String source) {
|
||||||
String trimmed = source.trim();
|
String trimmed = source.trim();
|
||||||
if (trimmed.isEmpty() || trimmed.regionMatches(true, 0, "CREATE ", 0, "CREATE ".length())) {
|
if (trimmed.isEmpty() || trimmed.regionMatches(true, 0, "CREATE ", 0, "CREATE ".length())) {
|
||||||
|
|||||||
+28
-5
@@ -621,7 +621,7 @@ class OceanBaseOracleAgentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fallsBackToAllSourceForOracleRoutineAndPackageTypes() {
|
void readsOracleRoutineAndPackageTypesFromAllSourceFirst() {
|
||||||
for (String[] object : new String[][]{
|
for (String[] object : new String[][]{
|
||||||
{"PROCEDURE", "PROCEDURE"},
|
{"PROCEDURE", "PROCEDURE"},
|
||||||
{"FUNCTION", "FUNCTION"},
|
{"FUNCTION", "FUNCTION"},
|
||||||
@@ -631,7 +631,7 @@ class OceanBaseOracleAgentTest {
|
|||||||
List<String> sql = new ArrayList<>();
|
List<String> sql = new ArrayList<>();
|
||||||
List<String> params = new ArrayList<>();
|
List<String> params = new ArrayList<>();
|
||||||
OceanBaseOracleAgent agent = new OceanBaseOracleAgent();
|
OceanBaseOracleAgent agent = new OceanBaseOracleAgent();
|
||||||
TestSupport.setPrivateConnection(agent, objectSourceFallbackConnection(
|
TestSupport.setPrivateConnection(agent, objectSourceConnection(
|
||||||
sql,
|
sql,
|
||||||
params,
|
params,
|
||||||
resultSet(
|
resultSet(
|
||||||
@@ -645,14 +645,37 @@ class OceanBaseOracleAgentTest {
|
|||||||
Assertions.assertEquals(object[0], source.getObject_type());
|
Assertions.assertEquals(object[0], source.getObject_type());
|
||||||
Assertions.assertTrue(source.getSource().startsWith("CREATE OR REPLACE " + object[1]), source.getSource());
|
Assertions.assertTrue(source.getSource().startsWith("CREATE OR REPLACE " + object[1]), source.getSource());
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
List.of(object[0], "MixedRoutine", "MixedOwner", "MixedOwner", "MixedRoutine", object[1]),
|
List.of("MixedOwner", "MixedRoutine", object[1]),
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
Assertions.assertTrue(sql.get(1).contains("ALL_SOURCE"), sql.get(1));
|
Assertions.assertEquals(1, sql.size());
|
||||||
Assertions.assertTrue(sql.get(1).contains("ORDER BY LINE"), sql.get(1));
|
Assertions.assertTrue(sql.get(0).contains("ALL_SOURCE"), sql.get(0));
|
||||||
|
Assertions.assertTrue(sql.get(0).contains("ORDER BY LINE"), sql.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fallsBackToDbmsMetadataWhenAllSourceIsUnavailable() {
|
||||||
|
List<String> sql = new ArrayList<>();
|
||||||
|
List<String> params = new ArrayList<>();
|
||||||
|
OceanBaseOracleAgent agent = new OceanBaseOracleAgent();
|
||||||
|
TestSupport.setPrivateConnection(agent, objectSourceFallbackConnection(
|
||||||
|
sql,
|
||||||
|
params,
|
||||||
|
resultSet(
|
||||||
|
new String[]{"DDL"},
|
||||||
|
new Object[][]{{"CREATE OR REPLACE PROCEDURE APP.P1 AS BEGIN NULL; END;"}}
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
ObjectSource source = agent.getObjectSource("APP", "P1", "PROCEDURE");
|
||||||
|
|
||||||
|
Assertions.assertTrue(source.getSource().startsWith("CREATE OR REPLACE PROCEDURE"), source.getSource());
|
||||||
|
Assertions.assertTrue(sql.get(0).contains("ALL_SOURCE"), sql.get(0));
|
||||||
|
Assertions.assertTrue(sql.get(1).contains("DBMS_METADATA.GET_DDL"), sql.get(1));
|
||||||
|
Assertions.assertEquals(List.of("APP", "P1", "PROCEDURE", "PROCEDURE", "P1", "APP"), params);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void synonymSourcePreservesOwnersQuotedNamesAndRemoteLinkDomains() {
|
void synonymSourcePreservesOwnersQuotedNamesAndRemoteLinkDomains() {
|
||||||
for (String owner : List.of("Mixed.Owner", "PUBLIC")) {
|
for (String owner : List.of("Mixed.Owner", "PUBLIC")) {
|
||||||
|
|||||||
Reference in new issue
Block a user