Support the specification of default values for columns.
This commit is contained in:
@@ -178,11 +178,13 @@ public abstract class FieldMarshaller
|
||||
int length = 255;
|
||||
boolean nullable = false;
|
||||
boolean unique = false;
|
||||
String defval = "";
|
||||
Column column = _field.getAnnotation(Column.class);
|
||||
if (column != null) {
|
||||
nullable = column.nullable();
|
||||
unique = column.unique();
|
||||
length = column.length();
|
||||
defval = column.defaultValue();
|
||||
if (!StringUtil.isBlank(column.name())) {
|
||||
_columnName = column.name();
|
||||
}
|
||||
@@ -219,6 +221,11 @@ public abstract class FieldMarshaller
|
||||
if (unique) {
|
||||
builder.append(" UNIQUE");
|
||||
}
|
||||
|
||||
// append the default value if one was specified
|
||||
if (defval.length() > 0) {
|
||||
builder.append(" DEFAULT ").append(defval);
|
||||
}
|
||||
}
|
||||
|
||||
// handle primary keyness
|
||||
|
||||
@@ -62,4 +62,11 @@ public @interface Column
|
||||
* The column length. (Applies to String and byte[] columns.)
|
||||
*/
|
||||
int length () default 255;
|
||||
|
||||
/**
|
||||
* The SQL literal value to be used when defining this column's default value. The value must
|
||||
* be quoted and escaped if it is not a SQL primitive datatype. For example:
|
||||
* <code>'2006-01-01'</code> or <code>25</code> or <code>NULL</code>.
|
||||
*/
|
||||
String defaultValue () default "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user