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>
* <xs:annotation>
* <xs:documentation>
* Domain(f1); A(f2) ;Codomain =
* Domain(f3); B(f4) ;Codomain
* </xs:documentation>
* </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)));
}
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;
}
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();
}
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);
}
}
}
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));
}
}
Aggregations