From 06c7a9ca8e5cf954d1cf38004b54565cd3826157 Mon Sep 17 00:00:00 2001 From: Smith Cruise Date: Fri, 11 Oct 2024 13:01:57 +0800 Subject: [PATCH] [BugFix] Fix jdbc catalog change password not effect (#51748) Signed-off-by: Smith Cruise (cherry picked from commit acce535baf083fa54e2ae5cead5123118e722c80) # Conflicts: # java-extensions/jdbc-bridge/src/main/java/com/starrocks/jdbcbridge/JDBCScanner.java --- .../com/starrocks/jdbcbridge/JDBCScanner.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/java-extensions/jdbc-bridge/src/main/java/com/starrocks/jdbcbridge/JDBCScanner.java b/java-extensions/jdbc-bridge/src/main/java/com/starrocks/jdbcbridge/JDBCScanner.java index b228b715e9c72..6abfd4c09311d 100644 --- a/java-extensions/jdbc-bridge/src/main/java/com/starrocks/jdbcbridge/JDBCScanner.java +++ b/java-extensions/jdbc-bridge/src/main/java/com/starrocks/jdbcbridge/JDBCScanner.java @@ -61,12 +61,17 @@ public JDBCScanner(String driverLocation, JDBCScanContext scanContext) { } public void open() throws Exception { - String key = scanContext.getUser() + "/" + scanContext.getJdbcURL(); + String cacheKey = computeCacheKey(scanContext.getUser(), scanContext.getPassword(), scanContext.getJdbcURL()); URL driverURL = new File(driverLocation).toURI().toURL(); +<<<<<<< HEAD DataSourceCache.DataSourceCacheItem cacheItem = DataSourceCache.getInstance().getSource(key, () -> { ClassLoader classLoader = URLClassLoader.newInstance(new URL[] { driverURL, }); +======= + DataSourceCache.DataSourceCacheItem cacheItem = DataSourceCache.getInstance().getSource(cacheKey, () -> { + ClassLoader classLoader = URLClassLoader.newInstance(new URL[] {driverURL}); +>>>>>>> acce535baf ([BugFix] Fix jdbc catalog change password not effect (#51748)) Thread.currentThread().setContextClassLoader(classLoader); HikariConfig config = new HikariConfig(); config.setDriverClassName(scanContext.getDriverClassName()); @@ -118,6 +123,7 @@ public void open() throws Exception { } } +<<<<<<< HEAD private static final Set> GENERAL_JDBC_CLASS_SET = new HashSet<>(Arrays.asList( Boolean.class, Short.class, @@ -133,6 +139,16 @@ public void open() throws Exception { Time.class, String.class )); +======= + private static String computeCacheKey(String username, String password, String jdbcUrl) { + return username + "/" + password + "/" + jdbcUrl; + } + + private static final Set> GENERAL_JDBC_CLASS_SET = new HashSet<>( + Arrays.asList(Boolean.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, + BigInteger.class, BigDecimal.class, java.sql.Date.class, Timestamp.class, LocalDate.class, + LocalDateTime.class, Time.class, String.class)); +>>>>>>> acce535baf ([BugFix] Fix jdbc catalog change password not effect (#51748)) private boolean isGeneralJDBCClassType(Class clazz) { return GENERAL_JDBC_CLASS_SET.contains(clazz);