protected static Column syncColumn(MetaDataContext context, Column col,
int num, boolean forceJDBCType, Table colTable, Table targetTable,
Object target, boolean inverse) {
// use full name for cols that aren't in the expected table, or that
// are inverse joins
DBDictionary dict = ((MappingRepository) context.getRepository()).
getDBDictionary();
Column copy = new Column();
if (col.getTable() != colTable || inverse)
copy.setName(dict.getFullName(col.getTable(), true)
+ "." + col.getName());
else
copy.setName(col.getName());
// set target if not default
if (target != null) {
if (target == NULL)
copy.setTarget("null");
else if (target instanceof Column) {
Column tcol = (Column) target;
if ((!inverse && tcol.getTable() != targetTable)
|| (inverse && tcol.getTable() != colTable))
copy.setTarget(dict.getFullName(tcol.getTable(), true)
+ "." + tcol.getName());
else if (!defaultTarget(col, tcol, num))
copy.setTarget(tcol.getName());
} else if (target instanceof Number)
copy.setTarget(target.toString());
else
copy.setTarget("'" + target + "'");
} else if (num > 1)
copy.setTargetField(col.getTargetField());
if (col.getSize() != 0 && col.getSize() != dict.characterColumnSize
&& (col.getSize() != -1 || !col.isLob()))
copy.setSize(col.getSize());
if (col.getDecimalDigits() != 0)
copy.setDecimalDigits(col.getDecimalDigits());
if (col.getDefaultString() != null)
copy.setDefaultString(col.getDefaultString());
if (col.isNotNull() && !col.isPrimaryKey()
&& (!isPrimitive(col.getJavaType()) || isForeignKey(col)))
copy.setNotNull(true);
// set type name if not default
String typeName = col.getTypeName();
if (typeName != null || copy.getSize() != 0
|| copy.getDecimalDigits() != 0) {
// is this the dict default type? have to ensure jdbc-type set
// prior to finding dict default
copy.setType(col.getType());
String defName = dict.getTypeName(copy);
copy.setType(Types.OTHER);
// copy should not have size info set if it isn't used in type name
boolean defSized = defName.indexOf('(') != -1;
if (!defSized) {
if (copy.getSize() > 0)
copy.setSize(0);
copy.setDecimalDigits(0);
}
if (typeName != null) {
// make sure to strip size for comparison
if (typeName.indexOf('(') == -1 && defSized)
defName = defName.substring(0, defName.indexOf('('));
if (!typeName.equalsIgnoreCase(defName))
copy.setTypeName(typeName);
}
}
// set jdbc-type if not default or if forced
if (forceJDBCType
|| (target != null && !(target instanceof Column)
&& col.getType() != Types.VARCHAR)
|| dict.getJDBCType(col.getJavaType(), false) != col.getType())
copy.setType(col.getType());
return copy;
}