Kenmegne
6 days ago 908e81dd173f380879d5fabeb5794d5b7a76df0e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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);
    }
 
}