View Javadoc

1   /**
2    * Copyright 2004-2012 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.hr.location.dao;
17  
18  import java.sql.Date;
19  
20  import org.apache.ojb.broker.query.Criteria;
21  import org.apache.ojb.broker.query.Query;
22  import org.apache.ojb.broker.query.QueryFactory;
23  import org.apache.ojb.broker.query.ReportQueryByCriteria;
24  import org.kuali.hr.location.Location;
25  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26  
27  public class LocationDaoSpringObjImpl extends PlatformAwareDaoBaseOjb implements LocationDao {
28  
29  	@Override
30  	public Location getLocation(String location, Date asOfDate) {
31  		Criteria root = new Criteria();
32  		Criteria effdt = new Criteria();
33  		Criteria timestamp = new Criteria();
34  
35  		effdt.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
36  //		effdt.addEqualToField("org", Criteria.PARENT_QUERY_PREFIX + "org");
37  //		effdt.addEqualToField("chart", Criteria.PARENT_QUERY_PREFIX + "chart");
38  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
39  //		effdt.addEqualTo("active", true);
40  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(Location.class, effdt);
41  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
42  
43  		timestamp.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
44  //		timestamp.addEqualToField("org", Criteria.PARENT_QUERY_PREFIX + "org");
45  //		timestamp.addEqualToField("chart", Criteria.PARENT_QUERY_PREFIX + "chart");
46  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
47  //		timestamp.addEqualTo("active", true);
48  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(Location.class, timestamp);
49  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
50  
51  		root.addEqualTo("location", location);
52  		root.addEqualTo("effectiveDate", effdtSubQuery);
53  		root.addEqualTo("timestamp", timestampSubQuery);
54  //		root.addEqualTo("active", true);
55  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
56  		activeFilter.addEqualTo("active", true);
57  		root.addAndCriteria(activeFilter);
58  
59  		
60  		Query query = QueryFactory.newQuery(Location.class, root);
61  		
62  		Location l = (Location)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
63  		
64  		return l;
65  	}
66  
67  	@Override
68  	public Location getLocation(String hrLocationId) {
69  		Criteria crit = new Criteria();
70  		crit.addEqualTo("hrLocationId", hrLocationId);
71  		
72  		Query query = QueryFactory.newQuery(Location.class, crit);
73  		return (Location)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
74  	}
75  	
76  	@Override
77  	public int getLocationCount(String location) {
78  		Criteria crit = new Criteria();
79  		crit.addEqualTo("location", location);
80  		Query query = QueryFactory.newQuery(Location.class, crit);
81  		return this.getPersistenceBrokerTemplate().getCount(query);
82  	}
83  
84  }