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>
* <xs:annotation>
* <xs:documentation>
* ForAll.elem1 in (P1), ForAll.elem2 in (P2)
* Exists.p=(elem1,elem2) in Product
* </xs:documentation>
* </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));
}
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());
}
}
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();
}
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);
}
}
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
* -> b -> c -> 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();
}
Aggregations