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.krad.dao;
017
018import java.util.Collection;
019import java.util.List;
020import java.util.Map;
021
022import org.kuali.rice.krad.bo.BusinessObject;
023import org.kuali.rice.krad.bo.PersistableBusinessObject;
024import org.kuali.rice.krad.util.LegacyDataFramework;
025
026/**
027 * This is the generic data access interface for business objects. This should be used for unit testing purposes only.
028 * @deprecated use new KRAD Data framework {@link org.kuali.rice.krad.data.DataObjectService}
029 */
030@Deprecated
031@LegacyDataFramework
032public interface BusinessObjectDao {
033    /**
034     * Saves any object that implements the BusinessObject interface.
035     * 
036     * @param bo
037     */
038    public PersistableBusinessObject save(PersistableBusinessObject bo);
039
040    /**
041     * Saves a List of BusinessObjects.
042     * 
043     * @param businessObjects
044     */
045    public List<? extends PersistableBusinessObject> save(List businessObjects);
046
047    /**
048     * Retrieves an object instance identified by its primary key. For composite keys, use {@link #findByPrimaryKey(Class, Map)}
049     * 
050     * @param clazz
051     * @param primaryKey
052     * @return
053     */
054    public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey);
055    
056    /**
057     * Retrieves an object instance identified bys it primary keys and values. This can be done by constructing a map where the key
058     * to the map entry is the primary key attribute and the value of the entry being the primary key value. For composite keys,
059     * pass in each primaryKey attribute and its value as a map entry.
060     * 
061     * @param clazz
062     * @param primaryKeys
063     * @return
064     */
065    public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys);
066    
067    /**
068         * Retrieves an object, based on its PK object
069         * 
070         * @param clazz the class of the object to retrieve
071         * @param pkObject the value of the primary key
072         * @return the retrieved PersistableBusinessObject
073         */
074        public abstract <T  extends BusinessObject> T findByPrimaryKeyUsingKeyObject(Class<T> clazz, Object pkObject);
075
076    /**
077     * Retrieves an object instance identified by the class of the given object and the object's primary key values.
078     * 
079     * @param object
080     * @return
081     */
082    public Object retrieve(Object object);
083
084    /**
085     * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
086     * instance. This will only retrieve business objects by class type.
087     * 
088     * @param clazz
089     * @return
090     */
091    public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz);
092    
093    /**
094     * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
095     * instance. This will only retrieve business objects by class type.
096     * 
097     * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active
098     * 
099     * @param clazz
100     * @return
101     */
102    public <T extends BusinessObject> Collection<T> findAllActive(Class<T> clazz);
103
104    public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz);
105    
106    /**
107     * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
108     * instance. This will only retrieve business objects by class type. Orders the results by the given field.
109     * 
110     * @param clazz
111     * @return
112     */
113    public <T extends BusinessObject> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending);
114    
115    /**
116     * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
117     * instance. This will only retrieve business objects by class type. Orders the results by the given field.
118     * 
119     * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active
120     * @param clazz
121     * @return
122     */
123    public <T extends BusinessObject> Collection<T> findAllActiveOrderBy(Class<T> clazz, String sortField, boolean sortAscending);
124
125    /**
126     * This method retrieves a collection of business objects populated with data, such that each record in the database populates a
127     * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs,
128     * specifically attribute name-expected value.
129     * 
130     * @param clazz
131     * @param fieldValues
132     * @return
133     */
134    public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, ?> fieldValues);
135    
136    /**
137     * Finds all entities matching the passed in Rice JPA criteria
138     * 
139     * @param <T> the type of the entity that will be returned
140     * @param criteria the criteria to form the query with
141     * @return a Collection (most likely a List) of all matching entities 
142     */
143    //public abstract <T extends BusinessObject> Collection<T> findMatching(Criteria criteria);
144    
145    /**
146     * This method retrieves a collection of business objects populated with data, such that each record in the database populates a
147     * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs,
148     * specifically attribute name-expected value.
149     * 
150     * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active
151     * 
152     * @param clazz
153     * @param fieldValues
154     * @return
155     */
156    public <T extends BusinessObject> Collection<T> findMatchingActive(Class<T> clazz, Map<String, ?> fieldValues);
157
158    /**
159     * @param clazz
160     * @param fieldValues
161     * @return count of BusinessObjects of the given class whose fields match the values in the given Map.
162     */
163    public int countMatching(Class clazz, Map<String, ?> fieldValues);
164
165    
166    /**
167     * 
168     * This method returns the number of matching result given the positive criterias and
169     * negative criterias. The negative criterias are the ones that will be set to 
170     * "notEqualTo" or "notIn"
171     * 
172     * @param clazz
173     * @param positiveFieldValues  Map of fields and values for positive criteria
174     * @param negativeFieldValues  Map of fields and values for negative criteria
175     * @return
176     */
177    public int countMatching(Class clazz, Map<String, ?> positiveFieldValues, Map<String, ?> negativeFieldValues);
178    
179    /**
180     * This method retrieves a collection of business objects populated with data, such that each record in the database populates a
181     * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs,
182     * specifically attribute name-expected value. Orders the results by the given field.
183     * 
184     * @param clazz
185     * @param fieldValues
186     * @return
187     */
188    public <T extends BusinessObject> Collection<T> findMatchingOrderBy(Class<T> clazz, Map<String, ?> fieldValues, String sortField, boolean sortAscending);
189
190    /**
191     * Deletes a business object from the database.
192     * 
193     * @param bo
194     */
195    public void delete(Object bo);
196
197    /**
198     * Deletes each business object in the given List from the database.
199     * 
200     * @param boList
201     */
202    public void delete(List<? extends PersistableBusinessObject> boList);
203
204    /**
205     * Deletes the business objects matching the given fieldValues
206     * 
207     * @param clazz
208     * @param fieldValues
209     */
210    public void deleteMatching(Class clazz, Map<String, ?> fieldValues);
211    
212    /**
213     * Merges the given business object, but tells the ORM that the object is to be treated as Read Only,
214     * and even if it has changes, it will not be persisted to the database 
215     * 
216     * @param bo the business object to managed
217     * @return the managed copied of the business object
218     */
219    public PersistableBusinessObject manageReadOnly(PersistableBusinessObject bo);
220}