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.KualiDecimal; 024 025/** 026 * Converts the custom {@link KualiDecimal} objects for OJB by converting them to/from {@link BigDecimal}. 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030@Converter( 031 autoApply = true) 032public class KualiDecimalConverter implements AttributeConverter<KualiDecimal, BigDecimal> { 033 034 /** 035 * {@inheritDoc} 036 * 037 * This implementation will convert from a {@link KualiDecimal} to a {@link BigDecimal}. 038 */ 039 @Override 040 public BigDecimal convertToDatabaseColumn(KualiDecimal objectValue) { 041 if (objectValue == null) { 042 return null; 043 } 044 return objectValue.bigDecimalValue(); 045 } 046 047 /** 048 * {@inheritDoc} 049 * 050 * This implementation will convert from a {@link BigDecimal} to a {@link KualiDecimal}. 051 */ 052 @Override 053 public KualiDecimal convertToEntityAttribute(BigDecimal dataValue) { 054 if (dataValue == null) { 055 return null; 056 } 057 return new KualiDecimal(dataValue); 058 } 059}