View Javadoc
1   /*
2    * Copyright 2005-2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.dataaccess.impl;
17  
18  import java.sql.Date;
19  import java.util.Collection;
20  
21  import org.apache.ojb.broker.query.Criteria;
22  import org.apache.ojb.broker.query.QueryByCriteria;
23  import org.apache.ojb.broker.query.QueryFactory;
24  import org.apache.ojb.broker.query.ReportQueryByCriteria;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.ole.sys.businessobject.UniversityDate;
27  import org.kuali.ole.sys.dataaccess.UniversityDateDao;
28  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29  
30  /**
31   * The OJB implementation of the UniversityDateDao
32   */
33  public class UniversityDateDaoOjb extends PlatformAwareDaoBaseOjb implements UniversityDateDao {
34      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UniversityDateDaoOjb.class);
35  
36      /**
37       * Converts a java.util.Date to a java.sql.Date
38       * 
39       * @param date a java.util.Date to convert
40       * @return a java.sql.Date
41       */
42      protected java.sql.Date convertDate(java.util.Date date) {
43          return new Date(date.getTime());
44      }
45  
46      /**
47       * Returns the last university date for a given fiscal year
48       * 
49       * @param fiscalYear the fiscal year to find the last date for
50       * @return a UniversityDate record for the last day in the given fiscal year, or null if nothing can be found
51       * @see org.kuali.ole.sys.dataaccess.UniversityDateDao#getLastFiscalYearDate(java.lang.Integer)
52       */
53      @Override
54      public UniversityDate getLastFiscalYearDate(Integer fiscalYear) {
55          ReportQueryByCriteria subQuery;
56          Criteria subCrit = new Criteria();
57          Criteria crit = new Criteria();
58  
59          subCrit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, fiscalYear);
60          subQuery = QueryFactory.newReportQuery(UniversityDate.class, subCrit);
61          subQuery.setAttributes(new String[] { "max(univ_dt)" });
62  
63          crit.addGreaterOrEqualThan(OLEPropertyConstants.UNIVERSITY_DATE, subQuery);
64  
65          QueryByCriteria qbc = QueryFactory.newQuery(UniversityDate.class, crit);
66  
67          return (UniversityDate) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
68      }
69  
70      /**
71       * Returns the first university date for a given fiscal year
72       * 
73       * @param fiscalYear the fiscal year to find the first date for
74       * @return a UniversityDate record for the first day of the given fiscal year, or null if nothing can be found
75       * @see org.kuali.ole.sys.dataaccess.UniversityDateDao#getFirstFiscalYearDate(java.lang.Integer)
76       */
77      @Override
78      public UniversityDate getFirstFiscalYearDate(Integer fiscalYear) {
79          ReportQueryByCriteria subQuery;
80          Criteria subCrit = new Criteria();
81          Criteria crit = new Criteria();
82  
83          subCrit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, fiscalYear);
84          subQuery = QueryFactory.newReportQuery(UniversityDate.class, subCrit);
85          subQuery.setAttributes(new String[] { "min(univ_dt)" });
86  
87          crit.addGreaterOrEqualThan(OLEPropertyConstants.UNIVERSITY_DATE, subQuery);
88  
89          QueryByCriteria qbc = QueryFactory.newQuery(UniversityDate.class, crit);
90  
91          return (UniversityDate) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
92      }
93  
94  }