au.org.theark.lims.model.dao.BioPersonDao.java Source code

Java tutorial

Introduction

Here is the source code for au.org.theark.lims.model.dao.BioPersonDao.java

Source

/*******************************************************************************
 * Copyright (c) 2011  University of Western Australia. All rights reserved.
 * 
 * This file is part of The Ark.
 * 
 * The Ark is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * The Ark is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package au.org.theark.lims.model.dao;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import au.org.theark.core.dao.HibernateSessionDao;
import au.org.theark.core.exception.ArkSystemException;
import au.org.theark.core.exception.EntityNotFoundException;
import au.org.theark.core.model.study.entity.Person;

@Repository("bioPersonDao")
public class BioPersonDao extends HibernateSessionDao implements IBioPersonDao {
    public Person getPerson(Long id) throws EntityNotFoundException, ArkSystemException {
        Criteria criteria = getSession().createCriteria(Person.class);
        criteria.add(Restrictions.eq("id", id));

        Person person = (Person) criteria.uniqueResult();
        if (person.getId() == null) {
            throw new EntityNotFoundException("The entity with id" + id.toString() + " cannot be found.");
        }
        return person;
    }
}