View Javadoc

1   /*
2    * Copyright 2007-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.core.dao;
17  
18  import java.util.Collection;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.ojb.broker.query.Criteria;
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.kns.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, 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, Criteria criteria, boolean selectForUpdate, long wait);
156 
157     /**
158      * @param clazz
159      * @param fieldValues
160      * @return count of BusinessObjects of the given class whose fields
161      *         match the values in the given Map.
162      */
163     public int countMatching(Class clazz, Map fieldValues);
164 
165     /**
166      * 
167      * This method returns the number of matching result given the positive
168      * criterias and negative criterias. The negative criterias are the ones
169      * that will be set to "notEqualTo" or "notIn"
170      * 
171      * @param clazz
172      * @param positiveFieldValues
173      *                Map of fields and values for positive criteria
174      * @param negativeFieldValues
175      *                Map of fields and values for negative criteria
176      * @return int
177      */
178     public int countMatching(Class clazz, Map positiveFieldValues,
179         Map negativeFieldValues);
180 
181     /**
182      * This method retrieves a collection of business objects populated with
183      * data, such that each record in the database populates a new object
184      * instance. This will retrieve business objects by class type and also
185      * by criteria passed in as key-value pairs, specifically attribute
186      * name-expected value. Orders the results by the given field.
187      * 
188      * @param clazz
189      * @param fieldValues
190      * @return Collection
191      */
192     public Collection findMatchingOrderBy(Class clazz, Map fieldValues,
193         String sortField, boolean sortAscending);
194 
195     /**
196      * Deletes a business object from the database.
197      * 
198      * @param bo
199      */
200     public void delete(Object bo);
201 
202     /**
203      * Deletes each business object in the given List from the database.
204      * 
205      * @param boList
206      */
207     public void delete(List<Object> boList);
208 
209     /**
210      * Deletes the business objects matching the given fieldValues
211      * 
212      * @param clazz
213      * @param fieldValues
214      */
215     public void deleteMatching(Class clazz, Map fieldValues);
216 }