View Javadoc

1   /**
2    * Copyright 2005-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.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.List;
22  
23  import javax.persistence.EntityManager;
24  import javax.persistence.PersistenceContext;
25  import javax.persistence.Query;
26  
27  import org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue;
28  import org.kuali.rice.kew.docsearch.SearchableAttributeFloatValue;
29  import org.kuali.rice.kew.docsearch.SearchableAttributeLongValue;
30  import org.kuali.rice.kew.docsearch.SearchableAttributeStringValue;
31  import org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO;
32  
33  /**
34   * JPA implementation of SearchableAttributeDAO
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   */
39  public class SearchableAttributeDAOJpaImpl implements SearchableAttributeDAO {
40  
41  	@PersistenceContext(unitName = "kew-unit")
42  	private EntityManager entityManager;
43  
44  	/**
45  	 * This overridden method queries the SearchableAttributeDateTimeValue persistence class
46  	 *
47  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeDateTimeValuesByKey(java.lang.Long,
48  	 *      java.lang.String)
49  	 */
50  	public List<Timestamp> getSearchableAttributeDateTimeValuesByKey(
51  			String documentId, String key) {
52  
53  		List<Timestamp> lRet = null;
54  		Query query = entityManager.createNamedQuery("SearchableAttributeDateTimeValue.FindByKey");
55          query.setParameter("documentId", documentId);
56          query.setParameter("searchableAttributeKey", key);
57          List<SearchableAttributeDateTimeValue> results = query.getResultList();
58          if (!results.isEmpty()) {
59          	lRet = new ArrayList<Timestamp>();
60              for (SearchableAttributeDateTimeValue attribute: results) {
61              	lRet.add(attribute.getSearchableAttributeValue());
62              }
63          }
64  		return lRet;
65  	}
66  
67  	/**
68  	 * This overridden method queries the SearchableAttributeFloatValue persistence class
69  	 *
70  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeFloatValuesByKey(java.lang.Long,
71  	 *      java.lang.String)
72  	 */
73  	public List<BigDecimal> getSearchableAttributeFloatValuesByKey(
74  			String documentId, String key) {
75  		List<BigDecimal> lRet = null;
76  		Query query = entityManager.createNamedQuery("SearchableAttributeFloatValue.FindByKey");
77          query.setParameter("documentId", documentId);
78          query.setParameter("searchableAttributeKey", key);
79          List<SearchableAttributeFloatValue> results = query.getResultList();
80          if (!results.isEmpty()) {
81          	lRet = new ArrayList<BigDecimal>();
82              for (SearchableAttributeFloatValue attribute: results) {
83              	lRet.add(attribute.getSearchableAttributeValue());
84              }
85          }
86  		return lRet;
87  	}
88  
89  	/**
90  	 * This overridden method queries the searchableAttributeKey persistence class
91  	 *
92  	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeLongValuesByKey(java.lang.Long,
93  	 *      java.lang.String)
94  	 */
95  	public List<Long> getSearchableAttributeLongValuesByKey(String documentId,
96  			String key) {
97  		List<Long> lRet = null;
98  		Query query = entityManager.createNamedQuery("SearchableAttributeLongValue.FindByKey");
99          query.setParameter("documentId", documentId);
100         query.setParameter("searchableAttributeKey", key);
101         List<SearchableAttributeLongValue> results = query.getResultList();
102         if (!results.isEmpty()) {
103         	lRet = new ArrayList<Long>();
104             for (SearchableAttributeLongValue attribute: results) {
105             	lRet.add(attribute.getSearchableAttributeValue());
106             }
107         }
108 		return lRet;
109 	}
110 
111 	/**
112 	 * This overridden method queries the SearchableAttributeStringValue persistence class
113 	 *
114 	 * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeStringValuesByKey(java.lang.Long,
115 	 *      java.lang.String)
116 	 */
117 	public List<String> getSearchableAttributeStringValuesByKey(
118 			String documentId, String key) {
119 		List<String> lRet = null;
120 		Query query = entityManager.createNamedQuery("SearchableAttributeStringValue.FindByKey");
121         query.setParameter("documentId", documentId);
122         query.setParameter("searchableAttributeKey", key);
123         List<SearchableAttributeStringValue> results = query.getResultList();
124         if (!results.isEmpty()) {
125         	lRet = new ArrayList<String>();
126             for (SearchableAttributeStringValue attribute: results) {
127             	lRet.add(attribute.getSearchableAttributeValue());
128             }
129         }
130 		return lRet;
131 	}
132 
133     public EntityManager getEntityManager() {
134         return this.entityManager;
135     }
136 
137     public void setEntityManager(EntityManager entityManager) {
138         this.entityManager = entityManager;
139     }
140 
141 }