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