singhpk234 commented on code in PR #1287:
URL: https://github.com/apache/polaris/pull/1287#discussion_r2042516833


##########
extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java:
##########
@@ -0,0 +1,276 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.extension.persistence.relational.jdbc;
+
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Supplier;
+import javax.sql.DataSource;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
+import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.entity.*;
+import org.apache.polaris.core.persistence.*;
+import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet;
+import org.apache.polaris.core.persistence.cache.EntityCache;
+import org.apache.polaris.core.persistence.dao.entity.BaseResult;
+import org.apache.polaris.core.persistence.dao.entity.EntityResult;
+import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult;
+import org.apache.polaris.core.storage.PolarisStorageIntegrationProvider;
+import org.apache.polaris.core.storage.cache.StorageCredentialCache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The implementation of Configuration interface for configuring the {@link 
PolarisMetaStoreManager}
+ * using a JDBC backed by SQL metastore.
+ */
+public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(JdbcMetaStoreManagerFactory.class);
+  final Map<String, PolarisMetaStoreManager> metaStoreManagerMap = new 
HashMap<>();
+  final Map<String, StorageCredentialCache> storageCredentialCacheMap = new 
HashMap<>();
+  final Map<String, EntityCache> entityCacheMap = new HashMap<>();
+  final Map<String, Supplier<BasePersistence>> sessionSupplierMap = new 
HashMap<>();
+  protected final PolarisDiagnostics diagServices = new 
PolarisDefaultDiagServiceImpl();
+
+  DataSource ds;
+  private final PolarisDiagnostics diagnostics;
+  PolarisStorageIntegrationProvider storageIntegrationProvider;
+
+  protected JdbcMetaStoreManagerFactory(@Nonnull PolarisDiagnostics 
diagnostics) {
+    this.diagnostics = diagnostics;
+  }
+
+  /**
+   * Subclasses can override this to inject different implementations of 
PolarisMetaStoreManager
+   * into the existing realm-based setup flow.
+   */
+  protected PolarisMetaStoreManager createNewMetaStoreManager() {
+    return new AtomicOperationMetaStoreManager();
+  }
+
+  private void initializeForRealm(
+      RealmContext realmContext, RootCredentialsSet rootCredentialsSet) {
+    DatasourceOperations databaseOperations = new DatasourceOperations(ds);
+    // TODO: see if we need to take script from Quarkus or can we just
+    // use the script committed repo.
+    
databaseOperations.executeScript("scripts/postgres/schema-v1-postgres.sql");
+    sessionSupplierMap.put(
+        realmContext.getRealmIdentifier(),
+        () ->
+            new JdbcBasePersistenceImpl(
+                databaseOperations,
+                secretsGenerator(realmContext, rootCredentialsSet),
+                storageIntegrationProvider));

Review Comment:
   yes, i think the pass missing here is the following : 
   1. 1 datasource per realm and then use CDI magic to get the corresponding 
Datasource via using custom datasource name. 
   quarkus.datasource.`<real-identifier>`.jdbc.url 
   then while creating the JDBC persistence impl find the DS by real id and 
then wire in.
   2. 1 schema per realm presently if you see we have every table inside one 
schema i.e `POLARIS_SCHEMA`, i could wire in the schema as the realm to 
seperate the tables from each other.
   
   I am open of to both, as 1 I can't do cleanly without taking quarkus magic 
to find the Datasource by name, and 2nd is kind of a deviation as in prev 
Eclipse link impl 1 realm was 1 DB.
   
   please let me know your thoughts considering above.
   
   cc @flyrain 
   



-- 
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: issues-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to