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.PersistableBusinessObject;
019
020import java.util.List;
021import java.util.Map;
022
023/**
024 * @author Kuali Rice Team (rice.collab@kuali.org)
025 */
026public interface PersistenceService {
027//    public void initialize();
028    
029        public void loadRepositoryDescriptor(String ojbRepositoryFilePath);
030    
031    public void clearCache();
032    
033    public Object resolveProxy(Object o);
034
035    /**
036     * @param persistableObject object whose primary key field name,value pairs you want
037     * @return a Map containing the names and values of fields specified the given class which are designated as key fields in the
038     *         OJB repository file
039     * @throws IllegalArgumentException if the given Object is null
040     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
041     */
042    public Map getPrimaryKeyFieldValues(Object persistableObject);
043
044    /**
045     * @param persistableObject object whose primary key field name,value pairs you want
046     * @param sortFieldNames if true, the returned Map will iterate through its entries sorted by fieldName
047     * @return a Map containing the names and values of fields specified the given class which are designated as key fields in the
048     *         OJB repository file
049     * @throws IllegalArgumentException if the given Object is null
050     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
051     */
052    public Map getPrimaryKeyFieldValues(Object persistableObject, boolean sortFieldNames);
053
054    /**
055     * @param persistableObject object whose objects need to be filled in based on primary keys
056     * @return the object whose key fields have just been retrieved
057     * @throws IllegalArgumentException if the given Object is null
058     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
059     */
060    public void retrieveNonKeyFields(Object persistableObject);
061
062    /**
063     * @param persistableObject object whose specified reference object needs to be filled in based on primary keys
064     * @param referenceObjectName the name of the reference object that will be filled in based on primary key values
065     * @throws IllegalArgumentException if the given Object is null
066     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
067     */
068    public void retrieveReferenceObject(Object persistableObject, String referenceObjectName);
069
070
071    /**
072     * @param persistableObject object whose specified reference objects need to be filled in based on primary keys
073     * @param referenceObjectNames the names of the reference objects that will be filled in based on primary key values
074     * @throws IllegalArgumentException if either of the given lists is null or empty, or if any of the referenceObjectNames is
075     *         blank
076     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
077     */
078    public void retrieveReferenceObjects(Object persistableObject, List referenceObjectNames);
079
080    /**
081     * @param persistableObjects objects whose specified reference objects need to be filled in based on primary keys
082     * @param referenceObjectNames the names of the reference objects that will be filled in based on primary key values
083     * @throws IllegalArgumentException if either of the given lists is null or empty, or if any of the referenceObjectNames is
084     *         blank
085     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
086     */
087    public void retrieveReferenceObjects(List persistableObjects, List referenceObjectNames);
088
089
090    /**
091     * @param persistableObject object whose objects need to have keys filled
092     * @return the object whose key fields have just been filled
093     * @throws IllegalArgumentException if the given Object is null
094     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
095     */
096    public void linkObjects(Object persistableObject);
097
098
099    /**
100     * Gets the value for the given field name from the object, works for anonymous fields as well as simple fields
101     * 
102     * @param persistableObject object to get value from
103     * @param fieldName name of the field to get from the object
104     * @return Object value of field in object, or null
105     */
106    // This method never called
107    //public Object getFieldValue(Object persistableObject, String fieldName);
108
109    /**
110     * @param persistableObject object whose primary key field name,value pairs you want
111     * @param bounded - whether to restrict the number of rows returned
112     * @return a String representation of the primary key fields and values for the given persistableObject
113     * @throws IllegalArgumentException if the given Object is null
114     * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
115     */
116    public String getFlattenedPrimaryKeyFieldValues(Object persistableObject);
117
118    /**
119     * 
120     * This method examines whether all the foreign key fields for the specified reference contain values.
121     * 
122     * @param bo
123     * @param referenceName
124     * @return true if they all are accessible and have values, false otherwise
125     * 
126     */
127    public boolean allForeignKeyValuesPopulatedForReference(PersistableBusinessObject bo, String referenceName);
128
129    /**
130     * 
131     * This method refreshes all reference objects to this main object that are 'non-updateable'. In general, this means that if a
132     * reference object is configured to not be updated when the parent document is saved, then they are non-updated.
133     * 
134     * This will not refresh updateable objects, which can cause problems when you're creating new objects.
135     * 
136     * See PersistenceServiceImpl.isUpdateableReference() for the full logic.
137     * 
138     * @param bo - the businessObject to be refreshed
139     * 
140     */
141    public void refreshAllNonUpdatingReferences(PersistableBusinessObject bo);
142
143    
144    /**
145     * Determines if the given object is proxied by the ORM or not
146     * 
147     * @param object the object to determine if it is a proxy
148     * @return true if the object is an ORM proxy; false otherwise
149     */
150    public abstract boolean isProxied(Object object);
151    
152    /**
153         * Determines if JPA is enabled for the KNS and for the given class
154         * 
155         * @param clazz the class to check for JPA enabling of
156         * @return true if JPA is enabled for the class, false otherwise
157         */
158        public abstract boolean isJpaEnabledForKradClass(Class clazz);
159}