Search in sources :

Example 1 with XSDUniqueKey

use of easik.xml.xsd.nodes.constraints.XSDUniqueKey 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));
    }
}
Also used : XSDAbstractKey(easik.xml.xsd.nodes.constraints.XSDAbstractKey) XSDKey(easik.xml.xsd.nodes.constraints.XSDKey) XSDKeyRef(easik.xml.xsd.nodes.constraints.XSDKeyRef) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) XSDUniqueKey(easik.xml.xsd.nodes.constraints.XSDUniqueKey) SketchEdge(easik.sketch.edge.SketchEdge) XSDUniqueKey(easik.xml.xsd.nodes.constraints.XSDUniqueKey) UniqueKey(easik.model.keys.UniqueKey) Sketch(easik.sketch.Sketch) XSDComplexType(easik.xml.xsd.nodes.types.XSDComplexType)

Aggregations

UniqueKey (easik.model.keys.UniqueKey)1 Sketch (easik.sketch.Sketch)1 SketchEdge (easik.sketch.edge.SketchEdge)1 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)1 EntityNode (easik.sketch.vertex.EntityNode)1 SketchFrame (easik.ui.SketchFrame)1 XSDAbstractKey (easik.xml.xsd.nodes.constraints.XSDAbstractKey)1 XSDKey (easik.xml.xsd.nodes.constraints.XSDKey)1 XSDKeyRef (easik.xml.xsd.nodes.constraints.XSDKeyRef)1 XSDUniqueKey (easik.xml.xsd.nodes.constraints.XSDUniqueKey)1 XSDComplexType (easik.xml.xsd.nodes.types.XSDComplexType)1