private AmberColumn createColumn(AmberType amberType)
throws ConfigException
{
String name = _column.getName();
AmberColumn column = null;
if (_sourceType instanceof EntityType) {
EntityType entityType = (EntityType) _sourceType;
String tableName = _column.getTable();
AmberTable table;
if (tableName.equals("")) {
table = entityType.getTable();
if (table == null)
throw error(_field, L.l("{0} @Column(name='{1}') is an unknown table.",
_fieldName,
name));
}
else {
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 { // embeddable
column = new AmberColumn(null, name, amberType);
}
// primaryKey = column.primaryKey();
column.setUnique(_column.isUnique());
column.setNotNull(! _column.isNullable());
//insertable = column.insertable();
//updateable = column.updatable();
if (! "".equals(_column.getColumnDefinition()))
column.setSQLType(_column.getColumnDefinition());
column.setLength(_column.getLength());
int precision = _column.getPrecision();
if (precision < 0) {
throw error(_field, L.l("{0} @Column precision cannot be less than 0.",
_fieldName));
}
int scale = _column.getScale();
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 (precision < scale) {
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;
}