Search in sources :

Example 26 with EntityNode

use of easik.sketch.vertex.EntityNode 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 27 with EntityNode

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

the class QueryNode method processQuery.

/**
 * Processes the inQuery, assigning to instance variables
 *
 * @param String
 *            inQuery of the new node
 * @author Federico Mora
 * @throws QueryException
 */
private void processQuery(String inQuery) throws QueryException {
    if (inQuery.isEmpty()) {
        return;
    }
    boolean warnings = _ourSketch.useWarnings();
    String oldEntityNodeName = "";
    if (_queriedEntityNode != null) {
        oldEntityNodeName = _queriedEntityNode.getName();
    }
    String entityNodeName = null;
    String errMess = "";
    String tempWhere = "";
    ArrayList<String> tempQColumns = new ArrayList<>();
    EntityNode tempNode = null;
    boolean update = true;
    int fromToken = 0;
    String[] tokens = inQuery.split("[,\\s]+");
    if (!tokens[0].toUpperCase().equals("SELECT")) {
        // tell user has to start with Select
        throw new QueryException("Query must start with select");
    }
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].equalsIgnoreCase("from")) {
            fromToken = i;
            entityNodeName = tokens[i + 1];
        }
    }
    // get everything between Select and from
    for (int i = 1; i < fromToken; i++) {
        tempQColumns.add(tokens[i]);
    }
    if (!tempQColumns.contains("*") && tempQColumns.size() == 1) {
        // warn user that this may not be updatable
        update = false;
        errMess += "View will not be updatebale if not Select * \n";
    }
    // get everything after the table being queried
    for (int i = fromToken + 2; i < tokens.length; i++) {
        tempWhere += tokens[i] + " ";
    }
    if (tempWhere.toUpperCase().startsWith("WHERE")) {
        // warn user against where clause
        update = false;
        errMess += "Views with WHERE queries not updatebale \n";
    } else if (!tempWhere.isEmpty()) {
        // error, can't query from more than one table
        throw new QueryException("Cannot query from more than one table");
    }
    boolean found = false;
    // set corresponding node in order to use
    for (EntityNode sketchNode : _ourSketch.getEntities()) {
        if (sketchNode.getName().equals(entityNodeName)) {
            // same node.
            if (_theModel.getEntityNodePairs().containsKey(sketchNode) && !sketchNode.getName().equals(oldEntityNodeName)) {
                // this node is already being queried. Not allowed.
                throw new QueryException("Entity Node is already being queried.");
            }
            tempNode = sketchNode;
            found = true;
        }
    }
    if (!found) {
        throw new QueryException("Entity node being queried does not exist");
    }
    if (!errMess.isEmpty() && warnings) {
        JOptionPane.showMessageDialog(_theModel, this.getMModel().getName() + ", due to node " + this.getName() + ": " + errMess, "Warning", JOptionPane.ERROR_MESSAGE);
    }
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String s : tempQColumns) {
        if (!first) {
            sb.append(", ");
        }
        sb.append(s);
        first = false;
    }
    _queriedColumns = sb.toString();
    _whereStatement = tempWhere;
    _queriedEntityNode = tempNode;
    updateable = update;
    processAttributes();
}
Also used : QueryException(easik.view.util.QueryException) ArrayList(java.util.ArrayList) EntityNode(easik.sketch.vertex.EntityNode)

Example 28 with EntityNode

use of easik.sketch.vertex.EntityNode 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 29 with EntityNode

use of easik.sketch.vertex.EntityNode 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)

Example 30 with EntityNode

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

the class ViewDataAction method actionPerformed.

/**
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theSketch.getSelectionCells();
    if (!(currentSelection[0] instanceof EntityNode)) {
        return;
    }
    EntityNode node = (EntityNode) currentSelection[0];
    DatabaseUtil.selectRowPKs(node.getMModel().getFrame(), node);
}
Also used : 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