com.evasion.plugin.account.AccountManager Maven / Gradle / Ivy
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.evasion.plugin.account;
import com.evasion.entity.Account;
import com.evasion.exception.PersistenceViolationException;
import com.evasion.plugin.account.dao.AccountDAOImpl;
import com.evasion.plugin.person.PersonEJB;
import com.evasion.plugin.security.UserAuthService;
import java.util.List;
import javax.persistence.EntityManager;
/**
*
* @author sebastien.glon
*/
public class AccountManager {
private EntityManager em;
private final AccountDAOImpl accountDAO;
public AccountManager(EntityManager em) {
accountDAO = new AccountDAOImpl();
accountDAO.setEntityManager(em);
this.em = em;
}
public Account createAccount(Account account) throws PersistenceViolationException {
(new UserAuthService(em)).createUser(account.getUser());
(new PersonEJB(em)).createPerson(account.getPerson());
try {
em.persist(account);
em.flush();
} catch (Exception e) {
throw new PersistenceViolationException("Erreur dans la validation du compte utilisateur", e.fillInStackTrace());
}
return account;
}
public void deleteAccount(Account u) {
throw new UnsupportedOperationException("Not supported yet.");
}
public Account updateAccount(Account u) {
throw new UnsupportedOperationException("Not supported yet.");
}
public List listAllAccount() {
return accountDAO.findAll();
}
}