migrated persisteance context to CDI injections

This commit is contained in:
jomu
2017-06-12 17:08:38 +00:00
parent c36b88ca1c
commit d90284d28c
4 changed files with 20 additions and 12 deletions

View File

@ -5,8 +5,8 @@ import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
@ -18,7 +18,7 @@ public class ConfigService implements Serializable {
private static final long serialVersionUID = -3195224653632853003L;
@PersistenceContext
@Inject
EntityManager em;
private String storagePath = null;

View File

@ -6,14 +6,15 @@ import de.muehlencord.shared.account.business.mail.MailService;
import de.muehlencord.shared.account.entity.AccountEntity;
import de.muehlencord.shared.account.entity.ApplicationRoleEntity;
import de.muehlencord.shared.account.util.SecurityUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.Transactional;
import org.apache.commons.lang3.RandomStringUtils;
@ -27,9 +28,10 @@ import org.apache.shiro.subject.Subject;
* @author joern.muehlencord
*/
@Stateless
public class AccountControl {
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;
@ -37,7 +39,7 @@ public class AccountControl {
@EJB
private MailService mailService;
@PersistenceContext
@Inject
EntityManager em;
public List<AccountEntity> getAccounts() {

View File

@ -20,13 +20,16 @@ import javax.mail.internet.MimeMultipart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.muehlencord.shared.account.configuration.AccountConfigurationValue;
import java.io.Serializable;
/**
*
* @author joern.muehlencord
*/
@Stateless
public class MailService {
public class MailService implements Serializable {
private static final long serialVersionUID = -1937218474908356747L;
private static final Logger LOGGER = LoggerFactory.getLogger(MailService.class);

View File

@ -5,11 +5,12 @@ import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
import java.io.Serializable;
import java.io.StringWriter;
import java.io.Writer;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -19,11 +20,13 @@ import org.slf4j.LoggerFactory;
* @author jomu
*/
@Stateless
public class MailTemplateService {
public class MailTemplateService implements Serializable {
private static final long serialVersionUID = -136113381443058697L;
private static final Logger LOGGER = LoggerFactory.getLogger(MailTemplateService.class.getName());
@PersistenceContext
@Inject
EntityManager em;
public String getStringFromTemplate(String templateName, MailDatamodel dataModel) throws MailTemplateException {
@ -32,7 +35,7 @@ public class MailTemplateService {
query.setParameter("templateName", templateName);
MailTemplateEntity templateEntity = (MailTemplateEntity) query.getSingleResult();
if (templateEntity == null) {
LOGGER.error( "Tempate with name " + templateName + " not found");
LOGGER.error("Tempate with name " + templateName + " not found");
return null;
}
@ -52,9 +55,9 @@ public class MailTemplateService {
return templateString;
} catch (Exception ex) {
String hint = "Error while processing template with name " + templateName + ".";
LOGGER.error( hint + " " + ex.toString());
LOGGER.error(hint + " " + ex.toString());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug( hint, ex);
LOGGER.debug(hint, ex);
}
throw new MailTemplateException(hint, ex);