added multi persistence unit support
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
package de.muehlencord.shared.account.web;
|
package de.muehlencord.shared.account.web;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.enterprise.inject.Disposes;
|
import javax.enterprise.inject.Disposes;
|
||||||
@ -20,14 +21,15 @@ public class PersistenceContextFactory {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(PersistenceContextFactory.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(PersistenceContextFactory.class);
|
||||||
|
|
||||||
@PersistenceUnit
|
@PersistenceUnit (unitName = "accountPu")
|
||||||
EntityManagerFactory emf;
|
EntityManagerFactory emf;
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
|
@AccountPU
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public EntityManager getEntityManager() {
|
public EntityManager getEntityManager() {
|
||||||
if (LOGGER.isTraceEnabled()) {
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace("getting entityManager");
|
LOGGER.trace("getting entityManager for accountPu");
|
||||||
}
|
}
|
||||||
return emf.createEntityManager(SynchronizationType.UNSYNCHRONIZED);
|
return emf.createEntityManager(SynchronizationType.UNSYNCHRONIZED);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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 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>
|
<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.AccountEntity</class>
|
||||||
<class>de.muehlencord.shared.account.business.account.entity.AccountHistoryEntity</class>
|
<class>de.muehlencord.shared.account.business.account.entity.AccountHistoryEntity</class>
|
||||||
|
|||||||
@ -2,13 +2,13 @@ package de.muehlencord.shared.account.business.account.control;
|
|||||||
|
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountStatus;
|
import de.muehlencord.shared.account.business.account.entity.AccountStatus;
|
||||||
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
|
||||||
import de.muehlencord.shared.account.business.mail.entity.MailException;
|
import de.muehlencord.shared.account.business.mail.entity.MailException;
|
||||||
import de.muehlencord.shared.account.business.mail.boundary.MailService;
|
import de.muehlencord.shared.account.business.mail.boundary.MailService;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity;
|
||||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import de.muehlencord.shared.account.util.SecurityUtil;
|
import de.muehlencord.shared.account.util.SecurityUtil;
|
||||||
import de.muehlencord.shared.util.DateUtil;
|
import de.muehlencord.shared.util.DateUtil;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -38,9 +38,6 @@ public class AccountControl implements Serializable {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(AccountControl.class.getName());
|
private static final Logger LOGGER = LoggerFactory.getLogger(AccountControl.class.getName());
|
||||||
private static final long serialVersionUID = 3424816272598108101L;
|
private static final long serialVersionUID = 3424816272598108101L;
|
||||||
|
|
||||||
@EJB
|
|
||||||
private ConfigService configService;
|
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
private MailService mailService;
|
private MailService mailService;
|
||||||
|
|
||||||
@ -48,6 +45,7 @@ public class AccountControl implements Serializable {
|
|||||||
private ApplicationEntity application;
|
private ApplicationEntity application;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,7 +279,6 @@ public class AccountControl implements Serializable {
|
|||||||
return updateLogin(login);
|
return updateLogin(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AccountLoginEntity updateLogin(AccountLoginEntity login) {
|
public AccountLoginEntity updateLogin(AccountLoginEntity login) {
|
||||||
return em.merge(login);
|
return em.merge(login);
|
||||||
}
|
}
|
||||||
@ -294,8 +291,6 @@ public class AccountControl implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void addLoginError(AccountEntity account) {
|
public void addLoginError(AccountEntity account) {
|
||||||
// TODO reimplement
|
// TODO reimplement
|
||||||
// try {
|
// try {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package de.muehlencord.shared.account.business.application.boundary;
|
package de.muehlencord.shared.account.business.application.boundary;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -24,6 +25,7 @@ public class ApplicationService implements Serializable {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationService.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationService.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
public ApplicationEntity findById(UUID id) {
|
public ApplicationEntity findById(UUID id) {
|
||||||
|
|||||||
@ -3,12 +3,13 @@ package de.muehlencord.shared.account.business.application.control;
|
|||||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.persistence.OptimisticLockException;
|
import javax.persistence.OptimisticLockException;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
@ -22,7 +23,8 @@ public class ApplicationPermissionControl implements Serializable {
|
|||||||
|
|
||||||
private static final long serialVersionUID = -3761100587901739481L;
|
private static final long serialVersionUID = -3761100587901739481L;
|
||||||
|
|
||||||
@PersistenceContext
|
@Inject
|
||||||
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
|
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
|
||||||
|
|||||||
@ -9,14 +9,15 @@ import de.muehlencord.shared.account.business.account.entity.AccountException;
|
|||||||
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
|
||||||
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.ejb.EJB;
|
import javax.ejb.EJB;
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.OptimisticLockException;
|
import javax.persistence.OptimisticLockException;
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -35,7 +36,8 @@ public class ApplicationRoleControl implements Serializable {
|
|||||||
@EJB
|
@EJB
|
||||||
ApplicationPermissionControl applicationPermissionControl;
|
ApplicationPermissionControl applicationPermissionControl;
|
||||||
|
|
||||||
@PersistenceContext
|
@Inject
|
||||||
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
public List<ApplicationRoleEntity> getAllRoles(ApplicationEntity app) {
|
public List<ApplicationRoleEntity> getAllRoles(ApplicationEntity app) {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import de.muehlencord.shared.account.business.application.entity.ApplicationEnti
|
|||||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -33,6 +34,7 @@ public class ConfigService implements Serializable {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigService.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigService.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business.config.boundary;
|
package de.muehlencord.shared.account.business.config.boundary;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
|
||||||
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey;
|
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey;
|
||||||
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue;
|
import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package de.muehlencord.shared.account.business.mail.boundary;
|
|||||||
import de.muehlencord.shared.account.business.mail.entity.MailDatamodel;
|
import de.muehlencord.shared.account.business.mail.entity.MailDatamodel;
|
||||||
import de.muehlencord.shared.account.business.mail.entity.MailTemplateException;
|
import de.muehlencord.shared.account.business.mail.entity.MailTemplateException;
|
||||||
import de.muehlencord.shared.account.business.mail.entity.MailTemplateEntity;
|
import de.muehlencord.shared.account.business.mail.entity.MailTemplateEntity;
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import freemarker.cache.StringTemplateLoader;
|
import freemarker.cache.StringTemplateLoader;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
@ -29,6 +30,7 @@ public class MailTemplateService implements Serializable {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MailTemplateService.class.getName());
|
private static final Logger LOGGER = LoggerFactory.getLogger(MailTemplateService.class.getName());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
public String getStringFromTemplate(String templateName, MailDatamodel dataModel) throws MailTemplateException {
|
public String getStringFromTemplate(String templateName, MailDatamodel dataModel) throws MailTemplateException {
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package de.muehlencord.shared.account.util;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.FIELD;
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.ElementType.PARAMETER;
|
||||||
|
import static java.lang.annotation.ElementType.TYPE;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Target({METHOD, FIELD, PARAMETER, TYPE})
|
||||||
|
public @interface AccountPU {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package de.muehlencord.shared.account.util;
|
||||||
|
|
||||||
|
import javax.annotation.Priority;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.interceptor.AroundInvoke;
|
||||||
|
import javax.interceptor.Interceptor;
|
||||||
|
import javax.interceptor.InvocationContext;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import static javax.transaction.Transactional.TxType.REQUIRED;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
|
*/
|
||||||
|
@Transactional(value = REQUIRED)
|
||||||
|
@Interceptor
|
||||||
|
@Priority(value=TransactionJoinInterceptor.PRIORITY)
|
||||||
|
public class TransactionJoinInterceptor {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(TransactionJoinInterceptor.class);
|
||||||
|
|
||||||
|
// attach behind the interceptor of the container
|
||||||
|
public static final int PRIORITY = Interceptor.Priority.PLATFORM_BEFORE+250;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@AccountPU
|
||||||
|
private EntityManager em;
|
||||||
|
|
||||||
|
|
||||||
|
@AroundInvoke
|
||||||
|
public Object joinTransaction(InvocationContext context) throws Exception {
|
||||||
|
if (em.isJoinedToTransaction()) {
|
||||||
|
LOGGER.trace("transaction already joined");
|
||||||
|
} else {
|
||||||
|
LOGGER.trace("joining transaction");
|
||||||
|
em.joinTransaction();
|
||||||
|
}
|
||||||
|
return context.proceed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,13 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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 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_shared-account_ejb_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
|
<persistence-unit name="accountPu" transaction-type="RESOURCE_LOCAL">
|
||||||
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
|
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
|
||||||
<exclude-unlisted-classes>false</exclude-unlisted-classes>
|
<exclude-unlisted-classes>false</exclude-unlisted-classes>
|
||||||
|
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/radius"/>
|
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/>
|
||||||
<property name="javax.persistence.jdbc.user" value="jomu"/>
|
<property name="hibernate.show_sql" value="false"/>
|
||||||
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
<property name="hibernate.cache.use_second_level_cache" value="true"/>
|
||||||
<property name="javax.persistence.jdbc.password" value="jomu"/>
|
<property name="hibernate.cache.use_query_cache" value="true"/>
|
||||||
</properties>
|
</properties>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|||||||
Reference in New Issue
Block a user