001// Generated by: hibernate/SpringHibernateDaoImpl.vsl in andromda-spring-cartridge.
002// license-header java merge-point
003//
004// Attention: Generated code! Do not modify by hand!
005// Generated by: SpringHibernateDaoImpl.vsl in andromda-spring-cartridge.
006//
007package fr.ifremer.adagio.core.dao.administration.user;
008
009/*
010 * #%L
011 * SIH-Adagio :: Core
012 * $Id:$
013 * $HeadURL:$
014 * %%
015 * Copyright (C) 2012 - 2014 Ifremer
016 * %%
017 * This program is free software: you can redistribute it and/or modify
018 * it under the terms of the GNU Affero General Public License as published by
019 * the Free Software Foundation, either version 3 of the License, or
020 * (at your option) any later version.
021 * 
022 * This program is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025 * GNU General Public License for more details.
026 * 
027 * You should have received a copy of the GNU Affero General Public License
028 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
029 * #L%
030 */
031
032import java.math.BigDecimal;
033import java.util.List;
034
035import org.hibernate.Query;
036import org.hibernate.SessionFactory;
037import org.hibernate.type.IntegerType;
038import org.springframework.beans.factory.annotation.Autowired;
039import org.springframework.context.annotation.Lazy;
040import org.springframework.stereotype.Repository;
041
042/**
043 * @see fr.ifremer.adagio.core.dao.administration.user.PersonSession
044 */
045@Repository("personSessionDao")
046@Lazy
047public class PersonSessionDaoImpl
048        extends PersonSessionDaoBase
049        implements PersonSessionExtendDao
050{
051
052    @Autowired
053    private PersonDao personDao;
054
055    /**
056     * Constructor used by Spring
057     */
058    @Autowired
059    public PersonSessionDaoImpl(SessionFactory sessionFactory) {
060        super();
061        setSessionFactory(sessionFactory);
062    }
063
064    @Override
065    public Integer initPersonSession(int personId) {
066        Person person = get(PersonImpl.class, personId);
067        if (person == null) {
068            return null;
069        }
070        Query query = createQuery("fillPersonSession",
071                "personId", IntegerType.INSTANCE, personId);
072        List<?> results = query.list();
073        Integer sessionId = null;
074        if (results != null && !results.isEmpty()) {
075            sessionId = ((BigDecimal) results.get(0)).intValue();
076        }
077        return sessionId;
078    }
079}