Search in sources :

Example 41 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class XSDExporter method createConstraint.

/**
 * Add an annotation explaining the product.
 * <p/>
 * Today, this is simply done by creating an annotation. For example in the
 * standard product constraint in constraints.easik gives this annotation:
 *
 * <pre>
 * &lt;xs:annotation>
 *  &lt;xs:documentation>
 *     ForAll.elem1 in (P1), ForAll.elem2 in (P2)
 *     Exists.p=(elem1,elem2) in Product
 *   &lt;/xs:documentation>
 * &lt;/xs:annotation>
 * </pre>
 *
 * @param prod
 *            the product diagram constraint.
 */
private void createConstraint(final ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> prod) {
    final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = prod.getPaths();
    final EntityNode dom = paths.get(0).getDomain();
    final XSDType domType = dom.getXsdType();
    final List<String> elts = new ArrayList<>(paths.size());
    int id = 0;
    @SuppressWarnings("unused") 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) {
        id++;
        final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
        tmpPath.removeFirst();
        final String elem = "elem" + id;
        elts.add(elem);
        if (tmpPath.size() == 0) {
            values.add("ForAll." + elem + " in (" + path.getCoDomain().getName() + ')');
        } else {
            values.add("ForAll." + elem + " in " + xmlJoinPath(tmpPath, true));
        }
    }
    final String documentation = EasikTools.join(", ", values);
    final String elements = "Exists.p=(" + EasikTools.join(",", elts) + ") in " + dom.getName();
    domType.addAnnotation(new XSDAnnotation(documentation + lineSep + elements));
}
Also used : ArrayList(java.util.ArrayList) 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) 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 42 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class XSDExporter method addTypesandElementsToSchema.

/**
 * After constraints have been handled, the types and elements remaining can
 * be added to the schema.
 * <p/>
 * Note that adding constraints may remove elements from the sketch
 * entities, e.g., in equalizers or sums, the isA relationship means that
 * containment can be used.
 */
private void addTypesandElementsToSchema() {
    final Collection<EntityNode> nodeCollection = sketch.getEntities();
    for (final EntityNode entity : nodeCollection) {
        theSchema.addType(entity.getXsdType());
        topLevel.addAtom(entity.getXsdElement());
    }
}
Also used : EntityNode(easik.sketch.vertex.EntityNode)

Example 43 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class XSDExporter method xmlJoinPath.

/**
 * protected method to assist in building "path" strings for the constraint
 * annotations
 *
 * @param inEdges
 *            List of sketchedges
 * @param includeLast
 *            Include the last or not
 * @return path like string
 */
protected String xmlJoinPath(final List<SketchEdge> inEdges, final boolean includeLast) {
    final LinkedList<SketchEdge> edges = new LinkedList<>(inEdges);
    final StringBuilder joinClause = new StringBuilder("; ");
    joinClause.append(quoteId(edges.get(0).getSourceEntity().getName()));
    if (!includeLast && !edges.isEmpty()) {
        edges.removeLast();
    }
    for (final SketchEdge e : edges) {
        final EntityNode target = e.getTargetEntity();
        joinClause.append('(').append(e.getName()).append(") ;").append(target.getName());
    }
    return joinClause.toString();
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode)

Example 44 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class JDBCDriver method overrideConstraints.

/**
 * Toggle constraints and let the user modify the table.
 *
 * @param sketch
 *            Sketch to override triggers for
 * @throws Exception
 */
@Override
public void overrideConstraints(Sketch sketch) throws Exception {
    // Get update type (in case they need to be treated separately)
    final String INSERT = "Insert";
    final String DELETE = "Delete";
    String[] options = { INSERT, DELETE };
    String edit = (String) JOptionPane.showInputDialog(sketch.getFrame(), "Select constraint override update", "What would you like to do?", JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
    if (edit == null) {
        return;
    }
    // Get which table to update
    ArrayList<EntityNode> ens = new ArrayList<>(sketch.getEntities());
    options = new String[ens.size()];
    for (int i = 0; i < options.length; i++) {
        options[i] = ens.get(i).getName();
    }
    String table = (String) JOptionPane.showInputDialog(sketch.getFrame(), "Select table to modify", "Which table to modify?", JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
    if (table == null) {
        return;
    }
    FreeQueryDialog afqd;
    String text;
    if (INSERT.equals(edit)) {
        text = "INSERT INTO " + table + "() VALUES()";
    } else {
        text = "DELETE FROM " + table + "\n WHERE()";
    }
    afqd = new FreeQueryDialog(sketch.getFrame(), text);
    if (!afqd.isAccepted()) {
        return;
    }
    try {
        // Disable constraint
        toggleConstraint(true);
        executeUpdate(afqd.getInput());
    } finally {
        // Enable constraints
        toggleConstraint(false);
    }
}
Also used : ArrayList(java.util.ArrayList) FreeQueryDialog(easik.ui.datamanip.FreeQueryDialog) EntityNode(easik.sketch.vertex.EntityNode)

Example 45 with EntityNode

use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.

the class JDBCExporter method joinPath.

/**
 * Constructs a join clause for this path. For instance, if the path is a
 * -&gt; b -&gt; c -&gt; d, this would return
 * <code>a JOIN b ON b.a_id = a.id JOIN c ON c.b_id = b.id JOIN d ON d.c_id = c.id</code>
 * suitable for use in a select query.
 *
 * @param inEdges
 *            the path for which the selection is being made
 * @param includeLast
 *            true if the last path target should be included. If false, the
 *            last path will be omitted.
 * @param initialOn
 *            if non-null, "ON " + initialOn will be added after the path
 *            source table name
 * @return the string, suitable for use in a SELECT query.
 */
protected String joinPath(final List<SketchEdge> inEdges, final boolean includeLast, final String initialOn) {
    final LinkedList<SketchEdge> edges = new LinkedList<>(inEdges);
    final StringBuilder joinClause = new StringBuilder(quoteId(edges.get(0).getSourceEntity().getName()));
    if (initialOn != null) {
        joinClause.append(" ON ").append(initialOn);
    }
    if (!includeLast && !edges.isEmpty()) {
        edges.removeLast();
    }
    for (final SketchEdge e : edges) {
        final EntityNode target = e.getTargetEntity();
        joinClause.append(" JOIN ").append(quoteId(target)).append(" ON ").append(qualifiedFK(e)).append(" = ").append(qualifiedPK(target));
    }
    return joinClause.toString();
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) LinkedList(java.util.LinkedList) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

EntityNode (easik.sketch.vertex.EntityNode)62 SketchEdge (easik.sketch.edge.SketchEdge)45 Sketch (easik.sketch.Sketch)30 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)30 SketchFrame (easik.ui.SketchFrame)29 LinkedList (java.util.LinkedList)21 LimitConstraint (easik.model.constraint.LimitConstraint)16 ProductConstraint (easik.model.constraint.ProductConstraint)15 PullbackConstraint (easik.model.constraint.PullbackConstraint)15 SumConstraint (easik.model.constraint.SumConstraint)15 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)12 ModelConstraint (easik.model.constraint.ModelConstraint)12 ArrayList (java.util.ArrayList)12 ModelPath (easik.model.path.ModelPath)8 InjectiveEdge (easik.sketch.edge.InjectiveEdge)7 UpdateMonitor (easik.ui.datamanip.UpdateMonitor)6 SQLException (java.sql.SQLException)6 LinkedHashSet (java.util.LinkedHashSet)6 QueryNode (easik.view.vertex.QueryNode)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5