001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.data.jpa.converters; 017 018import java.math.BigDecimal; 019 020import javax.persistence.AttributeConverter; 021import javax.persistence.Converter; 022 023import org.kuali.rice.core.api.util.type.KualiPercent; 024 025/** 026 * Converts the custom {@link KualiPercent} objects for OJB by converting them to/from {@link BigDecimal}. 027 */ 028@Converter( 029 autoApply = true) 030public class KualiPercentConverter implements AttributeConverter<KualiPercent, BigDecimal> { 031 032 /** 033 * {@inheritDoc} 034 * 035 * This implementation will convert from a {@link KualiPercent} to a {@link BigDecimal}. 036 */ 037 @Override 038 public BigDecimal convertToDatabaseColumn(KualiPercent objectValue) { 039 if (objectValue == null) { 040 return null; 041 } 042 return objectValue.bigDecimalValue(); 043 } 044 045 /** 046 * {@inheritDoc} 047 * 048 * This implementation will convert from a {@link BigDecimal} to a {@link KualiPercent}. 049 */ 050 @Override 051 public KualiPercent convertToEntityAttribute(BigDecimal dataValue) { 052 if (dataValue == null) { 053 return null; 054 } 055 return new KualiPercent(dataValue); 056 } 057}