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.lang.reflect.InvocationTargetException;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.TreeMap;
24
25 import org.apache.commons.beanutils.PropertyUtils;
26 import org.kuali.rice.krad.exception.IntrospectionException;
27 import org.kuali.rice.krad.util.LegacyDataFramework;
28
29 @Deprecated
30 @LegacyDataFramework
31 public class PersistenceServiceImplBase extends PersistenceServiceStructureImplBase {
32
33
34
35
36 public Map getPrimaryKeyFieldValues(Object persistableObject) {
37 return getPrimaryKeyFieldValues(persistableObject, false);
38 }
39
40
41
42
43
44 public Map getPrimaryKeyFieldValues(Object persistableObject, boolean sortFieldNames) {
45 if (persistableObject == null) {
46 throw new IllegalArgumentException("invalid (null) persistableObject");
47 }
48
49 Map keyValueMap = null;
50 if (sortFieldNames) {
51 keyValueMap = new TreeMap();
52 } else {
53 keyValueMap = new HashMap();
54 }
55
56 String className = null;
57 String fieldName = null;
58 try {
59 List fields = listPrimaryKeyFieldNames(persistableObject.getClass());
60 for (Iterator i = fields.iterator(); i.hasNext();) {
61 fieldName = (String) i.next();
62 className = persistableObject.getClass().getName();
63 Object fieldValue = PropertyUtils.getSimpleProperty(persistableObject, fieldName);
64
65 keyValueMap.put(fieldName, fieldValue);
66 }
67 } catch (IllegalAccessException e) {
68 throw new IntrospectionException("problem accessing property '" + className + "." + fieldName + "'", e);
69 } catch (NoSuchMethodException e) {
70 throw new IntrospectionException("unable to invoke getter for property '" + className + "." + fieldName + "'", e);
71 } catch (InvocationTargetException e) {
72 throw new IntrospectionException("problem invoking getter for property '" + className + "." + fieldName + "'", e);
73 }
74
75 return keyValueMap;
76 }
77
78 }