package io.ebeaninternal.server.type;
import javax.persistence.EnumType;
import java.sql.SQLException;
import java.sql.Types;
import java.time.DayOfWeek;
public class ScalarTypeDayOfWeek extends ScalarTypeEnumWithMapping {
static final EnumToDbIntegerMap beanDbMap = new EnumToDbIntegerMap();
static {
DayOfWeek[] values = DayOfWeek.values();
for (DayOfWeek value : values) {
beanDbMap.add(value, value.getValue(), value.name());
}
}
public ScalarTypeDayOfWeek() {
super(beanDbMap, DayOfWeek.class, 1);
}
@Override
public boolean isOverrideBy(EnumType type) {
return type != null;
}
@Override
public void bind(DataBind b, Object value) throws SQLException {
if (value == null) {
b.setNull(Types.INTEGER);
} else {
b.setInt(((DayOfWeek) value).getValue());
}
}
@Override
public Object read(DataReader dataReader) throws SQLException {
Integer i = dataReader.getInt();
if (i == null) {
return null;
} else {
return DayOfWeek.of(i);
}
}
}