Support the specification of default values for columns.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1995 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2006-12-11 21:34:11 +00:00
parent cf48a6a9eb
commit 4635caadea
2 changed files with 14 additions and 0 deletions
@@ -178,11 +178,13 @@ public abstract class FieldMarshaller
int length = 255; int length = 255;
boolean nullable = false; boolean nullable = false;
boolean unique = false; boolean unique = false;
String defval = "";
Column column = _field.getAnnotation(Column.class); Column column = _field.getAnnotation(Column.class);
if (column != null) { if (column != null) {
nullable = column.nullable(); nullable = column.nullable();
unique = column.unique(); unique = column.unique();
length = column.length(); length = column.length();
defval = column.defaultValue();
if (!StringUtil.isBlank(column.name())) { if (!StringUtil.isBlank(column.name())) {
_columnName = column.name(); _columnName = column.name();
} }
@@ -219,6 +221,11 @@ public abstract class FieldMarshaller
if (unique) { if (unique) {
builder.append(" UNIQUE"); builder.append(" UNIQUE");
} }
// append the default value if one was specified
if (defval.length() > 0) {
builder.append(" DEFAULT ").append(defval);
}
} }
// handle primary keyness // handle primary keyness
@@ -62,4 +62,11 @@ public @interface Column
* The column length. (Applies to String and byte[] columns.) * The column length. (Applies to String and byte[] columns.)
*/ */
int length () default 255; 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 "";
} }