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