1 /** 2 * Copyright 2005-2013 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 25 /** 26 * This is the generic data access interface for business objects. This should be used for unit testing purposes only. 27 * 28 * 29 */ 30 public interface BusinessObjectDao { 31 /** 32 * Saves any object that implements the BusinessObject interface. 33 * 34 * @param bo 35 */ 36 public PersistableBusinessObject save(PersistableBusinessObject bo); 37 38 /** 39 * Saves a List of BusinessObjects. 40 * 41 * @param businessObjects 42 */ 43 public List<? extends PersistableBusinessObject> save(List businessObjects); 44 45 /** 46 * Retrieves an object instance identified by its primary key. For composite keys, use {@link #findByPrimaryKey(Class, Map)} 47 * 48 * @param clazz 49 * @param primaryKey 50 * @return 51 */ 52 public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey); 53 54 /** 55 * Retrieves an object instance identified bys it primary keys and values. This can be done by constructing a map where the key 56 * to the map entry is the primary key attribute and the value of the entry being the primary key value. For composite keys, 57 * pass in each primaryKey attribute and its value as a map entry. 58 * 59 * @param clazz 60 * @param primaryKeys 61 * @return 62 */ 63 public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys); 64 65 /** 66 * Retrieves an object, based on its PK object 67 * 68 * @param clazz the class of the object to retrieve 69 * @param pkObject the value of the primary key 70 * @return the retrieved PersistableBusinessObject 71 */ 72 public abstract <T extends BusinessObject> T findByPrimaryKeyUsingKeyObject(Class<T> clazz, Object pkObject); 73 74 /** 75 * Retrieves an object instance identified by the class of the given object and the object's primary key values. 76 * 77 * @param object 78 * @return 79 */ 80 public PersistableBusinessObject retrieve(PersistableBusinessObject object); 81 82 /** 83 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object 84 * instance. This will only retrieve business objects by class type. 85 * 86 * @param clazz 87 * @return 88 */ 89 public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz); 90 91 /** 92 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object 93 * instance. This will only retrieve business objects by class type. 94 * 95 * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active 96 * 97 * @param clazz 98 * @return 99 */ 100 public <T extends BusinessObject> Collection<T> findAllActive(Class<T> clazz); 101 102 public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz); 103 104 /** 105 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object 106 * instance. This will only retrieve business objects by class type. Orders the results by the given field. 107 * 108 * @param clazz 109 * @return 110 */ 111 public <T extends BusinessObject> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending); 112 113 /** 114 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object 115 * instance. This will only retrieve business objects by class type. Orders the results by the given field. 116 * 117 * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active 118 * @param clazz 119 * @return 120 */ 121 public <T extends BusinessObject> Collection<T> findAllActiveOrderBy(Class<T> clazz, String sortField, boolean sortAscending); 122 123 /** 124 * This method retrieves a collection of business objects populated with data, such that each record in the database populates a 125 * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs, 126 * specifically attribute name-expected value. 127 * 128 * @param clazz 129 * @param fieldValues 130 * @return 131 */ 132 public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, ?> fieldValues); 133 134 /** 135 * Finds all entities matching the passed in Rice JPA criteria 136 * 137 * @param <T> the type of the entity that will be returned 138 * @param criteria the criteria to form the query with 139 * @return a Collection (most likely a List) of all matching entities 140 */ 141 //public abstract <T extends BusinessObject> Collection<T> findMatching(Criteria criteria); 142 143 /** 144 * This method retrieves a collection of business objects populated with data, such that each record in the database populates a 145 * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs, 146 * specifically attribute name-expected value. 147 * 148 * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active 149 * 150 * @param clazz 151 * @param fieldValues 152 * @return 153 */ 154 public <T extends BusinessObject> Collection<T> findMatchingActive(Class<T> clazz, Map<String, ?> fieldValues); 155 156 /** 157 * @param clazz 158 * @param fieldValues 159 * @return count of BusinessObjects of the given class whose fields match the values in the given Map. 160 */ 161 public int countMatching(Class clazz, Map<String, ?> fieldValues); 162 163 164 /** 165 * 166 * This method returns the number of matching result given the positive criterias and 167 * negative criterias. The negative criterias are the ones that will be set to 168 * "notEqualTo" or "notIn" 169 * 170 * @param clazz 171 * @param positiveFieldValues Map of fields and values for positive criteria 172 * @param negativeFieldValues Map of fields and values for negative criteria 173 * @return 174 */ 175 public int countMatching(Class clazz, Map<String, ?> positiveFieldValues, Map<String, ?> negativeFieldValues); 176 177 /** 178 * This method retrieves a collection of business objects populated with data, such that each record in the database populates a 179 * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs, 180 * specifically attribute name-expected value. Orders the results by the given field. 181 * 182 * @param clazz 183 * @param fieldValues 184 * @return 185 */ 186 public <T extends BusinessObject> Collection<T> findMatchingOrderBy(Class<T> clazz, Map<String, ?> fieldValues, String sortField, boolean sortAscending); 187 188 /** 189 * Deletes a business object from the database. 190 * 191 * @param bo 192 */ 193 public void delete(PersistableBusinessObject bo); 194 195 /** 196 * Deletes each business object in the given List from the database. 197 * 198 * @param boList 199 */ 200 public void delete(List<? extends PersistableBusinessObject> boList); 201 202 /** 203 * Deletes the business objects matching the given fieldValues 204 * 205 * @param clazz 206 * @param fieldValues 207 */ 208 public void deleteMatching(Class clazz, Map<String, ?> fieldValues); 209 210 /** 211 * Merges the given business object, but tells the ORM that the object is to be treated as Read Only, 212 * and even if it has changes, it will not be persisted to the database 213 * 214 * @param bo the business object to managed 215 * @return the managed copied of the business object 216 */ 217 public PersistableBusinessObject manageReadOnly(PersistableBusinessObject bo); 218 }