View Javadoc

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.impl;
17  
18  import java.lang.reflect.InvocationTargetException;
19  import java.util.Collection;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.kuali.rice.core.api.uif.RemotableQuickFinder;
24  import org.kuali.rice.krad.bo.BusinessObject;
25  import org.kuali.rice.krad.bo.PersistableBusinessObject;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectExtension;
27  import org.kuali.rice.krad.datadictionary.RelationshipDefinition;
28  import org.kuali.rice.krad.document.Document;
29  import org.kuali.rice.krad.service.LegacyDataAdapter;
30  import org.kuali.rice.krad.util.ForeignKeyFieldsPopulationState;
31  import org.kuali.rice.krad.util.LegacyUtils;
32  
33  /**
34   * LegacyDataAdapter implementation.
35   *
36   * @deprecated instead of using this class, where possible go directly against new KRAD code
37   */
38  @Deprecated
39  public class LegacyDataAdapterImpl implements LegacyDataAdapter {
40  
41      private LegacyDataAdapter kradLegacyDataAdapter;
42      private LegacyDataAdapter knsLegacyDataAdapter;
43  
44      @Override
45      public <T> T save(T dataObject) {
46          return selectAdapter(dataObject).save(dataObject);
47      }
48  
49      @Override
50      public <T> T linkAndSave(T dataObject) {
51          return selectAdapter(dataObject).linkAndSave(dataObject);
52      }
53  
54      @Override
55      public <T> T saveDocument(T document) {
56          return selectAdapter(document).saveDocument(document);
57      }
58  
59      @Override
60      public <T> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys) {
61          return selectAdapter(clazz).findByPrimaryKey(clazz, primaryKeys);
62      }
63  
64      @Override
65      public <T> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey) {
66          return selectAdapter(clazz).findBySinglePrimaryKey(clazz, primaryKey);
67      }
68  
69      @Override
70      public void delete(Object dataObject) {
71          selectAdapter(dataObject).delete(dataObject);
72      }
73  
74      @Override
75      public void deleteMatching(Class<?> type, Map<String, ?> fieldValues) {
76          selectAdapter(type).deleteMatching(type, fieldValues);
77      }
78  
79      @Override
80      public <T> T retrieve(T dataObject) {
81          return selectAdapter(dataObject).retrieve(dataObject);
82      }
83  
84      @Override
85      public <T> Collection<T> findAll(Class<T> clazz) {
86          return selectAdapter(clazz).findAll(clazz);
87      }
88  
89      @Override
90      public <T> Collection<T> findMatching(Class<T> clazz, Map<String, ?> fieldValues) {
91          return selectAdapter(clazz).findMatching(clazz,fieldValues);
92      }
93  
94      @Override
95      public <T> Collection<T> findMatchingOrderBy(Class<T> clazz, Map<String, ?> fieldValues, String sortField,
96              boolean sortAscending) {
97          return selectAdapter(clazz).findMatchingOrderBy(clazz, fieldValues, sortField, sortAscending);
98      }
99  
100     @Override
101     public Map<String, ?> getPrimaryKeyFieldValues(Object dataObject) {
102         return selectAdapter(dataObject).getPrimaryKeyFieldValues(dataObject);
103     }
104 
105     @Override
106     public void retrieveNonKeyFields(Object persistableObject) {
107         selectAdapter(persistableObject).retrieveNonKeyFields(persistableObject);
108     }
109 
110     @Override
111     public void retrieveReferenceObject(Object persistableObject, String referenceObjectName) {
112         selectAdapter(persistableObject).retrieveReferenceObject(persistableObject, referenceObjectName);
113     }
114 
115     @Override
116     public void refreshAllNonUpdatingReferences(Object persistableObject) {
117         selectAdapter(persistableObject).refreshAllNonUpdatingReferences(persistableObject);
118     }
119 
120     @Override
121     public boolean isProxied(Object object) {
122         return selectAdapter(object).isProxied(object);
123     }
124 
125     @Override
126     public Object resolveProxy(Object object) {
127         return selectAdapter(object).resolveProxy(object);
128     }
129 
130     // Lookup methods
131 
132     @Override
133     public <T> Collection<T> findCollectionBySearchHelper(Class<T> dataObjectClass, Map<String, String> formProperties,
134             boolean unbounded, boolean allPrimaryKeyValuesPresentAndNotWildcard, Integer searchResultsLimit) {
135         return selectAdapter(dataObjectClass).findCollectionBySearchHelper(dataObjectClass, formProperties, unbounded,
136                 allPrimaryKeyValuesPresentAndNotWildcard, searchResultsLimit);
137     }
138 
139     @Override
140     public <T> Collection<T> findCollectionBySearchHelper(Class<T> dataObjectClass, Map<String, String> formProperties,
141             List<String> wildcardAsLiteralPropertyNames, boolean unbounded,
142             boolean allPrimaryKeyValuesPresentAndNotWildcard, Integer searchResultsLimit) {
143         return selectAdapter(dataObjectClass).findCollectionBySearchHelper(dataObjectClass, formProperties,
144                 wildcardAsLiteralPropertyNames, unbounded, allPrimaryKeyValuesPresentAndNotWildcard, searchResultsLimit);
145     }
146 
147     @Override
148     public <T> T findObjectBySearch(Class<T> type, Map<String, String> formProps) {
149         return selectAdapter(type).findObjectBySearch(type, formProps);
150     }
151 
152     @Override
153     public boolean allPrimaryKeyValuesPresentAndNotWildcard(Class<?> boClass, Map<String, String> formProps) {
154         return selectAdapter(boClass).allPrimaryKeyValuesPresentAndNotWildcard(boClass, formProps);
155     }
156 
157     @Override
158     public List<String> listPrimaryKeyFieldNames(Class<?> type) {
159         return selectAdapter(type).listPrimaryKeyFieldNames(type);
160     }
161 
162     @Override
163     public Class<?> determineCollectionObjectType(Class<?> containingType, String collectionPropertyName) {
164         return selectAdapter(containingType).determineCollectionObjectType(containingType, collectionPropertyName);
165     }
166 
167     @Override
168     public boolean hasReference(Class<?> boClass, String referenceName) {
169         return selectAdapter(boClass).hasReference(boClass, referenceName);
170     }
171 
172     @Override
173     public boolean hasCollection(Class<?> boClass, String collectionName) {
174         return selectAdapter(boClass).hasCollection(boClass, collectionName);
175     }
176 
177     @Override
178     public boolean isExtensionAttribute(Class<?> boClass, String attributePropertyName, Class<?> propertyType) {
179         return selectAdapter(boClass).isExtensionAttribute(boClass, attributePropertyName, propertyType);
180     }
181 
182     @Override
183     public Class<?> getExtensionAttributeClass(Class<?> boClass, String attributePropertyName) {
184         return selectAdapter(boClass).getExtensionAttributeClass(boClass, attributePropertyName);
185     }
186 
187     @Override
188     public Map<String, ?> getPrimaryKeyFieldValuesDOMDS(Object dataObject) {
189         return selectAdapter(dataObject).getPrimaryKeyFieldValuesDOMDS(dataObject);
190     }
191 
192     @Override
193     public boolean equalsByPrimaryKeys(Object do1, Object do2) {
194         return selectAdapter(do1).equalsByPrimaryKeys(do1, do2);
195     }
196 
197     @Override
198     public PersistableBusinessObject toPersistableBusinessObject(Object object) {
199         return selectAdapter(object).toPersistableBusinessObject(object);
200     }
201 
202     @Override
203     public void materializeAllSubObjects(Object object) {
204         selectAdapter(object).materializeAllSubObjects(object);
205     }
206 
207     @Override
208     public Class<?> getPropertyType(Object object, String propertyName) {
209         return selectAdapter(object).getPropertyType(object, propertyName);
210     }
211 
212     @Override
213     public PersistableBusinessObjectExtension getExtension(
214             Class<? extends PersistableBusinessObject> businessObjectClass) throws InstantiationException, IllegalAccessException {
215         return selectAdapter(businessObjectClass).getExtension(businessObjectClass);
216     }
217 
218     @Override
219     public void refreshReferenceObject(PersistableBusinessObject businessObject, String referenceObjectName) {
220         selectAdapter(businessObject).refreshReferenceObject(businessObject, referenceObjectName);
221     }
222 
223     @Override
224     public boolean isLockable(Object object) {
225         return selectAdapter(object).isLockable(object);
226     }
227 
228     @Override
229     public void verifyVersionNumber(Object dataObject) {
230         selectAdapter(dataObject).verifyVersionNumber(dataObject);
231     }
232 
233     @Override
234     public RemotableQuickFinder.Builder createQuickFinder(Class<?> containingClass, String attributeName) {
235         return selectAdapter(containingClass).createQuickFinder(containingClass, attributeName);
236     }
237 
238     @Override
239     public boolean isReferenceUpdatable(Class<?> type, String referenceName) {
240         return selectAdapter(type).isReferenceUpdatable(type, referenceName);
241     }
242 
243     @Override
244     @SuppressWarnings("rawtypes")
245     public Map<String, Class> listReferenceObjectFields(Class<?> type) {
246         return selectAdapter(type).listReferenceObjectFields(type);
247     }
248 
249     @Override
250     public boolean isCollectionUpdatable(Class<?> type, String collectionName) {
251         return selectAdapter(type).isCollectionUpdatable(type, collectionName);
252     }
253 
254     @Override
255     @SuppressWarnings("rawtypes")
256     public Map<String, Class> listCollectionObjectTypes(Class<?> type) {
257         return selectAdapter(type).listCollectionObjectTypes(type);
258     }
259 
260     @Override
261     public BusinessObject getReferenceIfExists(BusinessObject bo, String referenceName) {
262         return selectAdapter(bo).getReferenceIfExists(bo, referenceName);
263     }
264 
265     @Override
266     public boolean allForeignKeyValuesPopulatedForReference(PersistableBusinessObject bo, String referenceName) {
267         return selectAdapter(bo).allForeignKeyValuesPopulatedForReference(bo, referenceName);
268     }
269 
270     @Override
271     public RelationshipDefinition getDictionaryRelationship(Class<?> c, String attributeName) {
272         return selectAdapter(c).getDictionaryRelationship(c, attributeName);
273     }
274 
275     @Override
276     public String getTitleAttribute(Class<?> dataObjectClass) {
277         return selectAdapter(dataObjectClass).getTitleAttribute(dataObjectClass);
278     }
279 
280     @Override
281     public boolean areNotesSupported(Class<?> dataObjectClass) {
282         return selectAdapter(dataObjectClass).areNotesSupported(dataObjectClass);
283     }
284 
285     @Override
286     public String getDataObjectIdentifierString(Object dataObject) {
287         return selectAdapter(dataObject).getDataObjectIdentifierString(dataObject);
288     }
289 
290     @Override
291     public Class<?> getInquiryObjectClassIfNotTitle(Object dataObject, String propertyName) {
292         return selectAdapter(dataObject).getInquiryObjectClassIfNotTitle(dataObject, propertyName);
293     }
294 
295     @Override
296     public Map<String, String> getInquiryParameters(Object dataObject, List<String> keys, String propertyName) {
297         return selectAdapter(dataObject).getInquiryParameters(dataObject, keys, propertyName);
298     }
299 
300     @Override
301     public boolean hasLocalLookup(Class<?> dataObjectClass) {
302         return selectAdapter(dataObjectClass).hasLocalLookup(dataObjectClass);
303     }
304 
305     @Override
306     public boolean hasLocalInquiry(Class<?> dataObjectClass) {
307         return selectAdapter(dataObjectClass).hasLocalInquiry(dataObjectClass);
308     }
309 
310     @Override
311     public org.kuali.rice.krad.bo.DataObjectRelationship getDataObjectRelationship(Object dataObject,
312             Class<?> dataObjectClass, String attributeName, String attributePrefix, boolean keysOnly,
313             boolean supportsLookup, boolean supportsInquiry) {
314         return selectAdapter(dataObjectClass).getDataObjectRelationship(dataObject, dataObjectClass, attributeName,
315                     attributePrefix, keysOnly, supportsLookup, supportsInquiry);
316     }
317 
318     @Override
319     public boolean isPersistable(Class<?> dataObjectClass) {
320         return selectAdapter(dataObjectClass).isPersistable(dataObjectClass);
321     }
322 
323 
324     @Override
325     public ForeignKeyFieldsPopulationState getForeignKeyFieldsPopulationState(Object dataObject, String referenceName) {
326         return selectAdapter(dataObject).getForeignKeyFieldsPopulationState(dataObject, referenceName);
327     }
328 
329     @Override
330     public Map<String, String> getForeignKeysForReference(Class<?> clazz, String attributeName) {
331         return selectAdapter(clazz).getForeignKeysForReference(clazz, attributeName);
332     }
333 
334     @Override
335     public boolean hasPrimaryKeyFieldValues(Object dataObject) {
336         return selectAdapter(dataObject).hasPrimaryKeyFieldValues(dataObject);
337     }
338 
339     @Override
340     public void setObjectPropertyDeep(Object bo, String propertyName, Class type,
341             Object propertyValue) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
342         selectAdapter(bo).setObjectPropertyDeep(bo, propertyName, type, propertyValue);
343     }
344 
345     @Override
346     @SuppressWarnings("rawtypes")
347     public Class materializeClassForProxiedObject(Object object){
348         return selectAdapter(object).materializeClassForProxiedObject(object);
349     }
350 
351     @Override
352     public Object getNestedValue(Object bo, String fieldName){
353         return selectAdapter(bo).getNestedValue(bo, fieldName);
354     }
355 
356     @Override
357     @SuppressWarnings("rawtypes")
358     public Object createNewObjectFromClass(Class clazz){
359         return selectAdapter(clazz).createNewObjectFromClass(clazz);
360     }
361 
362     @Override
363     public boolean isNull(Object object){
364         return selectAdapter(object).isNull(object);
365     }
366 
367     @Override
368     public void setObjectProperty(Object bo, String propertyName, Class propertyType,
369             Object propertyValue) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
370         selectAdapter(bo).setObjectProperty(bo,propertyName,propertyType,propertyValue);
371     }
372 
373     @Override
374     public <T extends Document> T findByDocumentHeaderId(Class<T> documentClass, String id) {
375         return selectAdapter(documentClass).findByDocumentHeaderId(documentClass, id);
376     }
377 
378     @Override
379     public <T extends Document> List<T> findByDocumentHeaderIds(Class<T> documentClass, List<String> ids) {
380         return selectAdapter(documentClass).findByDocumentHeaderIds(documentClass, ids);
381     }
382 
383     protected LegacyDataAdapter selectAdapter(Object dataObject) {
384         if (LegacyUtils.isKnsEnabled() && (dataObject instanceof Class) && LegacyUtils.useLegacy((Class<?>)dataObject)) {
385             return getKnsLegacyDataAdapter();
386         } else if(LegacyUtils.isKnsEnabled() && !(dataObject instanceof Class) && LegacyUtils.useLegacyForObject(dataObject)){
387             return getKnsLegacyDataAdapter();
388         } else {
389             return getKradLegacyDataAdapter();
390         }
391 
392     }
393 
394     public LegacyDataAdapter getKradLegacyDataAdapter() {
395         return kradLegacyDataAdapter;
396     }
397 
398     public void setKradLegacyDataAdapter(LegacyDataAdapter kradLegacyDataAdapter) {
399         this.kradLegacyDataAdapter = kradLegacyDataAdapter;
400     }
401 
402     public LegacyDataAdapter getKnsLegacyDataAdapter() {
403         return knsLegacyDataAdapter;
404     }
405 
406     public void setKnsLegacyDataAdapter(LegacyDataAdapter knsLegacyDataAdapter) {
407         this.knsLegacyDataAdapter = knsLegacyDataAdapter;
408     }
409 
410 }
411