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.dao;
17
18 import java.util.Collection;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.rice.kns.bo.PersistableBusinessObject;
23
24 /**
25 * This is the generic data access interface for business objects. This should be used for unit testing purposes only.
26 *
27 *
28 */
29 public interface BusinessObjectDao {
30 /**
31 * Saves any object that implements the BusinessObject interface.
32 *
33 * @param bo
34 */
35 public void save(PersistableBusinessObject bo);
36
37 /**
38 * Saves a List of BusinessObjects.
39 *
40 * @param businessObjects
41 */
42 public void save(List businessObjects);
43
44 /**
45 * Retrieves an object instance identified by its primary key. For composite keys, use {@link #findByPrimaryKey(Class, Map)}
46 *
47 * @param clazz
48 * @param primaryKey
49 * @return
50 */
51 public PersistableBusinessObject findBySinglePrimaryKey(Class clazz, Object primaryKey);
52
53 /**
54 * Retrieves an object instance identified bys it primary keys and values. This can be done by constructing a map where the key
55 * to the map entry is the primary key attribute and the value of the entry being the primary key value. For composite keys,
56 * pass in each primaryKey attribute and its value as a map entry.
57 *
58 * @param clazz
59 * @param primaryKeys
60 * @return
61 */
62 public PersistableBusinessObject findByPrimaryKey(Class clazz, Map primaryKeys);
63
64 /**
65 * Retrieves an object instance identified by the class of the given object and the object's primary key values.
66 *
67 * @param object
68 * @return
69 */
70 public PersistableBusinessObject retrieve(PersistableBusinessObject object);
71
72 /**
73 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
74 * instance. This will only retrieve business objects by class type.
75 *
76 * @param clazz
77 * @return
78 */
79 public Collection findAll(Class clazz);
80
81 /**
82 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
83 * instance. This will only retrieve business objects by class type.
84 *
85 * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active
86 *
87 * @param clazz
88 * @return
89 */
90 public Collection findAllActive(Class clazz);
91
92 public Collection findAllInactive(Class clazz);
93
94 /**
95 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
96 * instance. This will only retrieve business objects by class type. Orders the results by the given field.
97 *
98 * @param clazz
99 * @return
100 */
101 public Collection findAllOrderBy(Class clazz, String sortField, boolean sortAscending);
102
103 /**
104 * Retrieves a collection of business objects populated with data, such that each record in the database populates a new object
105 * instance. This will only retrieve business objects by class type. Orders the results by the given field.
106 *
107 * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active
108 * @param clazz
109 * @return
110 */
111 public Collection findAllActiveOrderBy(Class clazz, String sortField, boolean sortAscending);
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-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 collection of business objects populated with data, such that each record in the database populates a
126 * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs,
127 * specifically attribute name-expected value.
128 *
129 * Adds criteria on active column to return only active records. Assumes there exist a mapping for PropertyConstants.Active
130 *
131 * @param clazz
132 * @param fieldValues
133 * @return
134 */
135 public Collection findMatchingActive(Class clazz, Map fieldValues);
136
137 /**
138 * @param clazz
139 * @param fieldValues
140 * @return count of BusinessObjects of the given class whose fields match the values in the given Map.
141 */
142 public int countMatching(Class clazz, Map fieldValues);
143
144
145 /**
146 *
147 * This method returns the number of matching result given the positive criterias and
148 * negative criterias. The negative criterias are the ones that will be set to
149 * "notEqualTo" or "notIn"
150 *
151 * @param clazz
152 * @param positiveFieldValues Map of fields and values for positive criteria
153 * @param negativeFieldValues Map of fields and values for negative criteria
154 * @return
155 */
156 public int countMatching(Class clazz, Map positiveFieldValues, Map negativeFieldValues);
157
158 /**
159 * This method retrieves a collection of business objects populated with data, such that each record in the database populates a
160 * new object instance. This will retrieve business objects by class type and also by criteria passed in as key-value pairs,
161 * specifically attribute name-expected value. Orders the results by the given field.
162 *
163 * @param clazz
164 * @param fieldValues
165 * @return
166 */
167 public Collection findMatchingOrderBy(Class clazz, Map fieldValues, String sortField, boolean sortAscending);
168
169 /**
170 * Deletes a business object from the database.
171 *
172 * @param bo
173 */
174 public void delete(PersistableBusinessObject bo);
175
176 /**
177 * Deletes each business object in the given List from the database.
178 *
179 * @param boList
180 */
181 public void delete(List<? extends PersistableBusinessObject> boList);
182
183 /**
184 * Deletes the business objects matching the given fieldValues
185 *
186 * @param clazz
187 * @param fieldValues
188 */
189 public void deleteMatching(Class clazz, Map fieldValues);
190 }