package com.megatim.fdxconvert.converter;
|
|
import com.megatim.fdxconvert.enums.DataType;
|
import java.util.stream.Stream;
|
import javax.persistence.AttributeConverter;
|
import javax.persistence.Converter;
|
|
/**
|
*
|
* @author STEPHANIE
|
*/
|
@Converter(autoApply = true)
|
public class DataTypeConverter implements AttributeConverter<DataType, String> {
|
|
@Override
|
public String convertToDatabaseColumn(DataType dataType) {
|
if (dataType == null) {
|
return null;
|
}
|
|
return dataType.getDataType();
|
}
|
|
@Override
|
public DataType convertToEntityAttribute(String dataType) {
|
if (dataType == null) {
|
return null;
|
}
|
|
return Stream.of(DataType.values())
|
.filter(c -> c.getDataType().equals(dataType))
|
.findFirst()
|
.orElseThrow(IllegalArgumentException::new);
|
}
|
|
}
|