Coverage Report - org.kuali.rice.krad.service.impl.PersistenceServiceImplBase
 
Classes in this File Line Coverage Branch Coverage Complexity
PersistenceServiceImplBase
0%
0/25
0%
0/6
6
 
 1  
 /*
 2  
  * Copyright 2006-2007 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  
 
 28  0
 public class PersistenceServiceImplBase extends PersistenceServiceStructureImplBase {
 29  
 
 30  
         /**
 31  
          * @see org.kuali.rice.krad.service.PersistenceMetadataService#getPrimaryKeyFields(java.lang.Object)
 32  
          */
 33  
         public Map getPrimaryKeyFieldValues(Object persistableObject) {
 34  0
                 return getPrimaryKeyFieldValues(persistableObject, false);
 35  
         }
 36  
 
 37  
         /**
 38  
          * @see org.kuali.rice.krad.service.PersistenceMetadataService#getPrimaryKeyFields(java.lang.Object,
 39  
          *      boolean)
 40  
          */
 41  
         public Map getPrimaryKeyFieldValues(Object persistableObject, boolean sortFieldNames) {
 42  0
                 if (persistableObject == null) {
 43  0
                         throw new IllegalArgumentException("invalid (null) persistableObject");
 44  
                 }
 45  
 
 46  0
                 Map keyValueMap = null;
 47  0
                 if (sortFieldNames) {
 48  0
                         keyValueMap = new TreeMap();
 49  
                 } else {
 50  0
                         keyValueMap = new HashMap();
 51  
                 }
 52  
 
 53  0
                 String className = null;
 54  0
                 String fieldName = null;
 55  
                 try {
 56  0
                         List fields = listPrimaryKeyFieldNames(persistableObject.getClass());
 57  0
                         for (Iterator i = fields.iterator(); i.hasNext();) {
 58  0
                                 fieldName = (String) i.next();
 59  0
                                 className = persistableObject.getClass().getName();
 60  0
                                 Object fieldValue = PropertyUtils.getSimpleProperty(persistableObject, fieldName);
 61  
 
 62  0
                                 keyValueMap.put(fieldName, fieldValue);
 63  0
                         }
 64  0
                 } catch (IllegalAccessException e) {
 65  0
                         throw new IntrospectionException("problem accessing property '" + className + "." + fieldName + "'", e);
 66  0
                 } catch (NoSuchMethodException e) {
 67  0
                         throw new IntrospectionException("unable to invoke getter for property '" + className + "." + fieldName + "'", e);
 68  0
                 } catch (InvocationTargetException e) {
 69  0
                         throw new IntrospectionException("problem invoking getter for property '" + className + "." + fieldName + "'", e);
 70  0
                 }
 71  
 
 72  0
                 return keyValueMap;
 73  
         }
 74  
 
 75  
 }