added multi persistence unit support

This commit is contained in:
2018-11-16 12:43:20 +01:00
parent 349310ccf9
commit b2c2619dc4
12 changed files with 118 additions and 41 deletions

View File

@ -1,5 +1,6 @@
package de.muehlencord.shared.account.web;
import de.muehlencord.shared.account.util.AccountPU;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Disposes;
@ -17,26 +18,27 @@ import org.slf4j.LoggerFactory;
*/
@ApplicationScoped
public class PersistenceContextFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(PersistenceContextFactory.class);
@PersistenceUnit
@PersistenceUnit (unitName = "accountPu")
EntityManagerFactory emf;
@Produces
@AccountPU
@RequestScoped
public EntityManager getEntityManager() {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("getting entityManager");
}
LOGGER.trace("getting entityManager for accountPu");
}
return emf.createEntityManager(SynchronizationType.UNSYNCHRONIZED);
}
public void closeEntityManager (@Disposes EntityManager em) {
public void closeEntityManager(@Disposes EntityManager em) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("closing entityManager");
}
}
em.close();
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="de.muehlencord.shared.accountUiPu" transaction-type="JTA">
<persistence-unit name="accountPu" transaction-type="JTA">
<jta-data-source>java:/jboss/accountDs</jta-data-source>
<class>de.muehlencord.shared.account.business.account.entity.AccountEntity</class>
<class>de.muehlencord.shared.account.business.account.entity.AccountHistoryEntity</class>