001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.service; 017 018import org.kuali.rice.krad.bo.DataObjectRelationship; 019import org.kuali.rice.krad.bo.PersistableBusinessObject; 020import org.kuali.rice.krad.bo.PersistableBusinessObjectExtension; 021import org.kuali.rice.krad.util.ForeignKeyFieldsPopulationState; 022import org.kuali.rice.krad.util.LegacyDataFramework; 023 024import java.util.List; 025import java.util.Map; 026 027/** 028 * Defines methods that a Persistence Service must provide. PersistenceMetadataService provides access to 029 * persistence-layer information about persistable classes 030 * @deprecated use new KRAD Data framework {@link org.kuali.rice.krad.data.DataObjectService} 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033@Deprecated 034@LegacyDataFramework 035public interface PersistenceStructureService { 036 /** 037 * @param clazz 038 * @return true if the given Class is persistable (is known to OJB) 039 */ 040 public boolean isPersistable(Class clazz); 041 042 /** 043 * @param clazz Class whose primary key field names you want to list 044 * @return a List of field names for the given class which are designated as key fields in the OJB repository file 045 * @throws IllegalArgumentException if the given Class is null 046 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository 047 */ 048 public List listPrimaryKeyFieldNames(Class clazz); 049 050 051 /** 052 * @param clazz Class whose field names you want to list 053 * @return a List of field names for the given class in the OJB repository file 054 * @throws IllegalArgumentException if the given Class is null 055 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository 056 */ 057 public List listFieldNames(Class clazz); 058 059 060 /** 061 * @param clazz whose primary key field name, anonymous key marking is requested for 062 * @return a Map containing the primary key name as the key and Boolean indicating whether or not the pk is marked as anonymous 063 * in the obj repository file 064 * @throws IllegalArgumentException if the given Object is null 065 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository 066 */ 067 /* No references - https://test.kuali.org/confluence/x/SYCf 068 public Map getPrimaryKeyFieldAnonymousMarking(Class clazz); 069 */ 070 071 /** 072 * 073 * This method returns a List of Strings, each containing the field name of one of the primary keys, as defined in the ORM 074 * layer. 075 * 076 * @param clazz - Class whose primary key field names are requested 077 * @return A List of Strings, each containing the field name of the primary key 078 * @throws IllegalArgumentException if the given Object is null 079 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository 080 * 081 */ 082 public List getPrimaryKeys(Class clazz); 083 084 /** 085 * @param persistableObject 086 * @return true if all primary key fields of the string have a non-null (and non-empty, for Strings) value 087 * @throws IllegalArgumentException if the given Object is null 088 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository 089 */ 090 public boolean hasPrimaryKeyFieldValues(Object persistableObject); 091 092 /** 093 * @param persistableObject object whose primary key fields need to be cleared 094 * @return the object whose primary key fields have just been cleared 095 * @throws IllegalArgumentException if the given Object is null 096 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository 097 */ 098 public Object clearPrimaryKeyFields(Object persistableObject); 099 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}