if(field.getAnnotation(Text.class) != null) {
columnType = Types.LONGVARCHAR;
} else {
columnType = Types.VARCHAR;
Max max = field.getAnnotation(Max.class);
if(max == null){
//throw new SienaRestrictedApiException(DB, "createColumn", "Field "+field.getName()+" in class "
// +clazz.getName()+" doesn't have a @Max annotation");
// default is 255 chars as in hibernate
column.setSize("255");
}
else column.setSize(""+max.value());
}
}
else if(type == Boolean.class || type == Boolean.TYPE) columnType = Types.BOOLEAN;
else if(type == Date.class) {
if(field.getAnnotation(DateTime.class) != null)
columnType = Types.TIMESTAMP;
else if(field.getAnnotation(Time.class) != null)
columnType = Types.TIME;
else if(field.getAnnotation(SimpleDate.class) != null)
columnType = Types.DATE;
else
columnType = Types.TIMESTAMP;
} else if(type == Json.class) {
columnType = Types.LONGVARCHAR;
} else if(type == byte[].class){
columnType = Types.BLOB;
} else if(Enum.class.isAssignableFrom(type)){
// enums are stored as string
columnType = Types.VARCHAR;
Max max = field.getAnnotation(Max.class);
if(max == null)
column.setSize(""+255); // fixes by default to this value in order to prevent alter tables every time
else column.setSize(""+max.value());
} else if(type == BigDecimal.class){
DecimalPrecision an = field.getAnnotation(DecimalPrecision.class);
if(an == null) {
columnType = Types.DECIMAL;
column.setSizeAndScale(19, 2);