net.yadaframework.persistence.YadaMoneyConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yadaweb Show documentation
Show all versions of yadaweb Show documentation
Some useful tasks for the Yada Framework
package net.yadaframework.persistence;
import jakarta.persistence.AttributeConverter;
/**
* JPA converter between Object representation "YadaMoney" and DB column "Long"
*
*/
public class YadaMoneyConverter implements AttributeConverter {
@Override
public Long convertToDatabaseColumn(YadaMoney attribute) {
if (attribute==null) {
return 0l;
}
return attribute.getInternalValue();
}
@Override
public YadaMoney convertToEntityAttribute(Long dbData) {
if (dbData==null) {
dbData = 0l;
}
YadaMoney result = YadaMoney.fromDatabaseColumn(dbData);
return result;
}
}