flyrain commented on code in PR #1843:
URL: https://github.com/apache/polaris/pull/1843#discussion_r2138513484


##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DatasourceOperations.java:
##########
@@ -55,64 +55,71 @@ public class DatasourceOperations {
 
   private final DataSource datasource;
   private final RelationalJdbcConfiguration relationalJdbcConfiguration;
-  private final DatabaseType databaseType;
+  private volatile DatabaseType databaseType;
 
   private final Random random = new Random();
 
   public DatasourceOperations(
-      DataSource datasource,
-      DatabaseType databaseType,
-      RelationalJdbcConfiguration relationalJdbcConfiguration) {
+      DataSource datasource, RelationalJdbcConfiguration 
relationalJdbcConfiguration) {
     this.datasource = datasource;
-    this.databaseType = databaseType;
     this.relationalJdbcConfiguration = relationalJdbcConfiguration;
   }
 
-  public DatabaseType getDatabaseType() {
+  protected DatabaseType getDatabaseType() throws SQLException {
+    if (databaseType == null) {
+      synchronized (this) {
+        if (databaseType == null) {
+          try (Connection connection = datasource.getConnection()) {
+            String productName = 
connection.getMetaData().getDatabaseProductName();
+            return DatabaseType.fromDisplayName(productName);
+          }
+        }
+      }

Review Comment:
   Can we set it in the constructor?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to