| 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.bo.PersistableBusinessObjectExtension; | |
| 24 | import org.kuali.rice.kns.exception.ClassNotPersistableException; | |
| 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 | */ | |
| 152 | public Class<? extends PersistableBusinessObjectExtension> getBusinessObjectAttributeClass(Class<? extends PersistableBusinessObject> clazz, String attributeName); | |
| 153 | ||
| 154 | /** | |
| 155 | * Builds a map of reference pk attributes back to the foreign key. | |
| 156 | * | |
| 157 | * @param persistableObjectClass | |
| 158 | * @return | |
| 159 | */ | |
| 160 | public Map getNestedForeignKeyMap(Class persistableObjectClass); | |
| 161 | ||
| 162 | /** | |
| 163 | * | |
| 164 | * This method checks the foreign keys for a reference on a given BO, and tests that all fk fields are populated if any are | |
| 165 | * populated. | |
| 166 | * | |
| 167 | * 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 | |
| 168 | * if they all have values. It also keeps a list of all the fieldNames that do not have values. | |
| 169 | * | |
| 170 | * @param bo - A populated BusinessObject descendent. Must contain an attributed named referenceName. | |
| 171 | * @param referenceName - The name of the field that is a reference we are analyzing. | |
| 172 | * @return A populated ForeignKeyFieldsPopulation object which represents the state of population for the foreign key fields. | |
| 173 | */ | |
| 174 | public ForeignKeyFieldsPopulationState getForeignKeyFieldsPopulationState(PersistableBusinessObject bo, String referenceName); | |
| 175 | ||
| 176 | /** | |
| 177 | * | |
| 178 | * This method uses the persistence layer to determine the list of reference objects contained within this parent object. For | |
| 179 | * example, an Account object contains sub-objects such as Chart, as well as the key that connects the two, String | |
| 180 | * chartOfAccountsCode. | |
| 181 | * | |
| 182 | * The return structure is: Map<referenceName, referenceClass>. | |
| 183 | * | |
| 184 | * As an example, an Account object passed into this would return: | |
| 185 | * | |
| 186 | * 0:['chartOfAccounts', org.kuali.module.chart.bo.Chart] 1:['organization', org.kuali.module.chart.bo.Org] etc. | |
| 187 | * | |
| 188 | * @param boClass Class that would like to be analyzed for reference names | |
| 189 | * @return Map containing the reference name for the key as a string, and the class of the reference as the value. If the object | |
| 190 | * contains no references, then this Map will be empty. | |
| 191 | * | |
| 192 | */ | |
| 193 | public Map<String, Class> listReferenceObjectFields(Class boClass); | |
| 194 | ||
| 195 | /** | |
| 196 | * | |
| 197 | * This method uses the persistence layer to determine the list of reference objects contained within this parent object. For | |
| 198 | * example, an Account object contains sub-objects such as Chart, as well as the key that connects the two, String | |
| 199 | * chartOfAccountsCode. | |
| 200 | * | |
| 201 | * The return structure is: Map<referenceName, referenceClass>. | |
| 202 | * | |
| 203 | * As an example, an Account object passed into this would return: | |
| 204 | * | |
| 205 | * 0:['chartOfAccounts', org.kuali.module.chart.bo.Chart] 1:['organization', org.kuali.module.chart.bo.Org] etc. | |
| 206 | * | |
| 207 | * @param bo BusinessObject (or subclass) instance that would like to be analyzed for reference names | |
| 208 | * @return Map containing the reference name for the key as a string, and the class of the reference as the value. If the object | |
| 209 | * contains no references, then this Map will be empty. | |
| 210 | * | |
| 211 | */ | |
| 212 | public Map<String, Class> listReferenceObjectFields(PersistableBusinessObject bo); | |
| 213 | ||
| 214 | public Map<String, Class> listCollectionObjectTypes(Class boClass); | |
| 215 | public Map<String, Class> listCollectionObjectTypes(PersistableBusinessObject bo); | |
| 216 | ||
| 217 | /** | |
| 218 | * Returns whether there is a reference defined in the persistence layer with the given name. | |
| 219 | * Depending on the type of underlying persistence mechanism, this method may or may not return true | |
| 220 | * when the referenceName really refers to a collection type. | |
| 221 | * | |
| 222 | * To determine whether a reference is a collection, use the hasCollection method instead. | |
| 223 | * | |
| 224 | * In OJB, this method will return false for collection references. | |
| 225 | * | |
| 226 | * @param boClass | |
| 227 | * @param referenceName | |
| 228 | * @return | |
| 229 | */ | |
| 230 | public boolean hasReference(Class boClass, String referenceName); | |
| 231 | ||
| 232 | ||
| 233 | /** | |
| 234 | * Returns whether BOs of the given class have a collection defined within them with the given collection name. | |
| 235 | * | |
| 236 | * @param boClass | |
| 237 | * @param collectionName | |
| 238 | * @return | |
| 239 | */ | |
| 240 | public boolean hasCollection(Class boClass, String collectionName); | |
| 241 | ||
| 242 | public boolean isReferenceUpdatable(Class boClass, String referenceName); | |
| 243 | public boolean isCollectionUpdatable(Class boClass, String collectionName); | |
| 244 | ||
| 245 | /** | |
| 246 | * Returns a listing of the FK field mappings between a BO and the elements in a collection. Since this is in effect a | |
| 247 | * 1:n relationship, only the complete primary key set of the parent BO will be returned. | |
| 248 | * | |
| 249 | * for example, assume Account BO has an "acctNbrForAcct" PK, and it has a list of subAccounts, | |
| 250 | * each of which has a ("acctNbrForSubAcct", "subAcctNbr") PK pair. | |
| 251 | * | |
| 252 | * the Account PK will be mapped to some of the PK fields of the element list. | |
| 253 | * When called on the Account BO class with the "subAccounts" collection name, his method should return | |
| 254 | * a map with a mapping of "acctNbrForAcct" (key) => "acctNbrForSubAcct" | |
| 255 | * | |
| 256 | * @param boClass | |
| 257 | * @param collectionName | |
| 258 | * @return | |
| 259 | */ | |
| 260 | public Map<String, String> getInverseForeignKeysForCollection(Class boClass, String collectionName); | |
| 261 | ||
| 262 | /** | |
| 263 | * Returns the name of the table underlying the business object class | |
| 264 | * | |
| 265 | * @param boClass | |
| 266 | * @return | |
| 267 | */ | |
| 268 | public String getTableName(Class<? extends PersistableBusinessObject> boClass); | |
| 269 | } |