001package org.kuali.kpme.edo.util;
002
003import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
004
005import java.math.BigDecimal;
006
007/**
008 * $HeadURL$
009 * $Revision$
010 * Created with IntelliJ IDEA.
011 * User: bradleyt
012 * Date: 12/13/12
013 * Time: 9:34 AM
014 * To change this template use File | Settings | File Templates.
015 */
016public class Bool2BigDecimalOJBConversion implements FieldConversion {
017
018        private static BigDecimal I_TRUE = new BigDecimal(1);
019        private static BigDecimal I_FALSE = new BigDecimal(0);
020
021        private static Boolean B_TRUE = new Boolean(true);
022        private static Boolean B_FALSE = new Boolean(false);
023
024        /**
025         * @see FieldConversion#javaToSql(Object)
026         */
027        public Object javaToSql(Object source)
028        {
029            if (source instanceof Boolean)
030            {
031                if (source.equals(B_TRUE))
032                {
033                    return I_TRUE;
034                }
035                else
036                {
037                    return I_FALSE;
038                }
039            }
040            else
041            {
042                return source;
043            }
044        }
045
046        /**
047         * @see FieldConversion#sqlToJava(Object)
048         */
049        public Object sqlToJava(Object source)
050        {
051            if (source instanceof BigDecimal)
052            {
053                if (source.equals(I_TRUE))
054                {
055                    return B_TRUE;
056                }
057                else
058                {
059                    return B_FALSE;
060                }
061            }
062            else
063            {
064                return source;
065            }
066        }
067}