1 /** 2 * Copyright 2005-2015 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.data.jpa.converters; 17 18 import javax.persistence.AttributeConverter; 19 import javax.persistence.Converter; 20 21 /** 22 * Converts active/inactive represented by the characters "A" and "I" to and from true and false. 23 * 24 * <p>The conversion treats the values as follows: "A" is true and "I" is false.</p> 25 * 26 * @author Kuali Rice Team (rice.collab@kuali.org) 27 */ 28 @Converter 29 public class BooleanAIConverter implements AttributeConverter<Boolean, String> { 30 31 /** 32 * {@inheritDoc} 33 * 34 * This implementation will convert from a false or true value to an "I" or "A" value. 35 */ 36 @Override 37 public String convertToDatabaseColumn(Boolean objectValue) { 38 if (objectValue == null) { 39 return "I"; 40 } 41 return objectValue ? "A" : "I"; 42 } 43 44 /** 45 * {@inheritDoc} 46 * 47 * This implementation will convert from an "I" or "A" value to a false or true value. 48 */ 49 @Override 50 public Boolean convertToEntityAttribute(String dataValue) { 51 if (dataValue == null) { 52 return false; 53 } 54 return dataValue.equals("A"); 55 } 56 }