javax.persistence.BooleanToStringYNConverter Maven / Gradle / Ivy
package javax.persistence;
@Converter
public class BooleanToStringYNConverter implements AttributeConverter {
public static final AttributeConverter INSTANCE = new BooleanToStringYNConverter();
private final boolean nullable;
public BooleanToStringYNConverter() {
this(true);
}
public BooleanToStringYNConverter(boolean nullable) {
this.nullable = nullable;
}
@Override
public String convertToDatabaseColumn(Boolean attribute) {
if (attribute == null) {
return this.nullable ? null : "N";
}
return attribute ? "Y" : "N";
}
@Override
public Boolean convertToEntityAttribute(String dbData) {
if (dbData == null) {
return this.nullable ? null : false;
}
return "Y".equalsIgnoreCase(dbData) ? true : false;
}
}