improved account controller

This commit is contained in:
2019-04-03 23:29:25 +02:00
parent eb332461aa
commit 91b967f008
3 changed files with 60 additions and 28 deletions

View File

@ -78,7 +78,7 @@ public abstract class AbstractController<T> {
if (Updateable.class.isAssignableFrom(entity.getClass())) {
Updateable updateable = (Updateable) entity;
applyUpdateableChanges(updateable, true);
}
}
em.persist(entity);
return entity;
}
@ -90,7 +90,7 @@ public abstract class AbstractController<T> {
if (Updateable.class.isAssignableFrom(entity.getClass())) {
Updateable updateable = (Updateable) entity;
applyUpdateableChanges(updateable, false);
}
}
return em.merge(entity);
}
@ -101,6 +101,11 @@ public abstract class AbstractController<T> {
em.remove(attach(entity));
}
@Lock(LockType.READ)
public T find(Object id) {
return em.find(entityClass, id);
}
@Lock(LockType.READ)
public List<T> findAll() {
return findAll(new ArrayList<>());

View File

@ -33,7 +33,11 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import javax.ejb.EJB;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
@ -106,6 +110,8 @@ public class AccountControl implements Serializable {
}
@Lock(LockType.READ)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public AccountEntity getAccountEntity(String userName, boolean loadRoles) {
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("SELECT a FROM AccountEntity a ");