001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.docsearch.dao.impl;
017
018import java.math.BigDecimal;
019import java.sql.Timestamp;
020import java.util.ArrayList;
021import java.util.Collection;
022import java.util.List;
023
024import org.apache.ojb.broker.query.Criteria;
025import org.apache.ojb.broker.query.QueryByCriteria;
026import org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue;
027import org.kuali.rice.kew.docsearch.SearchableAttributeFloatValue;
028import org.kuali.rice.kew.docsearch.SearchableAttributeLongValue;
029import org.kuali.rice.kew.docsearch.SearchableAttributeStringValue;
030import org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO;
031import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
032
033/**
034 * OJB implementation of SearchableAttributeDAO
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 *
038 */
039public class SearchableAttributeDAOOjbImpl extends PersistenceBrokerDaoSupport implements SearchableAttributeDAO {
040
041        public static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SearchableAttributeDAOOjbImpl.class);
042
043        /**
044         * This overridden method queries the SearchableAttributeDateTimeValue persistence class
045         *
046         * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeDateTimeValuesByKey(java.lang.Long, java.lang.String)
047         */
048        public List<Timestamp> getSearchableAttributeDateTimeValuesByKey(
049                        String documentId, String key) {
050
051                List<Timestamp> lRet = null;
052
053                Criteria crit = new Criteria();
054                crit.addEqualTo("documentId", documentId);
055                crit.addEqualTo("searchableAttributeKey", key);
056                Collection<SearchableAttributeDateTimeValue> collection = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SearchableAttributeDateTimeValue.class, crit));
057
058                if(collection != null && !collection.isEmpty()){
059                        lRet = new ArrayList<Timestamp>();
060                        for(SearchableAttributeDateTimeValue value:collection){
061                                lRet.add(value.getSearchableAttributeValue());
062                        }
063                }
064
065                return lRet;
066        }
067
068        /**
069         * This overridden method queries the SearchableAttributeFloatValue persistence class
070         *
071         * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeFloatValuesByKey(java.lang.Long, java.lang.String)
072         */
073        public List<BigDecimal> getSearchableAttributeFloatValuesByKey(
074                        String documentId, String key) {
075                List<BigDecimal> lRet = null;
076
077                Criteria crit = new Criteria();
078                crit.addEqualTo("documentId", documentId);
079                crit.addEqualTo("searchableAttributeKey", key);
080                Collection<SearchableAttributeFloatValue> collection = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SearchableAttributeFloatValue.class, crit));
081
082                if(collection != null && !collection.isEmpty()){
083                        lRet = new ArrayList<BigDecimal>();
084                        for(SearchableAttributeFloatValue value:collection){
085                                lRet.add(value.getSearchableAttributeValue());
086                        }
087                }
088
089                return lRet;
090        }
091
092        /**
093         * This overridden method queries the SearchableAttributeStringValue persistence class
094         *
095         * @see org.kuali.rice.kew.docsearch.dao.SearchableAttributeDAO#getSearchableAttributeStringValuesByKey(java.lang.Long, java.lang.String)
096         */
097        public List<String> getSearchableAttributeStringValuesByKey(
098                        String documentId, String key) {
099
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}