1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.rice.krad.bo.ExternalizableBusinessObject;
20 import org.kuali.rice.krad.bo.PersistableBusinessObject;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.service.KualiModuleService;
23 import org.kuali.rice.krad.service.ModuleService;
24 import org.kuali.rice.krad.service.PersistenceService;
25 import org.kuali.rice.krad.util.ExternalizableBusinessObjectUtils;
26 import org.springframework.beans.BeanUtils;
27 import org.springframework.transaction.annotation.Transactional;
28 import org.springframework.util.CollectionUtils;
29
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37
38
39
40 @Transactional
41 public class PersistenceServiceImpl extends PersistenceServiceImplBase implements PersistenceService {
42
43 private static Logger LOG = Logger.getLogger(PersistenceServiceImpl.class);
44
45 private KualiModuleService kualiModuleService;
46
47 private PersistenceService persistenceServiceJpa;
48
49 private PersistenceService persistenceServiceOjb;
50
51 public void setPersistenceServiceJpa(PersistenceService persistenceServiceJpa) {
52 this.persistenceServiceJpa = persistenceServiceJpa;
53 }
54
55 public void setPersistenceServiceOjb(PersistenceService persistenceServiceOjb) {
56 this.persistenceServiceOjb = persistenceServiceOjb;
57 }
58
59 private PersistenceService getService(Class clazz) {
60 return (isJpaEnabledForKradClass(clazz)) ?
61 persistenceServiceJpa : persistenceServiceOjb;
62 }
63
64
65 public void clearCache() {
66 throw new UnsupportedOperationException("This should be called directly from the OJB Impl if needed.");
67 }
68
69
70 public void loadRepositoryDescriptor(String ojbRepositoryFilePath) {
71 throw new UnsupportedOperationException("This should be called directly from the OJB Impl if needed.");
72 }
73
74 public Object resolveProxy(Object o) {
75 return getService(o.getClass()).resolveProxy(o);
76 }
77
78
79
80
81 public void retrieveNonKeyFields(Object persistableObject) {
82 if (persistableObject != null &&
83 ExternalizableBusinessObjectUtils.isExternalizableBusinessObject(persistableObject.getClass())) {
84
85
86
87 Map<String, ?> criteria = KRADServiceLocatorWeb.getDataObjectMetaDataService().getPrimaryKeyFieldValues(persistableObject);
88 if (!CollectionUtils.isEmpty(criteria)) {
89 ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(persistableObject.getClass());
90 if (moduleService != null) {
91 Class<? extends ExternalizableBusinessObject> clazz =
92 ExternalizableBusinessObjectUtils.determineExternalizableBusinessObjectSubInterface(persistableObject.getClass());
93 ExternalizableBusinessObject freshEbo = moduleService.getExternalizableBusinessObject(clazz, (Map<String, Object>)criteria);
94 if (freshEbo != null) {
95 BeanUtils.copyProperties(freshEbo, persistableObject);
96 }
97 }
98 }
99 } else {
100 getService(persistableObject.getClass()).retrieveNonKeyFields(persistableObject);
101 }
102 }
103
104
105
106
107
108 public void retrieveReferenceObject(Object persistableObject, String referenceObjectName) {
109 getService(persistableObject.getClass()).retrieveReferenceObject(persistableObject, referenceObjectName);
110 }
111
112
113
114
115
116 public void retrieveReferenceObjects(Object persistableObject, List referenceObjectNames) {
117 getService(persistableObject.getClass()).retrieveReferenceObjects(persistableObject, referenceObjectNames);
118 }
119
120
121
122
123
124 public void retrieveReferenceObjects(List persistableObjects, List referenceObjectNames) {
125 if (persistableObjects == null) {
126 throw new IllegalArgumentException("invalid (null) persistableObjects");
127 }
128 if (persistableObjects.isEmpty()) {
129 throw new IllegalArgumentException("invalid (empty) persistableObjects");
130 }
131 if (referenceObjectNames == null) {
132 throw new IllegalArgumentException("invalid (null) referenceObjectNames");
133 }
134 if (referenceObjectNames.isEmpty()) {
135 throw new IllegalArgumentException("invalid (empty) referenceObjectNames");
136 }
137
138 for (Iterator i = persistableObjects.iterator(); i.hasNext();) {
139 Object persistableObject = i.next();
140 retrieveReferenceObjects(persistableObject, referenceObjectNames);
141 }
142 }
143
144
145
146
147 public String getFlattenedPrimaryKeyFieldValues(Object persistableObject) {
148 return getService(persistableObject.getClass()).getFlattenedPrimaryKeyFieldValues(persistableObject);
149 }
150
151
152
153
154
155
156
157
158
159
160
161
162 public void linkObjects(Object persistableObject) {
163 getService(persistableObject.getClass()).linkObjects(persistableObject);
164 }
165
166
167
168
169
170
171 public boolean allForeignKeyValuesPopulatedForReference(PersistableBusinessObject bo, String referenceName) {
172 return getService(bo.getClass()).allForeignKeyValuesPopulatedForReference(bo, referenceName);
173 }
174
175
176
177
178
179 public void refreshAllNonUpdatingReferences(PersistableBusinessObject bo) {
180 getService(bo.getClass()).refreshAllNonUpdatingReferences(bo);
181 }
182
183
184
185
186
187
188 public boolean isProxied(Object bo) {
189 return getService(bo.getClass()).isProxied(bo);
190 }
191
192 public KualiModuleService getKualiModuleService() {
193 return kualiModuleService;
194 }
195
196 public void setKualiModuleService(KualiModuleService kualiModuleService) {
197 this.kualiModuleService = kualiModuleService;
198 }
199 }