Skip to content

Commit

Permalink
Remove reuse EntityManagerFactory since we need to have different one…
Browse files Browse the repository at this point in the history
… for different realm
  • Loading branch information
aihuaxu committed Aug 7, 2024
1 parent c7bbb3d commit cb23532
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class PolarisEclipseLinkMetaStoreSessionImpl implements PolarisMetaStoreS
private static final Logger LOG =
LoggerFactory.getLogger(PolarisEclipseLinkMetaStoreSessionImpl.class);

private static volatile EntityManagerFactory emf;
private final EntityManagerFactory emf;
private final ThreadLocal<EntityManager> localSession = new ThreadLocal<>();
private final PolarisEclipseLinkStore store;
private final PolarisStorageIntegrationProvider storageIntegrationProvider;
Expand Down Expand Up @@ -114,17 +114,13 @@ public PolarisEclipseLinkMetaStoreSessionImpl(
/**
* Create EntityManagerFactory.
*
* <p>The creation is expensive, but it should only need to create once and can be reused across
* the sessions.
* <p>TODO: The EntityManagerFactory creation is expensive. We should consider save and reuse for
* each realm.
*/
private EntityManagerFactory createEntityManagerFactory(
@NotNull RealmContext realmContext,
@Nullable String confFile,
@Nullable String persistenceUnitName) {
if (emf != null) {
return emf;
}

ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
try {
persistenceUnitName = persistenceUnitName == null ? "polaris" : persistenceUnitName;
Expand Down Expand Up @@ -171,14 +167,6 @@ private EntityManagerFactory createEntityManagerFactory(
}
}

@TestOnly
static void clearEntityManagerFactory() {
if (emf != null) {
emf.close();
emf = null;
}
}

/** Load the persistence unit properties from a given configuration file */
private Map<String, String> loadProperties(
@NotNull String confFile, @NotNull String persistenceUnitName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
@ParameterizedTest()
@ArgumentsSource(CreateStoreSessionArgs.class)
void testCreateStoreSession(String confFile, boolean success) {
// Clear to test out EntityManagerFactory creation rather than reusing
PolarisEclipseLinkMetaStoreSessionImpl.clearEntityManagerFactory();

PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices);
try {
Expand Down

0 comments on commit cb23532

Please sign in to comment.