| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BusinessObjectService |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2005-2008 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.kns.service; | |
| 17 | ||
| 18 | import java.util.Collection; | |
| 19 | import java.util.List; | |
| 20 | import java.util.Map; | |
| 21 | ||
| 22 | import org.kuali.rice.kns.bo.BusinessObject; | |
| 23 | import org.kuali.rice.kns.bo.PersistableBusinessObject; | |
| 24 | ||
| 25 | /** | |
| 26 | * This interface defines methods that a BusinessObjectService must provide. | |
| 27 | * | |
| 28 | * | |
| 29 | */ | |
| 30 | public interface BusinessObjectService { | |
| 31 | ||
| 32 | /** | |
| 33 | * Saves the passed in object via the persistence layer. | |
| 34 | * | |
| 35 | * This will throw an IllegalArgumentException (runtime exception) if the object passed in is not a descendent of | |
| 36 | * BusinessObject. | |
| 37 | * | |
| 38 | * @param bo A BusinessObject instance or descendent that you wish to be stored. | |
| 39 | * | |
| 40 | */ | |
| 41 | public void save(PersistableBusinessObject bo); | |
| 42 | ||
| 43 | /** | |
| 44 | * Saves the businessObjects on the list via the persistence layer. | |
| 45 | * | |
| 46 | * This will throw an IllegalArgumentException (runtime exception) if any of the objects passed in is not a descendent of | |
| 47 | * BusinessObject. | |
| 48 | * | |
| 49 | * @param businessObjects A List<PersistableBusinessObject> of objects to persist. | |
| 50 | * | |
| 51 | */ | |
| 52 | public void save(List<? extends PersistableBusinessObject> businessObjects); | |
| 53 | ||
| 54 | /** | |
| 55 | * Links up any contained objects, and then Saves the passed in object via the persistence layer. | |
| 56 | * | |
| 57 | * This will throw an IllegalArgumentException (runtime exception) if the object passed in is not a descendent of | |
| 58 | * BusinessObject. | |
| 59 | * | |
| 60 | * @param bo A BusinessObject instance or descendent that you wish to be stored. | |
| 61 | * | |
| 62 | */ | |
| 63 | public void linkAndSave(PersistableBusinessObject bo); | |
| 64 | ||
| 65 | /** | |
| 66 | * Links up any contained objects, and Saves the businessObjects on the list via the persistence layer. | |
| 67 | * | |
| 68 | * This will throw an IllegalArgumentException (runtime exception) if any of the objects passed in is not a descendent of | |
| 69 | * BusinessObject. | |
| 70 | * | |
| 71 | * @param businessObjects A List<BusinessObject> of objects to persist. | |
| 72 | * | |
| 73 | */ | |
| 74 | public void linkAndSave(List<? extends PersistableBusinessObject> businessObjects); | |
| 75 | ||
| 76 | /** | |
| 77 | * Retrieves an object instance identified by its primary key. For composite keys, use {@link #findByPrimaryKey(Class, Map)} | |
| 78 | * | |
| 79 | * @param clazz | |
| 80 | * @param primaryKey | |
| 81 | * @return | |
| 82 | */ | |
| 83 | public <T> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey); | |
| 84 | ||
| 85 | /** | |
| 86 | * Retrieves an object instance identified by its primary keys and values. This can be done by constructing a map where the key | |
| 87 | * to the map entry is the primary key attribute and the value of the entry being the primary key value. For composite keys, | |
| 88 | * pass in each primaryKey attribute and its value as a map entry. | |
| 89 | * | |
| 90 | * @param clazz | |
| 91 | * @param primaryKeys | |
| 92 | * @return | |
| 93 | */ | |
| 94 | public PersistableBusinessObject findByPrimaryKey(Class clazz, Map primaryKeys); | |
| 95 | ||
| 96 | /** | |
| 97 | * Retrieves an object instance identified by the class of the given object and the object's primary key values. | |
| 98 | * | |
| 99 | * @param object | |
| 100 | * @return | |
| 101 | */ | |
| 102 | public PersistableBusinessObject retrieve(PersistableBusinessObject object); | |
| 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. | |
| 107 | * | |
| 108 | * @param clazz | |
| 109 | * @return | |
| 110 | */ | |
| 111 | public Collection findAll(Class clazz); | |
| 112 | ||
| 113 | /** | |
| 114 | * This method retrieves a collection of business objects populated with data, such that each record in the database populates a | |
| 115 | * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs, | |
| 116 | * specifically attribute name and its expected value. | |
| 117 | * | |
| 118 | * @param clazz | |
| 119 | * @param fieldValues | |
| 120 | * @return | |
| 121 | */ | |
| 122 | public Collection findMatching(Class clazz, Map fieldValues); | |
| 123 | ||
| 124 | /** | |
| 125 | * This method retrieves a count of the business objects populated with data which match the criteria in the given Map. | |
| 126 | * | |
| 127 | * @param clazz | |
| 128 | * @param fieldValues | |
| 129 | * @return number of businessObjects of the given class whose fields match the values in the given expected-value Map | |
| 130 | */ | |
| 131 | public int countMatching(Class clazz, Map fieldValues); | |
| 132 | ||
| 133 | /** | |
| 134 | * This method retrieves a count of the business objects populated with data which match both the positive criteria | |
| 135 | * and the negative criteria in the given Map. | |
| 136 | * | |
| 137 | * @param clazz | |
| 138 | * @param positiveFieldValues | |
| 139 | * @param negativeFieldValues | |
| 140 | * @return number of businessObjects of the given class whose fields match the values in the given expected-value Maps | |
| 141 | */ | |
| 142 | public int countMatching(Class clazz, Map positiveFieldValues, Map negativeFieldValues); | |
| 143 | ||
| 144 | /** | |
| 145 | * This method retrieves a collection of business objects populated with data, such that each record in the database populates a | |
| 146 | * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs, | |
| 147 | * specifically attribute name and its expected value. Performs an order by on sort field. | |
| 148 | * | |
| 149 | * @param clazz | |
| 150 | * @param fieldValues | |
| 151 | * @return | |
| 152 | */ | |
| 153 | public Collection findMatchingOrderBy(Class clazz, Map fieldValues, String sortField, boolean sortAscending); | |
| 154 | ||
| 155 | /** | |
| 156 | * Deletes a business object from the database. | |
| 157 | * | |
| 158 | * @param bo | |
| 159 | */ | |
| 160 | public void delete(PersistableBusinessObject bo); | |
| 161 | ||
| 162 | /** | |
| 163 | * Deletes each business object in the given List. | |
| 164 | * | |
| 165 | * @param boList | |
| 166 | */ | |
| 167 | public void delete(List<? extends PersistableBusinessObject> boList); | |
| 168 | ||
| 169 | /** | |
| 170 | * Deletes the object(s) matching the given field values | |
| 171 | * | |
| 172 | * @param clazz | |
| 173 | * @param fieldValues | |
| 174 | */ | |
| 175 | public void deleteMatching(Class clazz, Map fieldValues); | |
| 176 | ||
| 177 | /** | |
| 178 | * | |
| 179 | * This method attempts to retrieve the reference from a BO if it exists. | |
| 180 | * | |
| 181 | * @param bo - populated BusinessObject instance that includes the referenceName property | |
| 182 | * @param referenceName - name of the member/property to load | |
| 183 | * @return A populated object from the DB, if it exists | |
| 184 | * | |
| 185 | */ | |
| 186 | public BusinessObject getReferenceIfExists(BusinessObject bo, String referenceName); | |
| 187 | ||
| 188 | /** | |
| 189 | * | |
| 190 | * Updates all KualiUser or Person objects contained within this BO, based on the UserID as the authoritative key. The | |
| 191 | * appropriate foreign-key field in the BO itself is also updated. | |
| 192 | * | |
| 193 | * This allows UserIDs to be entered on forms, and the back-end will link up correctly based on this non-key field. | |
| 194 | * | |
| 195 | * @param bo The populated BO (or descendent) instance to be linked & updated | |
| 196 | * | |
| 197 | */ | |
| 198 | public void linkUserFields(PersistableBusinessObject bo); | |
| 199 | ||
| 200 | /** | |
| 201 | * | |
| 202 | * Updates all KualiUser or Person objects contained within this BO, based on the UserID as the authoritative key. The | |
| 203 | * appropriate foreign-key field in the BO itself is also updated. | |
| 204 | * | |
| 205 | * This allows UserIDs to be entered on forms, and the back-end will link up correctly based on this non-key field. | |
| 206 | * | |
| 207 | * @param bos A List of populated BusinessObject (or descendent) instances to be linked & updated. | |
| 208 | */ | |
| 209 | public void linkUserFields(List<PersistableBusinessObject> bos); | |
| 210 | ||
| 211 | } | |
| 212 |