提交 78199bd1 authored 作者: Thomas Mueller's avatar Thomas Mueller

JaQu: the maximum length of a column can now be defined using maxLength.

上级 d2448d9f
...@@ -26,6 +26,11 @@ public class Define { ...@@ -26,6 +26,11 @@ public class Define {
currentTableDefinition.addIndex(columns); currentTableDefinition.addIndex(columns);
} }
public static void maxLength(Object column, int length) {
checkInDefine();
currentTableDefinition.setMaxLength(column, length);
}
public static void tableName(String tableName) { public static void tableName(String tableName) {
currentTableDefinition.setTableName(tableName); currentTableDefinition.setTableName(tableName);
} }
......
...@@ -45,6 +45,7 @@ class TableDefinition<T> { ...@@ -45,6 +45,7 @@ class TableDefinition<T> {
String columnName; String columnName;
Field field; Field field;
String dataType; String dataType;
int maxLength;
Object getValue(Object obj) { Object getValue(Object obj) {
try { try {
...@@ -119,6 +120,16 @@ class TableDefinition<T> { ...@@ -119,6 +120,16 @@ class TableDefinition<T> {
index.columnNames = mapColumnNames(columns); index.columnNames = mapColumnNames(columns);
indexes.add(index); indexes.add(index);
} }
public void setMaxLength(Object column, int maxLength) {
String columnName = getColumnName(column);
for (FieldDefinition f: fields) {
if (f.columnName.equals(columnName)) {
f.maxLength = maxLength;
break;
}
}
}
void mapFields() { void mapFields() {
Field[] classFields = clazz.getFields(); Field[] classFields = clazz.getFields();
...@@ -186,6 +197,11 @@ class TableDefinition<T> { ...@@ -186,6 +197,11 @@ class TableDefinition<T> {
buff.append(field.columnName); buff.append(field.columnName);
buff.append(' '); buff.append(' ');
buff.append(field.dataType); buff.append(field.dataType);
if (field.maxLength != 0) {
buff.append('(');
buff.append(field.maxLength);
buff.append(')');
}
} }
if (primaryKeyColumnNames != null) { if (primaryKeyColumnNames != null) {
buff.append(", PRIMARY KEY("); buff.append(", PRIMARY KEY(");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论