added multi persistence unit support
This commit is contained in:
@ -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;
|
||||
@ -20,19 +21,20 @@ 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");
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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.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.boundary.MailService;
|
||||
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.ApplicationRoleEntity;
|
||||
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.util.DateUtil;
|
||||
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 long serialVersionUID = 3424816272598108101L;
|
||||
|
||||
@EJB
|
||||
private ConfigService configService;
|
||||
|
||||
@EJB
|
||||
private MailService mailService;
|
||||
|
||||
@ -48,6 +45,7 @@ public class AccountControl implements Serializable {
|
||||
private ApplicationEntity application;
|
||||
|
||||
@Inject
|
||||
@AccountPU
|
||||
EntityManager em;
|
||||
|
||||
/**
|
||||
@ -281,21 +279,18 @@ public class AccountControl implements Serializable {
|
||||
return updateLogin(login);
|
||||
}
|
||||
|
||||
|
||||
public AccountLoginEntity updateLogin(AccountLoginEntity login) {
|
||||
return em.merge (login);
|
||||
return em.merge(login);
|
||||
}
|
||||
|
||||
public void updateLogin (AccountEntity account) {
|
||||
public void updateLogin(AccountEntity account) {
|
||||
if (account.getAccountLogin() == null) {
|
||||
// TODO connect to IPRS - how can an account ask for an updated login if the user cannot login
|
||||
} else {
|
||||
updateSuccessFullLogin (account.getAccountLogin(), account.getUsername());
|
||||
updateSuccessFullLogin(account.getAccountLogin(), account.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addLoginError(AccountEntity account) {
|
||||
// TODO reimplement
|
||||
// try {
|
||||
@ -339,7 +334,7 @@ public class AccountControl implements Serializable {
|
||||
return login;
|
||||
}
|
||||
|
||||
public String getHashedPassword (String password) {
|
||||
public String getHashedPassword(String password) {
|
||||
String hashedPassword = SecurityUtil.createPassword(password);
|
||||
return hashedPassword;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package de.muehlencord.shared.account.business.application.boundary;
|
||||
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import de.muehlencord.shared.account.util.AccountPU;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -24,6 +25,7 @@ public class ApplicationService implements Serializable {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationService.class);
|
||||
|
||||
@Inject
|
||||
@AccountPU
|
||||
EntityManager em;
|
||||
|
||||
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.ApplicationPermissionEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import de.muehlencord.shared.account.util.AccountPU;
|
||||
import java.io.Serializable;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
@ -22,7 +23,8 @@ public class ApplicationPermissionControl implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3761100587901739481L;
|
||||
|
||||
@PersistenceContext
|
||||
@Inject
|
||||
@AccountPU
|
||||
EntityManager em;
|
||||
|
||||
public List<ApplicationPermissionEntity> getApplicationPermissions(ApplicationEntity app) {
|
||||
@ -49,7 +51,7 @@ public class ApplicationPermissionControl implements Serializable {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(ApplicationEntity application,String name, String description) {
|
||||
public void create(ApplicationEntity application, String name, String description) {
|
||||
ApplicationPermissionEntity permission = new ApplicationPermissionEntity(application, name, description);
|
||||
em.persist(permission);
|
||||
}
|
||||
|
||||
@ -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.ApplicationRoleEntity;
|
||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||
import de.muehlencord.shared.account.util.AccountPU;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
@ -35,7 +36,8 @@ public class ApplicationRoleControl implements Serializable {
|
||||
@EJB
|
||||
ApplicationPermissionControl applicationPermissionControl;
|
||||
|
||||
@PersistenceContext
|
||||
@Inject
|
||||
@AccountPU
|
||||
EntityManager em;
|
||||
|
||||
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.ConfigEntityPK;
|
||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||
import de.muehlencord.shared.account.util.AccountPU;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -33,6 +34,7 @@ public class ConfigService implements Serializable {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigService.class);
|
||||
|
||||
@Inject
|
||||
@AccountPU
|
||||
EntityManager em;
|
||||
|
||||
@Inject
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
*/
|
||||
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.AccountConfigurationValue;
|
||||
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.MailTemplateException;
|
||||
import de.muehlencord.shared.account.business.mail.entity.MailTemplateEntity;
|
||||
import de.muehlencord.shared.account.util.AccountPU;
|
||||
import freemarker.cache.StringTemplateLoader;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
@ -29,6 +30,7 @@ public class MailTemplateService implements Serializable {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MailTemplateService.class.getName());
|
||||
|
||||
@Inject
|
||||
@AccountPU
|
||||
EntityManager em;
|
||||
|
||||
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"?>
|
||||
<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>
|
||||
<exclude-unlisted-classes>false</exclude-unlisted-classes>
|
||||
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/radius"/>
|
||||
<property name="javax.persistence.jdbc.user" value="jomu"/>
|
||||
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
||||
<property name="javax.persistence.jdbc.password" value="jomu"/>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/>
|
||||
<property name="hibernate.show_sql" value="false"/>
|
||||
<property name="hibernate.cache.use_second_level_cache" value="true"/>
|
||||
<property name="hibernate.cache.use_query_cache" value="true"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
|
||||
Reference in New Issue
Block a user