metaclass.setDescription(table.getDescription());
for (int i = 0; i < table.getColumnCount(); ++i)
{
final Column column = table.getColumn(i);
final Attribute attribute = new Attribute(getAttributeName(column.getName(), metaclass));
boolean bRequired = !column.isNullable() && column.getType() != Primitive.STRING;
if (bRequired)
{
Component component = column.getConverter();
if (component != null)
{
try
{
bRequired = (((Converter)component.getInstance(null)).getInverseFunction().invoke(null) == null);
}
catch (Throwable e)
{
// Still required if an error occurs
}
}
}
attribute.setDescription(column.getDescription());
attribute.setMetaclass(metaclass);
attribute.setDeclarator(metaclass);
attribute.setRootDeclarator(metaclass);
attribute.setType(column.getType());
attribute.setRequired(bRequired);
attribute.setOrdinal(metaclass.getAttributeCount());
metaclass.addAttribute(attribute);
final RelationalPrimitiveMapping mapping = new RelationalPrimitiveMapping();
mapping.setColumn(column);
mapping.setAttribute(attribute);
fixupList2.add(new Fixup()
{
public void fixup()
{
relationalMapping.addAttributeMapping(mapping);
}
});
}
for (int i = 0; i < table.getRelatedKeyCount(); ++i)
{
final Index index = table.getRelatedKey(i);
if (!index.getTable().isAspect())
{
final Index primaryKey = table.getPrimaryKey();
final String sClassName = getClassName(index.getTable().getTableName(), sPrefix, nameMap);
final Attribute attribute = new Attribute(getAttributeName(sClassName, metaclass));
attribute.setMetaclass(metaclass);
attribute.setDeclarator(metaclass);
attribute.setRootDeclarator(metaclass);
attribute.setCollection(true);
attribute.setOrdinal(metaclass.getAttributeCount());
metaclass.addAttribute(attribute);
final RelationalClassMapping mapping = new RelationalClassMapping();
mapping.setAttribute(attribute);
mapping.setSourceKey(primaryKey);
mapping.setDestinationKey(index);
fixupList.add(new Fixup()
{
public void fixup()
{
final Metaclass mc = getMetadata().getMetaclass(sClassName);
attribute.setType(mc);
mapping.setMapping(mc.getPersistenceMapping());
Attribute a = new Attribute(getAttributeName(metaclass.getName(), mc));
a.setMetaclass(mc);
a.setDeclarator(mc);
a.setRootDeclarator(mc);
a.setOrdinal(mc.getAttributeCount());
a.setType(metaclass);
a.setReverse(attribute);
attribute.setReverse(a);
mc.addAttribute(a);
final RelationalClassMapping m = new RelationalClassMapping();