Package dao.jpa

Source Code of dao.jpa.UserRoleJpaDao

package dao.jpa;

import dao.DataAccessException;
import dao.UserRoleDao;
import models.entities.UserRole;
import play.Logger;
import play.db.jpa.JPA;

import javax.persistence.TypedQuery;

/**
* Created by kiryl on 17.08.2014.
*/
public class UserRoleJpaDao extends BaseJpaDao<UserRole, Integer> implements UserRoleDao {
    @Override
    public UserRole findByName(String roleName) throws DataAccessException {
        if (roleName == null) {
            return null;
        }
        try {
            TypedQuery<UserRole> query = JPA.em().createQuery("SELECT r FROM UserRole r WHERE r.name = :roleName", UserRole.class);
            query.setParameter("roleName", roleName);
            return query.getSingleResult();
        } catch (Throwable throwable) {
            Logger.error("Failed to get role by name: " + roleName);
            throw new DataAccessException("Failed to get role by name: " + roleName, throwable);
        }
    }
}
TOP

Related Classes of dao.jpa.UserRoleJpaDao

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.