{
throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
new Object[]{attribute.getName(), metaclass.getName()});
}
loader.addPersistenceMappingFixup(new ContextFixup(m_helper)
{
public void fixup()
{
Metaclass type = (Metaclass)attribute.getType();
PersistenceMapping assocClassMapping = type.getPersistenceMapping();
if (assocClassMapping == null)
{
throw new MetadataException("err.meta.missingAssocPersistenceMapping",
new Object[]{attribute.getName(), metaclass.getName(), type.getName()});
}
classMapping.setSourceKey((bObjectSourceKey) ? mapping.getObjectKey() : new VirtualKey(attribute));
classMapping.setDestinationKey(assocClassMapping.addForeignKey(sDestinationKeyName, classMapping));
}
});
loader.addComponentFixup(new ContextFixup(m_helper)
{
public void fixup()
{
classMapping.validate(metadata, m_helper.getWarnings());
}
});
}
attrMapping.setAttribute(attribute);
mapping.addAttributeMapping(attrMapping);
}
});
}
});
XMLUtil.withFirstChildElement(element, "SortKeys", false,
new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
XMLUtil.forEachChildElement(element, "SortKey", new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
mapping.addSortKey(
(Pair)m_helper.parse(XMLUtil.getReqStringAttr(element, "attributes"), true,
mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()),
XMLUtil.getBooleanAttr(element, "unique", false)
);
}
});
}
});
XMLUtil.withFirstChildElement(element, "ReadMapping", false,
new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
final ReadMapping readMapping = mapping.getReadMapping();
XMLUtil.forEachChildElement(element, "Case", new XMLUtil.ElementHandler()
{
private int m_nOrdinal = 0;
public void handleElement(Element element)
{
final String sReadPrefix = sURLPrefix + ".read." + m_nOrdinal;
Object whereExpr = m_helper.parse(
XMLUtil.getStringAttr(element, "where"),
false, sReadPrefix + "$where", mapping.getTextPositionMap(), Symbol.ELSE, metadata.getGlobalEnvironment()
);
Pair variables = (Pair)m_helper.parse(
XMLUtil.getStringAttr(element, "variables"),
true, mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()
);
final ReadMappingCase readMappingCase = new ReadMappingCase();
readMappingCase.setWhere(whereExpr);
readMappingCase.setVariables(variables);
XMLUtil.withFirstChildElement(element, "Read", true, new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
readMappingCase.setReadScript(loadScript(element, sReadPrefix + "$read", mapping.getTextPositionMap()));
}
});
XMLUtil.withFirstChildElement(element, "Close", false, new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
readMappingCase.setCloseScript(loadScript(element, sReadPrefix + "$close", mapping.getTextPositionMap()));
}
});
readMapping.addCase(readMappingCase);
m_nOrdinal += 1;
}
});
}
});
XMLUtil.withFirstChildElement(element, "CreateMapping", false,
new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
final WorkMapping operation = new WorkMapping(metaclass);
operation.setBatch(XMLUtil.getBooleanAttr(element, "batch", operation.isBatch()));
operation.setScript(loadScript(element, sURLPrefix + ".create", mapping.getTextPositionMap()));
mapping.setCreateMapping(operation);
}
});
XMLUtil.withFirstChildElement(element, "UpdateMapping", false,
new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
final UpdateMapping updateMapping = new UpdateMapping(mapping);
XMLUtil.forEachChildElement(element, "Case", new XMLUtil.ElementHandler()
{
private int m_nOrdinal = 0;
public void handleElement(Element element)
{
final UpdateMappingCase update = new UpdateMappingCase(metaclass);
update.setBatch(XMLUtil.getBooleanAttr(element, "batch", update.isBatch()));
update.setDirty(XMLUtil.getBooleanAttr(element, "dirty", update.isDirty()));
update.setFull(XMLUtil.getBooleanAttr(element, "full", update.isFull()));
Pair attributes = (Pair)m_helper.parse(
XMLUtil.getStringAttr(element, "attributes"),
true, mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()
);
update.setScript(loadScript(element, sURLPrefix + ".update." + m_nOrdinal, mapping.getTextPositionMap()));
updateMapping.addCase(update, attributes);
m_nOrdinal += 1;
}
});
mapping.setUpdateMapping(updateMapping);
}
});
XMLUtil.withFirstChildElement(element, "DeleteMapping", false,
new XMLUtil.ElementHandler()
{
public void handleElement(Element element)
{
final WorkMapping operation = new WorkMapping(metaclass);
operation.setBatch(XMLUtil.getBooleanAttr(element, "batch", operation.isBatch()));
operation.setScript(loadScript(element, sURLPrefix + ".delete", mapping.getTextPositionMap()));
mapping.setDeleteMapping(operation);
}
});
// Key Generator
final String sKeyGeneratorName = XMLUtil.getStringAttr(element, "keyGenerator");
if (sKeyGeneratorName != null)
{
loader.addComponentFixup(new ContextFixup(m_helper)
{
public void fixup()
{
mapping.setKeyGenerator(metadata.getComponent(sKeyGeneratorName));
}
});
}
mapping.setDerived(XMLUtil.getBooleanAttr(element, "derived", mapping.isDerived()));
}
});
loader.addSingletonFixup(new ContextFixup(m_helper)
{
public void fixup()
{
mapping.compile(loader.getMachine());
}