View Javadoc
1   // license-header java merge-point
2   /**
3    * This is only generated once! It will never be overwritten.
4    * You can (and have to!) safely modify it by hand.
5    */
6   package org.andromda.timetracker.domain;
7   
8   import java.util.List;
9   import org.andromda.timetracker.vo.TimecardSearchCriteriaVO;
10  import org.andromda.timetracker.vo.TimecardSummaryVO;
11  import org.apache.commons.logging.Log;
12  import org.apache.commons.logging.LogFactory;
13  import org.hibernate.Criteria;
14  import org.hibernate.FetchMode;
15  import org.hibernate.criterion.Restrictions;
16  
17  /**
18   * @see Timecard
19   */
20  public class TimecardDaoImpl
21      extends TimecardDaoBase
22  {
23      private Log logger = LogFactory.getLog(TimecardDaoImpl.class);
24  
25      /**
26       * @see TimecardDao#findByCriteria(TimecardSearchCriteriaVO)
27       */
28      @Override
29      protected List handleFindByCriteria(TimecardSearchCriteriaVO criteria)
30      {
31          // Create the timecard criteria
32          Criteria timecardCriteria = this.hibernateSession.createCriteria(Timecard.class);
33          timecardCriteria.setFetchMode("submitter", FetchMode.JOIN);
34          timecardCriteria.setFetchMode("approver", FetchMode.JOIN);
35  
36          // Add submitter criteria
37          if (criteria.getSubmitterId() != null)
38          {
39              timecardCriteria.createCriteria("submitter").add(Restrictions.idEq(criteria.getSubmitterId()));
40          }
41  
42          // Add approver criteria
43          if (criteria.getApproverId() != null)
44          {
45              timecardCriteria.createCriteria("approver").add(Restrictions.idEq(criteria.getApproverId()));
46          }
47  
48          // Add status criteria
49          if (criteria.getStatus() != null)
50          {
51              timecardCriteria.add(Restrictions.eq("status", criteria.getStatus()));
52          }
53  
54          // Add startDateMin criteria
55          if (criteria.getStartDateMin() != null)
56          {
57              timecardCriteria.add(Restrictions.ge("startDate", criteria.getStartDateMin()));
58          }
59  
60          // Add startDateMax criteria
61          if (criteria.getStartDateMax() != null)
62          {
63              timecardCriteria.add(Restrictions.le("startDate", criteria.getStartDateMax()));
64          }
65  
66          List timecards = timecardCriteria.list();
67          if (this.logger.isDebugEnabled())
68          {
69              this.logger.debug(timecards.size() + " timecards found");
70          }
71          return timecards;
72      }
73  
74      /**
75       * @see TimecardDao#toTimecardSummaryVO(Timecard, TimecardSummaryVO)
76       */
77      @Override
78      public void toTimecardSummaryVO(
79          Timecard sourceEntity,
80          TimecardSummaryVO targetVO)
81      {
82          // TODO verify behavior of toTimecardSummaryVO
83          super.toTimecardSummaryVO(sourceEntity, targetVO);
84  
85          // add the related entities
86          targetVO.setSubmitterName(sourceEntity.getSubmitter().getUsername());
87          if (sourceEntity.getApprover() != null)
88          {
89              targetVO.setApproverName(sourceEntity.getApprover().getUsername());
90          }
91      }
92  
93      /**
94       * @see TimecardDao#toTimecardSummaryVO(Timecard)
95       */
96      @Override
97      public TimecardSummaryVO toTimecardSummaryVO(final Timecard entity)
98      {
99          // TODO verify behavior of toTimecardSummaryVO
100         return super.toTimecardSummaryVO(entity);
101     }
102 
103     /**
104      * Retrieves the entity object that is associated with the specified value object
105      * from the object store. If no such entity object exists in the object store,
106      * a new, blank entity is created
107      */
108     @SuppressWarnings("static-method")
109     private Timecard loadTimecardFromTimecardSummaryVO(TimecardSummaryVO timecardSummaryVO)
110     {
111         // TODO implement loadTimecardFromTimecardSummaryVO
112         throw new java.lang.UnsupportedOperationException("loadTimecardFromTimecardSummaryVO(TimecardSummaryVO) not yet implemented.");
113 
114         /* A typical implementation looks like this:
115         Timecard timecard = this.load(timecardSummaryVO.getId());
116         if (timecard == null)
117         {
118             timecard = Timecard.Factory.newInstance();
119         }
120         return timecard;
121         */
122     }
123 
124     /**
125      * @see TimecardDao#timecardSummaryVOToEntity(TimecardSummaryVO)
126      */
127     @Override
128     public Timecard timecardSummaryVOToEntity(TimecardSummaryVO timecardSummaryVO)
129     {
130         // TODO verify behavior of timecardSummaryVOToEntity
131         Timecard entity = this.loadTimecardFromTimecardSummaryVO(timecardSummaryVO);
132         this.timecardSummaryVOToEntity(timecardSummaryVO, entity, true);
133         return entity;
134     }
135 
136     /**
137      * @see TimecardDao#timecardSummaryVOToEntity(TimecardSummaryVO, Timecard, boolean)
138      */
139     @Override
140     public void timecardSummaryVOToEntity(
141         TimecardSummaryVO sourceVO,
142         Timecard targetEntity,
143         boolean copyIfNull)
144     {
145         // TODO verify behavior of timecardSummaryVOToEntity
146         super.timecardSummaryVOToEntity(sourceVO, targetEntity, copyIfNull);
147     }
148 }