Search in sources :

Example 16 with SketchEdge

use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the commutativity of the diagram.
 * <p/>
 * Today, this is simply done by creating an annotation. For example in the
 * standard cd in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     Domain(f1); A(f2) ;Codomain =
 *     Domain(f3); B(f4) ;Codomain
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 *
 * @param cd
 *            the commutative diagram constraint.
 */
private void createConstraint(final CommutativeDiagram<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> cd) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = cd.getPaths();
    final EntityNode dom = paths.get(0).getDomain();
    final XSDType domType = dom.getXsdType();
    final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
    final List<String> values = new ArrayList<>(paths.size());
    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : paths) {
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        if (tmpPath.size() == 0) {
            values.add(dom.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')');
        } else {
            values.add(dom.getName() + '(' + path.getFirstEdge().getForeignKeyName(keyrefName) + ')' + xmlJoinPath(tmpPath, true));
        }
    }
    domType.addAnnotation(new XSDAnnotation(EasikTools.join(" = " + lineSep, values)));
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode) XSDType(easik.xml.xsd.nodes.types.XSDType) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath) Sketch(easik.sketch.Sketch) XSDAnnotation(easik.xml.xsd.nodes.XSDAnnotation)

Example 17 with SketchEdge

use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.

the class EntityNode method getIndexableEdges.

/**
 * Returns a Set of UniqueIndexable-implementing outgoing edges of this
 * node.
 *
 * @return set of uniques
 */
@Override
public Set<UniqueIndexable> getIndexableEdges() {
    final Set<SketchEdge> edges = getOutgoingEdges();
    final Set<UniqueIndexable> attribs = new LinkedHashSet<>(edges.size());
    for (final SketchEdge edge : edges) {
        if (edge instanceof UniqueIndexable) {
            attribs.add((UniqueIndexable) edge);
        }
    }
    return attribs;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SketchEdge(easik.sketch.edge.SketchEdge) UniqueIndexable(easik.model.keys.UniqueIndexable)

Example 18 with SketchEdge

use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.

the class JDBCExporter method leftJoinPath.

/**
 * Constructs a special join clause for this path to be used in an update
 * statement for constraint consistency in projections.
 *
 * @param p
 *            the path for which the selection is being made
 * @return the string, suitable for use in a SELECT query.
 *
 * @author Federico Mora
 */
protected String leftJoinPath(final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> p) {
    final LinkedList<SketchEdge> edges = p.getEdges();
    final StringBuilder joinClause = new StringBuilder();
    Iterator<SketchEdge> iter = edges.descendingIterator();
    iter.next();
    int i = 0;
    while (iter.hasNext()) {
        final SketchEdge e = iter.next();
        final EntityNode source = e.getSourceEntity();
        final EntityNode target = e.getTargetEntity();
        if (i == 0) {
            i++;
            joinClause.append(quoteId(target) + " LEFT JOIN ").append(quoteId(source)).append(" ON ").append(qualifiedPK(target)).append(" = ").append(qualifiedFK(e));
        } else {
            joinClause.append(" LEFT JOIN ").append(quoteId(source)).append(" ON ").append(qualifiedPK(target)).append(" = ").append(qualifiedFK(e));
        }
    }
    return joinClause.toString();
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) LimitConstraint(easik.model.constraint.LimitConstraint) EqualizerConstraint(easik.model.constraint.EqualizerConstraint) ProductConstraint(easik.model.constraint.ProductConstraint) SumConstraint(easik.model.constraint.SumConstraint) PullbackConstraint(easik.model.constraint.PullbackConstraint) ModelConstraint(easik.model.constraint.ModelConstraint) EntityNode(easik.sketch.vertex.EntityNode)

Example 19 with SketchEdge

use of easik.sketch.edge.SketchEdge in project fql by CategoricalData.

the class View method autoAddExistingEdges.

/**
 * Call this method when a new QueryNode or Edge is created to automatically
 * add whatever existing edges It has in the underlying sketch with other
 * existing QueryNodes.
 *
 * @author Federico Mora
 */
public void autoAddExistingEdges() {
    Collection<SketchEdge> sketchEdges = _ourSketch.getEdges().values();
    HashMap<EntityNode, QueryNode> nodeMatches = getEntityNodePairs();
    for (SketchEdge se : sketchEdges) {
        if (nodeMatches.containsKey(se.getTargetEntity()) && nodeMatches.containsKey(se.getSourceEntity()) && !_edges.containsKey(se.getName())) {
            View_Edge vEdge;
            // need to move down??
            if (se.isPartial()) {
                vEdge = new PartialViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
            } else if (se.isInjective()) {
                // System.out.println("Edge is injective");
                // **NEED TO FIGURE OUT CASCADING
                vEdge = new InjectiveViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName(), Cascade.RESTRICT);
            } else {
                vEdge = new NormalViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
            }
            this.addEdge(vEdge);
        }
    }
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) NormalViewEdge(easik.view.edge.NormalViewEdge) QueryNode(easik.view.vertex.QueryNode) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) EntityNode(easik.sketch.vertex.EntityNode)

Example 20 with SketchEdge

use of easik.sketch.edge.SketchEdge 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

SketchEdge (easik.sketch.edge.SketchEdge)51 EntityNode (easik.sketch.vertex.EntityNode)45 Sketch (easik.sketch.Sketch)31 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)31 SketchFrame (easik.ui.SketchFrame)30 LinkedList (java.util.LinkedList)22 LimitConstraint (easik.model.constraint.LimitConstraint)17 ProductConstraint (easik.model.constraint.ProductConstraint)16 PullbackConstraint (easik.model.constraint.PullbackConstraint)16 SumConstraint (easik.model.constraint.SumConstraint)16 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)13 ModelConstraint (easik.model.constraint.ModelConstraint)13 ArrayList (java.util.ArrayList)11 ModelPath (easik.model.path.ModelPath)9 LinkedHashSet (java.util.LinkedHashSet)9 InjectiveEdge (easik.sketch.edge.InjectiveEdge)7 UniqueIndexable (easik.model.keys.UniqueIndexable)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5 XSDType (easik.xml.xsd.nodes.types.XSDType)5 EasikType (easik.database.types.EasikType)4