Example usage for org.hibernate Criteria uniqueResult

List of usage examples for org.hibernate Criteria uniqueResult

Introduction

In this page you can find the example usage for org.hibernate Criteria uniqueResult.

Prototype

public Object uniqueResult() throws HibernateException;

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public long getArkModuleFunctionCount(ArkModuleFunction arkModuleFunctionCriteria) {
    Criteria criteria = buildArkModuleFunctionCriteria(arkModuleFunctionCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public ArkModuleFunction getArkModuleFunction(Long id) {
    Criteria criteria = getSession().createCriteria(ArkModuleFunction.class);
    criteria.add(Restrictions.eq("id", id));
    return (ArkModuleFunction) criteria.uniqueResult();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public ArkRole getArkRole(Long id) {
    Criteria criteria = getSession().createCriteria(ArkRole.class);
    criteria.add(Restrictions.eq("id", id));
    return (ArkRole) criteria.uniqueResult();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public long getArkRoleCount(ArkRole arkRoleCriteria) {
    Criteria criteria = buildArkRoleCriteria(arkRoleCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public long getArkModuleRoleCount(ArkModuleRole arkModuleRoleCriteria) {
    Criteria criteria = buildArkModuleRoleCriteria(arkModuleRoleCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public ArkModuleRole getArkModuleRole(Long id) {
    Criteria criteria = getSession().createCriteria(ArkModuleRole.class);
    criteria.add(Restrictions.eq("id", id));
    return (ArkModuleRole) criteria.uniqueResult();
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

/**
 * Looks up a ArkUser based on a String that represents the user name in LDAP. If the user name provided is null or is invalid/does not exist in
 * the database, the method will return NULL for a ArkUser instance.
 * //from  ww  w  . j  a  v a2 s .  c  o  m
 * @param ldapUserName
 * @return ArkUser
 */
public ArkUser getArkUser(String ldapUserName) throws EntityNotFoundException {
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(ArkUser.class);
    criteria.add(Restrictions.eq("ldapUserName", ldapUserName));
    ArkUser arkUser = (ArkUser) criteria.uniqueResult();
    // Close the session
    session.close();
    if (arkUser != null) {
        return arkUser;
    } else {
        throw new EntityNotFoundException("The given Ldap User does not exist in the database system");
    }
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

/**
 * Overloaded method to lookup an ArkUser by username and study
 * /*from  ww w .  jav a  2s. co m*/
 * @param ldapUserName
 * @param study
 * @return
 * @throws EntityNotFoundException
 */
public ArkUser getArkUser(String ldapUserName, Study study) throws EntityNotFoundException {
    StatelessSession session = getStatelessSession();
    Criteria criteria = session.createCriteria(ArkUser.class);
    criteria.add(Restrictions.eq("ldapUserName", ldapUserName));
    criteria.add(Restrictions.eq("study", study));
    ArkUser arkUser = (ArkUser) criteria.uniqueResult();
    // Close the session
    session.close();
    if (arkUser != null) {
        return arkUser;
    } else {
        throw new EntityNotFoundException("The given Ldap User does not exist in the database system");
    }
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

/**
 * <p>//from www  .  j  a  v a2 s  . c  om
 * Given a String Role name like Super Administrator or Administrator the method will return the actual instance of ArkRole object.
 * </p>
 * 
 * @param roleName
 * @return ArkRole
 */
public ArkRole getArkRoleByName(String roleName) {
    Criteria criteria = getSession().createCriteria(ArkRole.class);
    criteria.add(Restrictions.eq("name", roleName));
    ArkRole arkRole = (ArkRole) criteria.uniqueResult();
    return arkRole;
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

public boolean isUserAdminHelper(String ldapUserName, String roleName) throws EntityNotFoundException {
    boolean isAdminType = false;
    StatelessSession session = getStatelessSession();
    // Check or get user ark_user object based on ldapUserName
    ArkUser arkUser = getArkUser(ldapUserName);
    Criteria criteria = session.createCriteria(ArkUserRole.class);
    ArkRole arkRole = getArkRoleByName(roleName);
    criteria.add(Restrictions.eq("arkRole", arkRole));
    criteria.add(Restrictions.eq("arkUser", arkUser));
    criteria.setMaxResults(1);// w w w  . ja v  a  2  s.c  o  m
    ArkUserRole arkUserRole = (ArkUserRole) criteria.uniqueResult();
    if (arkUserRole != null) {
        isAdminType = true;
    }
    session.close();
    return isAdminType;
}