mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
36 lines
831 B
Java
36 lines
831 B
Java
package com.imprimelibros.erp.users;
|
|
|
|
import jakarta.persistence.EntityManager;
|
|
import jakarta.persistence.TypedQuery;
|
|
|
|
import java.util.Optional;
|
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
@Repository
|
|
public class RoleDaoImpl implements RoleDao {
|
|
|
|
private EntityManager entityManager;
|
|
|
|
public RoleDaoImpl(EntityManager theEntityManager) {
|
|
entityManager = theEntityManager;
|
|
}
|
|
|
|
@Override
|
|
public Optional<Role> findRoleByName(String theRoleName) {
|
|
|
|
// retrieve/read from database using name
|
|
TypedQuery<Role> theQuery = entityManager.createQuery("from Role where name=:roleName", Role.class);
|
|
theQuery.setParameter("roleName", theRoleName);
|
|
|
|
Role theRole = null;
|
|
|
|
try {
|
|
theRole = theQuery.getSingleResult();
|
|
} catch (Exception e) {
|
|
theRole = null;
|
|
}
|
|
return Optional.ofNullable(theRole);
|
|
}
|
|
}
|