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