1 /** 2 * Copyright 2005-2014 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.krad.dao; 17 18 import java.util.Collection; 19 import java.util.List; 20 import java.util.Map; 21 22 import org.kuali.rice.krad.bo.BusinessObject; 23 import org.kuali.rice.krad.bo.PersistableBusinessObject; 24 import org.kuali.rice.krad.util.LegacyDataFramework; 25 26 /** 27 * This is the generic data access interface for business objects. This should be used for unit testing purposes only. 28 * @deprecated use new KRAD Data framework {@link org.kuali.rice.krad.data.DataObjectService} 29 */ 30 @Deprecated 31 @LegacyDataFramework 32 public interface BusinessObjectDao { 33 /** 34 * Saves any object that implements the BusinessObject interface. 35 * 36 * @param bo 37 */ 38 public PersistableBusinessObject save(PersistableBusinessObject bo); 39 40 /** 41 * Saves a List of BusinessObjects. 42 * 43 * @param businessObjects 44 */ 45 public List<? extends PersistableBusinessObject> save(List businessObjects); 46 47 /** 48 * Retrieves an object instance identified by its primary key. For composite keys, use {@link #findByPrimaryKey(Class, Map)} 49 * 50 * @param clazz 51 * @param primaryKey 52 * @return 53 */ 54 public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey); 55 56 /** 57 * Retrieves an object instance identified bys it primary keys and values. This can be done by constructing a map where the key 58 * to the map entry is the primary key attribute and the value of the entry being the primary key value. For composite keys, 59 * pass in each primaryKey attribute and its value as a map entry. 60 * 61 * @param clazz 62 * @param primaryKeys 63 * @return 64 */ 65 public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys); 66 67 /** 68 * Retrieves an object, based on its PK object 69 * 70 * @param clazz the class of the object to retrieve 71 * @param pkObject the value of the primary key 72 * @return the retrieved PersistableBusinessObject 73 */ 74 public abstract <T extends BusinessObject> T findByPrimaryKeyUsingKeyObject(Class<T> clazz, Object pkObject); 75 76 /** 77 * Retrieves an object instance identified by the class of the given object and the object's primary key values. 78 * 79 * @param object 80 * @return 81 */ 82 public PersistableBusinessObject retrieve(PersistableBusinessObject object); 83 84 /** 85 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object 86 * instance. This will only retrieve business objects by class type. 87 * 88 * @param clazz 89 * @return 90 */ 91 public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz); 92 93 /** 94 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object 95 * instance. This will only retrieve business objects by class type. 96 * 97 * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active 98 * 99 * @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(PersistableBusinessObject 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 }