fixed broken persistence implementation after refactor generalization

This commit is contained in:
2019-01-18 14:28:35 +01:00
parent 2659ba1ff5
commit 1aab667a8e
3 changed files with 57 additions and 27 deletions

View File

@ -1,6 +1,7 @@
package de.muehlencord.shared.account.web;
import de.muehlencord.shared.account.util.AccountPU;
import de.muehlencord.shared.account.util.ApplicationPU;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Disposes;
@ -21,24 +22,50 @@ public class PersistenceContextFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(PersistenceContextFactory.class);
// need to define 2nd database as TransactionJoinInterceptor requires it
// account UI is the only application where application and account is the same database
// account UI does not call this as it references all database access via accountPu
@PersistenceUnit (unitName = "accountPu")
EntityManagerFactory emf;
@Produces
@AccountPU
EntityManagerFactory applicationEntityManagerFactory;
@PersistenceUnit (unitName = "accountPu")
EntityManagerFactory accountEntityManagerFactory;
@Produces
@RequestScoped
public EntityManager getEntityManager() {
@ApplicationPU
public EntityManager getPcdEntityManager() {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("getting entityManager for accountPu");
}
return emf.createEntityManager(SynchronizationType.UNSYNCHRONIZED);
LOGGER.trace("getting entityManager for application");
}
EntityManager em = applicationEntityManagerFactory.createEntityManager(SynchronizationType.UNSYNCHRONIZED);
return em;
}
public void closeEntityManager(@Disposes @AccountPU EntityManager em) {
public void closePcdEntityManager (@Disposes @ApplicationPU EntityManager em) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("closing entityManager");
}
LOGGER.trace("closing entityManager application database");
}
em.close();
}
}
@Produces
@RequestScoped
@AccountPU
public EntityManager getAccountEntityManager() {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("getting entityManager for account database");
}
EntityManager em = accountEntityManagerFactory.createEntityManager(SynchronizationType.UNSYNCHRONIZED);
return em;
}
public void closeAccountEntityManager (@Disposes @AccountPU EntityManager em) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("closing entityManager for account database");
}
em.close();
}
}