View Javadoc
1   package fr.ifremer.quadrige2.core.dao.administration.strategy;
2   
3   /*-
4    * #%L
5    * Quadrige2 Core :: Quadrige2 Server Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  import fr.ifremer.quadrige2.core.vo.administration.strategy.AppliedPeriodVO;
26  import org.hibernate.SessionFactory;
27  import org.springframework.beans.factory.annotation.Autowired;
28  import org.springframework.context.annotation.Lazy;
29  import org.springframework.stereotype.Repository;
30  
31  /**
32   * <p>
33   * AppliedPeriodDaoImpl class.
34   * </p>
35   * 
36   * @see AppliedPeriod
37   */
38  @Repository("appliedPeriodDao")
39  @Lazy
40  public class AppliedPeriodDaoImpl
41  		extends AppliedPeriodDaoBase
42  {
43  	/**
44  	 * Constructor used by Spring
45  	 * 
46  	 * @param sessionFactory
47  	 *            a {@link org.hibernate.SessionFactory} object.
48  	 */
49  	@Autowired
50  	public AppliedPeriodDaoImpl(SessionFactory sessionFactory) {
51  		super();
52  		setSessionFactory(sessionFactory);
53  	}
54  
55  	/** {@inheritDoc} */
56  	public void toAppliedPeriodVO(
57  			AppliedPeriod source,
58  			AppliedPeriodVO target)
59  	{
60  		super.toAppliedPeriodVO(source, target);
61  
62  		AppliedPeriodPK pk = source.getAppliedPeriodPk();
63  		if (pk != null) {
64  			target.setAppliedPeriodStartDt(pk.getAppliedPeriodStartDt());
65  			target.setAppliedStratId(pk.getAppliedStrategy().getAppliedStratId());
66  		}
67  
68  	}
69  
70  	/**
71  	 * Retrieves the entity object that is associated with the specified value object
72  	 * from the object store. If no such entity object exists in the object store,
73  	 * a new, blank entity is created
74  	 */
75  	private AppliedPeriod loadAppliedPeriodFromAppliedPeriodVO(AppliedPeriodVO source)
76  	{
77  		AppliedPeriodPK pk = new AppliedPeriodPK();
78  		pk.setAppliedPeriodStartDt(source.getAppliedPeriodStartDt());
79  		pk.setAppliedStrategy(load(AppliedStrategyImpl.class, source.getAppliedStratId()));
80  
81  		AppliedPeriod appliedPeriod = this.get(pk);
82  		if (appliedPeriod == null)
83  		{
84  			appliedPeriod = AppliedPeriod.Factory.newInstance();
85  			appliedPeriod.setAppliedPeriodPk(pk);
86  		}
87  		return appliedPeriod;
88  	}
89  
90  	/** {@inheritDoc} */
91  	public AppliedPeriod appliedPeriodVOToEntity(AppliedPeriodVO appliedPeriodVO)
92  	{
93  		AppliedPeriod entity = this.loadAppliedPeriodFromAppliedPeriodVO(appliedPeriodVO);
94  		this.appliedPeriodVOToEntity(appliedPeriodVO, entity, true);
95  		return entity;
96  	}
97  }