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.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  	 * @see org.kuali.rice.krad.service.PersistenceMetadataService#getPrimaryKeyFields(java.lang.Object)
35  	 */
36  	public Map getPrimaryKeyFieldValues(Object persistableObject) {
37  		return getPrimaryKeyFieldValues(persistableObject, false);
38  	}
39  
40  	/**
41  	 * @see org.kuali.rice.krad.service.PersistenceMetadataService#getPrimaryKeyFields(java.lang.Object,
42  	 *      boolean)
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  }