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