use of easik.xml.xsd.nodes.constraints.XSDKey in project fql by CategoricalData.
the class XSDElement method setKeys.
/**
* Use an entity node to set the keys, including foreign keyrefs and
* uniques.
* <p/>
* Key is set from the primary key. KeyRefs are set from the outgoing edges.
* Uniques are set by Uniques and by noninclusion injective outgoing edges.
*
* @param node
* we are working with
*/
@SuppressWarnings("unused")
public void setKeys(final EntityNode node) {
final List<UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> uniqueKeyList = node.getUniqueKeys();
final XSDComplexType myType = (XSDComplexType) getElementType();
constraints = new ArrayList<XSDAbstractKey>(uniqueKeyList.size() + 3);
final String idName = Easik.getInstance().getSettings().getProperty("xml_id_name");
final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
final boolean idIsAttribute = Boolean.valueOf(Easik.getInstance().getSettings().getProperty("xml_id_is_attribute"));
final XSDKey primaryKey = node.createXMLPrimaryKey(this);
final XSDElement theParent = (XSDElement) getParent();
theParent.addConstraint(primaryKey);
for (final SketchEdge edge : node.getOutgoingEdges()) {
final boolean isInclusion = edge.getTargetEntity().getName().equals(theParent.getName());
if (edge.isInjective()) {
if (!isInclusion) {
constraints.add(new XSDUniqueKey(edge.getForeignKeyName(keyrefName), this, edge.getName()));
}
}
if (!isInclusion) {
theParent.addConstraint(new XSDKeyRef(this, edge.getTargetEntity().getXMLPrimaryKeyName(), edge.getName()));
myType.addAtom(new XSDElement(edge.getName(), edge.isPartial(), XSDBaseType.xsInt));
}
}
for (final UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> k : uniqueKeyList) {
this.addConstraint(new XSDUniqueKey(this, k));
}
}
Aggregations