ItEr18S14CUAsignacionRecursosEspecificosAPlanificacion: Added findUniqueByNif method to Woker DAO.

This commit is contained in:
Manuel Rego Casasnovas 2009-07-23 11:28:15 +02:00 committed by Javier Moran Rua
parent 004ce99e6f
commit a7aa2bed5c
2 changed files with 40 additions and 2 deletions

View file

@ -1,12 +1,28 @@
package org.navalplanner.business.resources.daos;
import org.navalplanner.business.common.daos.IGenericDao;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.resources.entities.Worker;
/**
* DAO interface for the <code>Worker</code> entity.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*
*/
public interface IWorkerDao extends IGenericDao<Worker, Long> {}
public interface IWorkerDao extends IGenericDao<Worker, Long> {
/**
* Finds a {@link Worker} with the NIF param that should be unique.
*
* @param nif
* The NIF to search the {@link Worker}
* @return The {@link Worker} with this NIF
* @throws InstanceNotFoundException
* If there're more than one {@link Worker} with this NIF or
* there isn't any {@link Worker} with this NIF
*/
Worker findUniqueByNif(String nif) throws InstanceNotFoundException;
}

View file

@ -1,6 +1,11 @@
package org.navalplanner.business.resources.daos.impl;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.resources.daos.IWorkerDao;
import org.navalplanner.business.resources.entities.Worker;
import org.springframework.beans.factory.config.BeanDefinition;
@ -11,9 +16,26 @@ import org.springframework.stereotype.Repository;
* Hibernate DAO for the <code>Worker</code> entity.
*
* @author Fernando Bellas Permuy <fbellas@udc.es>
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*
*/
@Repository
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class WorkerDaoHibernate extends GenericDaoHibernate<Worker, Long>
implements IWorkerDao {}
implements IWorkerDao {
@Override
public Worker findUniqueByNif(String nif) throws InstanceNotFoundException {
Criteria criteria = getSession().createCriteria(Worker.class);
criteria.add(Restrictions.eq("nif", nif).ignoreCase());
List<Worker> list = criteria.list();
if (list.size() != 1) {
throw new InstanceNotFoundException(nif, Worker.class.getName());
}
return list.get(0);
}
}