View Javadoc

1   /**
2    * Copyright 2005-2011 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.rice.kew.docsearch.dao.impl;
17  
18  import java.math.BigDecimal;
19  import java.sql.Timestamp;
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.List;
23  
24  import org.apache.ojb.broker.query.Criteria;
25  import org.apache.ojb.broker.query.QueryByCriteria;
26  import org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue;
27  import org.kuali.rice.kew.docsearch.SearchableAttributeFloatValue;
28  import org.kuali.rice.kew.docsearch.SearchableAttributeLongValue;
29  import org.kuali.rice.kew.docsearch.SearchableAttributeStringValue;
30  import org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO;
31  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
32  
33  /**
34   * OJB implementation of SearchableAttributeDAO
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   */
39  public class SearchableAttributeDAOOjbImpl extends PersistenceBrokerDaoSupport implements SearchableAttributeDAO {
40  
41  	public static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SearchableAttributeDAOOjbImpl.class);
42  
43  	/**
44  	 * This overridden method queries the SearchableAttributeDateTimeValue persistence class
45  	 *
46  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeDateTimeValuesByKey(java.lang.Long, java.lang.String)
47  	 */
48  	public List<Timestamp> getSearchableAttributeDateTimeValuesByKey(
49  			String documentId, String key) {
50  
51  		List<Timestamp> lRet = null;
52  
53  		Criteria crit = new Criteria();
54  		crit.addEqualTo("documentId", documentId);
55  		crit.addEqualTo("searchableAttributeKey", key);
56  		Collection<SearchableAttributeDateTimeValue> collection = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SearchableAttributeDateTimeValue.class, crit));
57  
58  		if(collection != null && !collection.isEmpty()){
59  			lRet = new ArrayList<Timestamp>();
60  			for(SearchableAttributeDateTimeValue value:collection){
61  				lRet.add(value.getSearchableAttributeValue());
62  			}
63  		}
64  
65  		return lRet;
66  	}
67  
68  	/**
69  	 * This overridden method queries the SearchableAttributeFloatValue persistence class
70  	 *
71  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeFloatValuesByKey(java.lang.Long, java.lang.String)
72  	 */
73  	public List<BigDecimal> getSearchableAttributeFloatValuesByKey(
74  			String documentId, String key) {
75  		List<BigDecimal> lRet = null;
76  
77  		Criteria crit = new Criteria();
78  		crit.addEqualTo("documentId", documentId);
79  		crit.addEqualTo("searchableAttributeKey", key);
80  		Collection<SearchableAttributeFloatValue> collection = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SearchableAttributeFloatValue.class, crit));
81  
82  		if(collection != null && !collection.isEmpty()){
83  			lRet = new ArrayList<BigDecimal>();
84  			for(SearchableAttributeFloatValue value:collection){
85  				lRet.add(value.getSearchableAttributeValue());
86  			}
87  		}
88  
89  		return lRet;
90  	}
91  
92  	/**
93  	 * This overridden method queries the SearchableAttributeStringValue persistence class
94  	 *
95  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeStringValuesByKey(java.lang.Long, java.lang.String)
96  	 */
97  	public List<String> getSearchableAttributeStringValuesByKey(
98  			String documentId, String key) {
99  
100 		List<String> lRet = null;
101 
102 		Criteria crit = new Criteria();
103 		crit.addEqualTo("documentId", documentId);
104 		crit.addEqualTo("searchableAttributeKey", key);
105 		Collection<SearchableAttributeStringValue> collection = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SearchableAttributeStringValue.class, crit));
106 
107 		if(collection != null && !collection.isEmpty()){
108 			lRet = new ArrayList<String>();
109 			for(SearchableAttributeStringValue value:collection){
110 				lRet.add(value.getSearchableAttributeValue());
111 			}
112 		}
113 
114 		return lRet;
115 	}
116 
117 	/**
118 	 * This overridden method queries the SearchableAttributeLongValue persistence class
119 	 *
120 	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeValuesByKey(java.lang.Long, java.lang.String)
121 	 */
122 	public List<Long> getSearchableAttributeLongValuesByKey(String documentId,
123 			String key) {
124 		List<Long> lRet = null;
125 
126 			Criteria crit = new Criteria();
127 			crit.addEqualTo("documentId", documentId);
128 			crit.addEqualTo("searchableAttributeKey", key);
129 			Collection<SearchableAttributeLongValue> collection = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SearchableAttributeLongValue.class, crit));
130 
131 			if(collection != null && !collection.isEmpty()){
132 				lRet = new ArrayList<Long>();
133 				for(SearchableAttributeLongValue value:collection){
134 					lRet.add(value.getSearchableAttributeValue());
135 				}
136 			}
137 
138 			return lRet;
139 	}
140 
141 }