/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.csu.sdmx.dao;

import cz.csu.sdmx.web.security.User;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Component;

/**
 *
 * @author themi
 */
@Component
public class UsersDaoImp extends DaoSupportImp<User, String>implements UsersDao{

    public UsersDaoImp() {
        super(User.class);
    }
    
    @Override
    public List<User> getByPersonalNumberLike(String like) {
        String sql = "FROM "+getClassName()+" WHERE PERSONALNUMBER LIKE :search";
        Query q = getCurrentSession().createQuery(sql);
        q.setParameter("search", "%" + like + "%");
        
        return q.list();
    }

    @Override
    public String decodePersonalNumber(String ident) {
        String sql = "SELECT DEKOD(:ident) FROM DUAL";
        SQLQuery q = getCurrentSession().createSQLQuery(sql);
        q.setParameter("ident", ident);
        return (String) q.uniqueResult();
    }
    
    
}
