| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GenericDao |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2006-2011 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 | ||
| 17 | package org.kuali.rice.core.framework.persistence.dao; | |
| 18 | ||
| 19 | import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; | |
| 20 | ||
| 21 | import java.util.Collection; | |
| 22 | import java.util.List; | |
| 23 | import java.util.Map; | |
| 24 | ||
| 25 | /** | |
| 26 | * This is the generic data access interface for business objects. | |
| 27 | * This class was adapted from the Kuali Nervous System | |
| 28 | * (org.kuali.rice.krad.dao.BusinessObjectDao). | |
| 29 | * It's not as generic as it could be as it relies on the OJB criteria object... | |
| 30 | * | |
| 31 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 32 | */ | |
| 33 | public interface GenericDao { | |
| 34 | /** | |
| 35 | * Saves any object | |
| 36 | * | |
| 37 | * @param bo | |
| 38 | */ | |
| 39 | public void save(Object bo); | |
| 40 | ||
| 41 | /** | |
| 42 | * Saves a List of objects | |
| 43 | * | |
| 44 | * @param businessObjects | |
| 45 | */ | |
| 46 | public void save(List businessObjects); | |
| 47 | ||
| 48 | /** | |
| 49 | * Retrieves an object instance identified bys it primary key. | |
| 50 | * | |
| 51 | * @param clazz the class | |
| 52 | * @param id the primary key value | |
| 53 | * @return Object | |
| 54 | */ | |
| 55 | public Object findById(Class clazz, Object keyValue); | |
| 56 | ||
| 57 | /** | |
| 58 | * Retrieves an object instance identified by its primary keys and | |
| 59 | * values. This can be done by constructing a map where the key to the | |
| 60 | * map entry is the primary key attribute and the value of the entry | |
| 61 | * being the primary key value. For composite keys, pass in each | |
| 62 | * primaryKey attribute and its value as a map entry. | |
| 63 | * | |
| 64 | * @param clazz | |
| 65 | * @param primaryKeys | |
| 66 | * @return Object | |
| 67 | */ | |
| 68 | public Object findByPrimaryKey(Class clazz, Map primaryKeys); | |
| 69 | ||
| 70 | /** | |
| 71 | * This method should be used to try and locate an object instance by passing | |
| 72 | * in unique keys and values. This can be done by constructing a map where the key to the | |
| 73 | * map entry is the unique key attribute and the value of the entry | |
| 74 | * being the unique key value. For composite keys, pass in each | |
| 75 | * unique key attribute and its value as a map entry. | |
| 76 | * | |
| 77 | * @param clazz | |
| 78 | * @param uniqueKeys | |
| 79 | * @return Object | |
| 80 | */ | |
| 81 | public Object findByUniqueKey(Class clazz, Map uniqueKeys); | |
| 82 | ||
| 83 | /** | |
| 84 | * Retrieves an object instance identified by the class of the given | |
| 85 | * object and the object's primary key values. | |
| 86 | * | |
| 87 | * @param object | |
| 88 | * @return Object | |
| 89 | */ | |
| 90 | public Object retrieve(Object object); | |
| 91 | ||
| 92 | /** | |
| 93 | * This method allows you to pass in an object that has some fields filled in, | |
| 94 | * and will query underneath by automatically constructing a select statement | |
| 95 | * whose where clause is built automatically by looking at the non-null | |
| 96 | * attributes and using their values as part of the query. This is basically | |
| 97 | * a query by "template" method. | |
| 98 | * @param object | |
| 99 | * @return Collection | |
| 100 | */ | |
| 101 | public Collection findMatchingByExample(Object object); | |
| 102 | ||
| 103 | /** | |
| 104 | * Retrieves a collection of business objects populated with data, such | |
| 105 | * that each record in the database populates a new object instance. | |
| 106 | * This will only retrieve business objects by class type. | |
| 107 | * | |
| 108 | * @param clazz | |
| 109 | * @return Collection | |
| 110 | */ | |
| 111 | public Collection findAll(Class clazz); | |
| 112 | ||
| 113 | /** | |
| 114 | * Retrieves a collection of business objects populated with data, such | |
| 115 | * that each record in the database populates a new object instance. | |
| 116 | * This will only retrieve business objects by class type. Orders the | |
| 117 | * results by the given field. | |
| 118 | * | |
| 119 | * @param clazz | |
| 120 | * @return Collection | |
| 121 | */ | |
| 122 | public Collection findAllOrderBy(Class clazz, String sortField, | |
| 123 | boolean sortAscending); | |
| 124 | ||
| 125 | /** | |
| 126 | * This method retrieves a collection of business objects populated with | |
| 127 | * data, such that each record in the database populates a new object | |
| 128 | * instance. This will retrieve business objects by class type and also | |
| 129 | * by criteria passed in as key-value pairs, specifically attribute | |
| 130 | * name-expected value. | |
| 131 | * | |
| 132 | * @param clazz | |
| 133 | * @param fieldValues | |
| 134 | * @return Collection | |
| 135 | */ | |
| 136 | public Collection findMatching(Class clazz, Map fieldValues); | |
| 137 | ||
| 138 | /** | |
| 139 | * This method allows for a more flexible search by allowing the programmer to | |
| 140 | * construct the criteria however they need to and then pass that in for execution. | |
| 141 | * @param clazz | |
| 142 | * @param criteria | |
| 143 | * @return Collection | |
| 144 | */ | |
| 145 | public Collection findMatching(Class clazz, org.apache.ojb.broker.query.Criteria criteria); | |
| 146 | ||
| 147 | /** | |
| 148 | * This method allows for a more flexible search by allowing the programmer to | |
| 149 | * construct the criteria however they need to and then pass that in for execution. | |
| 150 | * @param clazz | |
| 151 | * @param criteria | |
| 152 | * @param selectForUpdate whether to perform a select for update query | |
| 153 | * @param wait millis to wait for select for update | |
| 154 | * @return Collection | |
| 155 | */ | |
| 156 | public Collection findMatching(Class clazz, org.apache.ojb.broker.query.Criteria criteria, boolean selectForUpdate, long wait); | |
| 157 | ||
| 158 | public Collection findMatching(Class clazz, Map criteria, boolean selectForUpdate, long wait); | |
| 159 | ||
| 160 | /** | |
| 161 | * @param clazz | |
| 162 | * @param fieldValues | |
| 163 | * @return count of BusinessObjects of the given class whose fields | |
| 164 | * match the values in the given Map. | |
| 165 | */ | |
| 166 | public int countMatching(Class clazz, Map fieldValues); | |
| 167 | ||
| 168 | /** | |
| 169 | * | |
| 170 | * This method returns the number of matching result given the positive | |
| 171 | * criterias and negative criterias. The negative criterias are the ones | |
| 172 | * that will be set to "notEqualTo" or "notIn" | |
| 173 | * | |
| 174 | * @param clazz | |
| 175 | * @param positiveFieldValues | |
| 176 | * Map of fields and values for positive criteria | |
| 177 | * @param negativeFieldValues | |
| 178 | * Map of fields and values for negative criteria | |
| 179 | * @return int | |
| 180 | */ | |
| 181 | public int countMatching(Class clazz, Map positiveFieldValues, | |
| 182 | Map negativeFieldValues); | |
| 183 | ||
| 184 | /** | |
| 185 | * This method retrieves a collection of business objects populated with | |
| 186 | * data, such that each record in the database populates a new object | |
| 187 | * instance. This will retrieve business objects by class type and also | |
| 188 | * by criteria passed in as key-value pairs, specifically attribute | |
| 189 | * name-expected value. Orders the results by the given field. | |
| 190 | * | |
| 191 | * @param clazz | |
| 192 | * @param fieldValues | |
| 193 | * @return Collection | |
| 194 | */ | |
| 195 | public Collection findMatchingOrderBy(Class clazz, Map fieldValues, | |
| 196 | String sortField, boolean sortAscending); | |
| 197 | ||
| 198 | /** | |
| 199 | * Deletes a business object from the database. | |
| 200 | * | |
| 201 | * @param bo | |
| 202 | */ | |
| 203 | public void delete(Object bo); | |
| 204 | ||
| 205 | /** | |
| 206 | * Deletes each business object in the given List from the database. | |
| 207 | * | |
| 208 | * @param boList | |
| 209 | */ | |
| 210 | public void delete(List<Object> boList); | |
| 211 | ||
| 212 | /** | |
| 213 | * Deletes the business objects matching the given fieldValues | |
| 214 | * | |
| 215 | * @param clazz | |
| 216 | * @param fieldValues | |
| 217 | */ | |
| 218 | public void deleteMatching(Class clazz, Map fieldValues); | |
| 219 | ||
| 220 | /** | |
| 221 | * This method allows for a more flexible search by allowing the programmer to | |
| 222 | * construct the criteria however they need to and then pass that in for execution. | |
| 223 | * @param clazz | |
| 224 | * @param criteria | |
| 225 | * @return Collection | |
| 226 | */ | |
| 227 | public Collection findMatching(Class clazz, Criteria criteria); | |
| 228 | ||
| 229 | /** | |
| 230 | * This method allows for a more flexible search by allowing the programmer to | |
| 231 | * construct the criteria however they need to and then pass that in for execution. | |
| 232 | * @param clazz | |
| 233 | * @param criteria | |
| 234 | * @param selectForUpdate whether to perform a select for update query | |
| 235 | * @param wait millis to wait for select for update | |
| 236 | * @return Collection | |
| 237 | */ | |
| 238 | public Collection findMatching(Class clazz, Criteria criteria, boolean selectForUpdate, long wait); | |
| 239 | ||
| 240 | } |