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

io.robe.admin.hibernate.dao.UserDao 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.User;
import io.robe.auth.data.entry.UserEntry;
import io.robe.auth.data.store.UserStore;
import io.robe.hibernate.dao.BaseDao;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

import javax.inject.Inject;
import java.util.List;

public class UserDao extends BaseDao implements UserStore {

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

    public Optional findByUsername(String username) {
        Criteria criteria = currentSession().createCriteria(User.class);
        criteria.add(Restrictions.eq("email", username));
        return Optional.fromNullable(uniqueResult(criteria));
    }

    public List findByRoleId(String roleId) {
        Criteria criteria = currentSession().createCriteria(User.class);
        criteria.add(Restrictions.eq("roleOid", roleId));
        return criteria.list();
    }

    @Override
    public Optional changePassword(String username, String newPassword) {
        Optional user = findByUsername(username);
        if (user.isPresent()) {
            user.get().setPassword(newPassword);
            persist(user.get());
        }
        return user;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy