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