1 /**
2 * Copyright 2005-2013 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.PersistableBusinessObject;
19
20 import java.util.List;
21 import java.util.Map;
22
23 /**
24 * @author Kuali Rice Team (rice.collab@kuali.org)
25 */
26 public interface PersistenceService {
27 // public void initialize();
28
29 public void loadRepositoryDescriptor(String ojbRepositoryFilePath);
30
31 public void clearCache();
32
33 public Object resolveProxy(Object o);
34
35 /**
36 * @param persistableObject object whose primary key field name,value pairs you want
37 * @return a Map containing the names and values of fields specified the given class which are designated as key fields in the
38 * OJB repository file
39 * @throws IllegalArgumentException if the given Object is null
40 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
41 */
42 public Map getPrimaryKeyFieldValues(Object persistableObject);
43
44 /**
45 * @param persistableObject object whose primary key field name,value pairs you want
46 * @param sortFieldNames if true, the returned Map will iterate through its entries sorted by fieldName
47 * @return a Map containing the names and values of fields specified the given class which are designated as key fields in the
48 * OJB repository file
49 * @throws IllegalArgumentException if the given Object is null
50 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
51 */
52 public Map getPrimaryKeyFieldValues(Object persistableObject, boolean sortFieldNames);
53
54 /**
55 * @param persistableObject object whose objects need to be filled in based on primary keys
56 * @return the object whose key fields have just been retrieved
57 * @throws IllegalArgumentException if the given Object is null
58 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
59 */
60 public void retrieveNonKeyFields(Object persistableObject);
61
62 /**
63 * @param persistableObject object whose specified reference object needs to be filled in based on primary keys
64 * @param referenceObjectName the name of the reference object that will be filled in based on primary key values
65 * @throws IllegalArgumentException if the given Object is null
66 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
67 */
68 public void retrieveReferenceObject(Object persistableObject, String referenceObjectName);
69
70
71 /**
72 * @param persistableObject object whose specified reference objects need to be filled in based on primary keys
73 * @param referenceObjectNames the names of the reference objects that will be filled in based on primary key values
74 * @throws IllegalArgumentException if either of the given lists is null or empty, or if any of the referenceObjectNames is
75 * blank
76 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
77 */
78 public void retrieveReferenceObjects(Object persistableObject, List referenceObjectNames);
79
80 /**
81 * @param persistableObjects objects whose specified reference objects need to be filled in based on primary keys
82 * @param referenceObjectNames the names of the reference objects that will be filled in based on primary key values
83 * @throws IllegalArgumentException if either of the given lists is null or empty, or if any of the referenceObjectNames is
84 * blank
85 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
86 */
87 public void retrieveReferenceObjects(List persistableObjects, List referenceObjectNames);
88
89
90 /**
91 * @param persistableObject object whose objects need to have keys filled
92 * @return the object whose key fields have just been filled
93 * @throws IllegalArgumentException if the given Object is null
94 * @throws org.kuali.rice.krad.exception.ClassNotPersistableException if the given object is of a type not described in the OJB repository
95 */
96 public void linkObjects(Object persistableObject);
97
98
99 /**
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 }