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