
com.jk.data.dataaccess.orm.util.JKBooleanConverter Maven / Gradle / Ivy
/*
* Copyright 2002-2022 Dr. Jalal Kiswani.
* Email: [email protected]
* Check out https://smart-api.com for more details
*
* All the opensource projects of Dr. Jalal Kiswani are free for personal and academic use only,
* for commercial usage and support, please contact the author.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jk.data.dataaccess.orm.util;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
// TODO: Auto-generated Javadoc
/**
* The Class JKBooleanConverter.
*/
@Converter
public class JKBooleanConverter implements AttributeConverter {
/** The true string. */
private String trueString;
/** The false string. */
private String falseString;
/**
* Instantiates a new JK boolean converter.
*/
public JKBooleanConverter() {
this("1","0");
}
/**
* Instantiates a new JK boolean converter.
*
* @param trueString the true string
* @param falseString the false string
*/
public JKBooleanConverter(String trueString, String falseString) {
this.trueString = trueString;
this.falseString = falseString;
}
/**
* Convert to database column.
*
* @param value the value
* @return the string
*/
@Override
public String convertToDatabaseColumn(Boolean value) {
if (value == null) {
return falseString;
} else {
return value ? trueString: falseString;
}
}
/**
* Convert to entity attribute.
*
* @param value the value
* @return the boolean
*/
@Override
public Boolean convertToEntityAttribute(String value) {
if (value == null)
return false;
return value.equalsIgnoreCase(trueString) ? true : false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy