All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.robe.admin.hibernate.dao.RoleDao Maven / Gradle / Ivy

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.admin.hibernate.dao;

import com.google.common.base.Optional;
import io.robe.admin.hibernate.entity.Role;
import io.robe.auth.data.entry.RoleEntry;
import io.robe.auth.data.store.RoleStore;
import io.robe.hibernate.dao.BaseDao;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

import javax.inject.Inject;

public class RoleDao extends BaseDao implements RoleStore {

    @Inject
    public RoleDao(SessionFactory sessionFactory) {
        super(sessionFactory);
    }


    public Optional findByRoleId(String oid) {
        return Optional.fromNullable(findById(oid));
    }

    public Optional findByName(String code) {
        Criteria criteria = currentSession().createCriteria(Role.class);
        criteria.add(Restrictions.eq("code", code));
        return Optional.fromNullable(uniqueResult(criteria));
    }

    public Optional findByNameAndNotEqualMe(String code, String oid) {
        Criteria criteria = currentSession().createCriteria(Role.class);
        criteria.add(Restrictions.eq("code", code));
        criteria.add(Restrictions.not(Restrictions.eq("oid", oid)));

        return Optional.fromNullable(uniqueResult(criteria));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy