Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PersistenceStructureService |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright 2006-2007 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.List; | |
19 | import java.util.Map; | |
20 | ||
21 | import org.kuali.rice.kns.bo.BusinessObjectRelationship; | |
22 | import org.kuali.rice.kns.bo.PersistableBusinessObject; | |
23 | import org.kuali.rice.kns.exception.ClassNotPersistableException; | |
24 | import org.kuali.rice.kns.exception.ObjectNotABusinessObjectRuntimeException; | |
25 | import org.kuali.rice.kns.util.ForeignKeyFieldsPopulationState; | |
26 | ||
27 | /** | |
28 | * This interface defines methods that a Persistence Service must provide. PersistenceMetadataService provides access to | |
29 | * persistence-layer information about persistable classes. | |
30 | */ | |
31 | public interface PersistenceStructureService { | |
32 | /** | |
33 | * @param clazz | |
34 | * @return true if the given Class is persistable (is known to OJB) | |
35 | */ | |
36 | public boolean isPersistable(Class clazz); | |
37 | ||
38 | /** | |
39 | * @param clazz Class whose primary key field names you want to list | |
40 | * @return a List of field names for the given class which are designated as key fields in the OJB repository file | |
41 | * @throws IllegalArgumentException if the given Class is null | |
42 | * @throws ClassNotPersistableException if the given object is of a type not described in the OJB repository | |
43 | */ | |
44 | public List listPrimaryKeyFieldNames(Class clazz); | |
45 | ||
46 | ||
47 | /** | |
48 | * @param clazz Class whose field names you want to list | |
49 | * @return a List of field names for the given class in the OJB repository file | |
50 | * @throws IllegalArgumentException if the given Class is null | |
51 | * @throws ClassNotPersistableException if the given object is of a type not described in the OJB repository | |
52 | */ | |
53 | public List listFieldNames(Class clazz); | |
54 | ||
55 | ||
56 | /** | |
57 | * @param clazz whose primary key field name, anonymous key marking is requested for | |
58 | * @return a Map containing the primary key name as the key and Boolean indicating whether or not the pk is marked as anonymous | |
59 | * in the obj repository file | |
60 | * @throws IllegalArgumentException if the given Object is null | |
61 | * @throws ClassNotPersistableException if the given object is of a type not described in the OJB repository | |
62 | */ | |
63 | /* No references - https://test.kuali.org/confluence/x/SYCf | |
64 | public Map getPrimaryKeyFieldAnonymousMarking(Class clazz); | |
65 | */ | |
66 | ||
67 | /** | |
68 | * | |
69 | * This method returns a List of Strings, each containing the field name of one of the primary keys, as defined in the ORM | |
70 | * layer. | |
71 | * | |
72 | * @param clazz - Class whose primary key field names are requested | |
73 | * @return A List of Strings, each containing the field name of the primary key | |
74 | * @throws IllegalArgumentException if the given Object is null | |
75 | * @throws ClassNotPersistableException if the given object is of a type not described in the OJB repository | |
76 | * | |
77 | */ | |
78 | public List getPrimaryKeys(Class clazz); | |
79 | ||
80 | /** | |
81 | * @param persistableObject | |
82 | * @return true if all primary key fields of the string have a non-null (and non-empty, for Strings) value | |
83 | * @throws IllegalArgumentException if the given Object is null | |
84 | * @throws ClassNotPersistableException if the given object is of a type not described in the OJB repository | |
85 | */ | |
86 | public boolean hasPrimaryKeyFieldValues(Object persistableObject); | |
87 | ||
88 | /** | |
89 | * @param persistableObject object whose primary key fields need to be cleared | |
90 | * @return the object whose primary key fields have just been cleared | |
91 | * @throws IllegalArgumentException if the given Object is null | |
92 | * @throws ClassNotPersistableException if the given object is of a type not described in the OJB repository | |
93 | */ | |
94 | public Object clearPrimaryKeyFields(Object persistableObject); | |
95 | ||
96 | ||
97 | /** | |
98 | * @param superclazz class whose persistable subclasses (or interface whose implementors) will be returned | |
99 | * @return a List of persistable Classes which extend or implement the given Class | |
100 | * @throws IllegalArgumentException if the given class is null | |
101 | */ | |
102 | public List listPersistableSubclasses(Class superclazz); | |
103 | ||
104 | /** | |
105 | * @param persistableClass | |
106 | * @param attributeName Name of an attribute used in the relationship | |
107 | * @return BusinessObjectRelationship object containing information about the object type related via the named relationship of the | |
108 | * given class, or null if the persistence service can find no object type related via the named relationship | |
109 | * @throws IllegalArgumentException if the given Class is null | |
110 | * @throws IllegalArgumentException if the given relationshipName is blanks | |
111 | * @throws ClassNotPersistableException if the given Class is a type not described in the OJB repository | |
112 | */ | |
113 | public Map<String,BusinessObjectRelationship> getRelationshipMetadata(Class persistableClass, String attributeName, String attributePrefix ); | |
114 | ||
115 | public Map<String,BusinessObjectRelationship> getRelationshipMetadata(Class persistableClass, String attributeName); | |
116 | ||
117 | public String getForeignKeyFieldName(Class persistableObjectClass, String attributeName, String pkName); | |
118 | ||
119 | /** | |
120 | * Attempts to match the attribute name given for the class as a fk field to a reference class defined in the repository. Since | |
121 | * a fk field can have references to many tables, this returns a list of all found. | |
122 | * | |
123 | * @param persistableObjectClass | |
124 | * @param attributeName | |
125 | * @return Map with attribue name as key of map and class as value | |
126 | */ | |
127 | public Map<String,Class> getReferencesForForeignKey(Class persistableObjectClass, String attributeName); | |
128 | ||
129 | /** | |
130 | * | |
131 | * This method will return a Map of all the foreign key fields and the corresponding primary key fields for a given reference. | |
132 | * | |
133 | * The Map structure is: Key(String fkFieldName) => Value(String pkFieldName) | |
134 | * | |
135 | * @param clazz - Class that contains the named reference | |
136 | * @param attributeName - Name of the member that is the reference you want foreign keys for | |
137 | * @return returns a Map populated as described above, with one entry per foreign key field | |
138 | * | |
139 | */ | |
140 | public Map getForeignKeysForReference(Class clazz, String attributeName); | |
141 | ||
142 | /** | |
143 | * | |
144 | * This method is a PersistableBusinessObject specifific utility method. If the Class clazz passed in is a descendent of PersistableBusinessObject, | |
145 | * and if the attributeName specified exists on the object, then the class of this | |
146 | * attribute named will be returned. | |
147 | * | |
148 | * @param clazz - class to be examined for the attribute's class | |
149 | * @param attributeName - name of the class' attribute to be examined | |
150 | * @return the class of the named attribute, if no exceptions occur | |
151 | * @throws ObjectNotABusinessObjectRuntimeException - if the class specified is not a descendent of PersistableBusinessObject, or the class of the | |
152 | * named attribute is not descended from PersistableBusinessObject | |
153 | * | |
154 | */ | |
155 | public Class getBusinessObjectAttributeClass(Class clazz, String attributeName) throws ObjectNotABusinessObjectRuntimeException; | |
156 | ||
157 | /** | |
158 | * Builds a map of reference pk attributes back to the foreign key. | |
159 | * | |
160 | * @param persistableObjectClass | |
161 | * @return | |
162 | */ | |
163 | public Map getNestedForeignKeyMap(Class persistableObjectClass); | |
164 | ||
165 | /** | |
166 | * | |
167 | * This method checks the foreign keys for a reference on a given BO, and tests that all fk fields are populated if any are | |
168 | * populated. | |
169 | * | |
170 | * In other words, for a given reference, it finds all the attributes of the BO that make up the foreign keys, and checks to see | |
171 | * if they all have values. It also keeps a list of all the fieldNames that do not have values. | |
172 | * | |
173 | * @param bo - A populated BusinessObject descendent. Must contain an attributed named referenceName. | |
174 | * @param referenceName - The name of the field that is a reference we are analyzing. | |
175 | * @return A populated ForeignKeyFieldsPopulation object which represents the state of population for the foreign key fields. | |
176 | */ | |
177 | public ForeignKeyFieldsPopulationState getForeignKeyFieldsPopulationState(PersistableBusinessObject bo, String referenceName); | |
178 | ||
179 | /** | |
180 | * | |
181 | * This method uses the persistence layer to determine the list of reference objects contained within this parent object. For | |
182 | * example, an Account object contains sub-objects such as Chart, as well as the key that connects the two, String | |
183 | * chartOfAccountsCode. | |
184 | * | |
185 | * The return structure is: Map<referenceName, referenceClass>. | |
186 | * | |
187 | * As an example, an Account object passed into this would return: | |
188 | * | |
189 | * 0:['chartOfAccounts', org.kuali.module.chart.bo.Chart] 1:['organization', org.kuali.module.chart.bo.Org] etc. | |
190 | * | |
191 | * @param boClass Class that would like to be analyzed for reference names | |
192 | * @return Map containing the reference name for the key as a string, and the class of the reference as the value. If the object | |
193 | * contains no references, then this Map will be empty. | |
194 | * | |
195 | */ | |
196 | public Map<String, Class> listReferenceObjectFields(Class boClass); | |
197 | ||
198 | /** | |
199 | * | |
200 | * This method uses the persistence layer to determine the list of reference objects contained within this parent object. For | |
201 | * example, an Account object contains sub-objects such as Chart, as well as the key that connects the two, String | |
202 | * chartOfAccountsCode. | |
203 | * | |
204 | * The return structure is: Map<referenceName, referenceClass>. | |
205 | * | |
206 | * As an example, an Account object passed into this would return: | |
207 | * | |
208 | * 0:['chartOfAccounts', org.kuali.module.chart.bo.Chart] 1:['organization', org.kuali.module.chart.bo.Org] etc. | |
209 | * | |
210 | * @param bo BusinessObject (or subclass) instance that would like to be analyzed for reference names | |
211 | * @return Map containing the reference name for the key as a string, and the class of the reference as the value. If the object | |
212 | * contains no references, then this Map will be empty. | |
213 | * | |
214 | */ | |
215 | public Map<String, Class> listReferenceObjectFields(PersistableBusinessObject bo); | |
216 | ||
217 | public Map<String, Class> listCollectionObjectTypes(Class boClass); | |
218 | public Map<String, Class> listCollectionObjectTypes(PersistableBusinessObject bo); | |
219 | ||
220 | /** | |
221 | * Returns whether there is a reference defined in the persistence layer with the given name. | |
222 | * Depending on the type of underlying persistence mechanism, this method may or may not return true | |
223 | * when the referenceName really refers to a collection type. | |
224 | * | |
225 | * To determine whether a reference is a collection, use the hasCollection method instead. | |
226 | * | |
227 | * In OJB, this method will return false for collection references. | |
228 | * | |
229 | * @param boClass | |
230 | * @param referenceName | |
231 | * @return | |
232 | */ | |
233 | public boolean hasReference(Class boClass, String referenceName); | |
234 | ||
235 | ||
236 | /** | |
237 | * Returns whether BOs of the given class have a collection defined within them with the given collection name. | |
238 | * | |
239 | * @param boClass | |
240 | * @param collectionName | |
241 | * @return | |
242 | */ | |
243 | public boolean hasCollection(Class boClass, String collectionName); | |
244 | ||
245 | public boolean isReferenceUpdatable(Class boClass, String referenceName); | |
246 | public boolean isCollectionUpdatable(Class boClass, String collectionName); | |
247 | ||
248 | /** | |
249 | * Returns a listing of the FK field mappings between a BO and the elements in a collection. Since this is in effect a | |
250 | * 1:n relationship, only the complete primary key set of the parent BO will be returned. | |
251 | * | |
252 | * for example, assume Account BO has an "acctNbrForAcct" PK, and it has a list of subAccounts, | |
253 | * each of which has a ("acctNbrForSubAcct", "subAcctNbr") PK pair. | |
254 | * | |
255 | * the Account PK will be mapped to some of the PK fields of the element list. | |
256 | * When called on the Account BO class with the "subAccounts" collection name, his method should return | |
257 | * a map with a mapping of "acctNbrForAcct" (key) => "acctNbrForSubAcct" | |
258 | * | |
259 | * @param boClass | |
260 | * @param collectionName | |
261 | * @return | |
262 | */ | |
263 | public Map<String, String> getInverseForeignKeysForCollection(Class boClass, String collectionName); | |
264 | ||
265 | /** | |
266 | * Returns the name of the table underlying the business object class | |
267 | * | |
268 | * @param boClass | |
269 | * @return | |
270 | */ | |
271 | public String getTableName(Class<? extends PersistableBusinessObject> boClass); | |
272 | } |