else if (columnConfig != null && ! columnConfig.getName().equals(""))
name = columnConfig.getName();
else
name = toSqlName(fieldName);
AmberColumn column = null;
if (entityType == null) { // embeddable
column = new AmberColumn(null, name, amberType);
}
else if (columnAnn != null && ! columnAnn.table().equals("")) {
String tableName = columnAnn.table();
AmberTable table;
table = entityType.getSecondaryTable(tableName);
if (table == null)
throw error(field, L.l("{0} @Column(table='{1}') is an unknown secondary table.",
fieldName,
tableName));
column = table.createColumn(name, amberType);
}
else if (entityType.getTable() != null)
column = entityType.getTable().createColumn(name, amberType);
else { // jpa/0ge2: MappedSuperclassType
column = new AmberColumn(null, name, amberType);
}
if (column != null && columnAnn != null) {
// primaryKey = column.primaryKey();
column.setUnique(columnAnn.unique());
column.setNotNull(! columnAnn.nullable());
//insertable = column.insertable();
//updateable = column.updatable();
if (! "".equals(columnAnn.columnDefinition()))
column.setSQLType(columnAnn.columnDefinition());
column.setLength(columnAnn.length());
int precision = columnAnn.precision();
if (precision < 0) {
throw error(field, L.l("{0} @Column precision cannot be less than 0.",
fieldName));
}
int scale = columnAnn.scale();
if (scale < 0) {
throw error(field, L.l("{0} @Column scale cannot be less than 0.",
fieldName));
}
// this test implicitly works for case where
// precision is not set explicitly (ie: set to 0 by default)
// and scale is set
if (scale > precision) {
throw error(field, L.l("{0} @Column scale cannot be greater than precision. Must set precision to a non-zero value before setting scale.",
fieldName));
}
if (precision > 0) {
column.setPrecision(precision);
column.setScale(scale);
}
}
return column;
}