@@ -98,15 +98,14 @@ protected PolarisMetaStoreManager createNewMetaStoreManager() {
9898 }
9999
100100 private void initializeForRealm (
101+ DatasourceOperations datasourceOperations ,
101102 RealmContext realmContext ,
102- RootCredentialsSet rootCredentialsSet ,
103- Optional <SchemaOptions > schemaOptions ) {
104- DatasourceOperations databaseOperations = getDatasourceOperations (schemaOptions );
103+ RootCredentialsSet rootCredentialsSet ) {
105104 sessionSupplierMap .put (
106105 realmContext .getRealmIdentifier (),
107106 () ->
108107 new JdbcBasePersistenceImpl (
109- databaseOperations ,
108+ datasourceOperations ,
110109 secretsGenerator (realmContext , rootCredentialsSet ),
111110 storageIntegrationProvider ,
112111 realmContext .getRealmIdentifier ()));
@@ -115,24 +114,13 @@ private void initializeForRealm(
115114 metaStoreManagerMap .put (realmContext .getRealmIdentifier (), metaStoreManager );
116115 }
117116
118- private DatasourceOperations getDatasourceOperations (Optional < SchemaOptions > schemaOptions ) {
117+ public DatasourceOperations getDatasourceOperations () {
119118 DatasourceOperations databaseOperations ;
120119 try {
121120 databaseOperations = new DatasourceOperations (dataSource .get (), relationalJdbcConfiguration );
122121 } catch (SQLException sqlException ) {
123122 throw new RuntimeException (sqlException );
124123 }
125- // If this is set, we are bootstrapping
126- if (schemaOptions .isPresent ()) {
127- try {
128- // Run the set-up script to create the tables.
129- databaseOperations .executeScript (
130- databaseOperations .getDatabaseType ().getInitScriptResource (schemaOptions .get ()));
131- } catch (SQLException e ) {
132- throw new RuntimeException (
133- String .format ("Error executing sql script: %s" , e .getMessage ()), e );
134- }
135- }
136124 return databaseOperations ;
137125 }
138126
@@ -159,10 +147,19 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(
159147 for (String realm : bootstrapOptions .realms ()) {
160148 RealmContext realmContext = () -> realm ;
161149 if (!metaStoreManagerMap .containsKey (realm )) {
150+ DatasourceOperations datasourceOperations = getDatasourceOperations ();
151+ try {
152+ // Run the set-up script to create the tables.
153+ datasourceOperations .executeScript (
154+ datasourceOperations .getDatabaseType ().getInitScriptResource (bootstrapOptions .schemaOptions ()));
155+ } catch (SQLException e ) {
156+ throw new RuntimeException (
157+ String .format ("Error executing sql script: %s" , e .getMessage ()), e );
158+ }
162159 initializeForRealm (
160+ datasourceOperations ,
163161 realmContext ,
164- bootstrapOptions .rootCredentialsSet (),
165- Optional .of (bootstrapOptions .schemaOptions ()));
162+ bootstrapOptions .rootCredentialsSet ());
166163 PrincipalSecretsResult secretsResult =
167164 bootstrapServiceAndCreatePolarisPrincipalForRealm (
168165 realmContext , metaStoreManagerMap .get (realm ));
@@ -198,7 +195,8 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
198195 public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager (
199196 RealmContext realmContext ) {
200197 if (!metaStoreManagerMap .containsKey (realmContext .getRealmIdentifier ())) {
201- initializeForRealm (realmContext , null , Optional .empty ());
198+ DatasourceOperations datasourceOperations = getDatasourceOperations ();
199+ initializeForRealm (datasourceOperations , realmContext , null );
202200 checkPolarisServiceBootstrappedForRealm (
203201 realmContext , metaStoreManagerMap .get (realmContext .getRealmIdentifier ()));
204202 }
@@ -209,7 +207,8 @@ public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(
209207 public synchronized Supplier <BasePersistence > getOrCreateSessionSupplier (
210208 RealmContext realmContext ) {
211209 if (!sessionSupplierMap .containsKey (realmContext .getRealmIdentifier ())) {
212- initializeForRealm (realmContext , null , Optional .empty ());
210+ DatasourceOperations datasourceOperations = getDatasourceOperations ();
211+ initializeForRealm (datasourceOperations , realmContext , null );
213212 checkPolarisServiceBootstrappedForRealm (
214213 realmContext , metaStoreManagerMap .get (realmContext .getRealmIdentifier ()));
215214 } else {
0 commit comments