Search in sources :

Example 1 with QueryException

use of easik.view.util.QueryException in project fql by CategoricalData.

the class OverviewHandler method startElement.

/**
 * Overloaded method that is called any time the start of an element is
 * found
 *
 * @param namespace
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param localName
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param qName
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param atts
 * 			@see org.xml.sax.helpers.DefaultHandler
 */
@Override
public void startElement(String namespace, String localName, String qName, Attributes atts) {
    _currNode = qName;
    // call
    if (_sketchParser != null) {
        _sketchParser.startElement(namespace, localName, qName, atts);
    } else // Initialize a sketch handler, and note this sketch's attributes
    if (qName.equals("easketch")) {
        String sketchName = atts.getValue("name");
        int sketchX = Integer.parseInt(atts.getValue("x"));
        int sketchY = Integer.parseInt(atts.getValue("y"));
        String cascade = atts.getValue("cascade"), pCascade = atts.getValue("partial-cascade");
        if (cascade == null) {
            cascade = Easik.getInstance().getSettings().getProperty("sql_cascade", "restrict");
        }
        if (pCascade == null) {
            pCascade = Easik.getInstance().getSettings().getProperty("sql_cascade_partial", "set_null");
        }
        Cascade c = cascade.equals("cascade") ? Cascade.CASCADE : Cascade.RESTRICT;
        Cascade cp = pCascade.equals("cascade") ? Cascade.CASCADE : pCascade.equals("restrict") ? Cascade.RESTRICT : Cascade.SET_NULL;
        _sketchParser = SketchFileIO.getNewSketchHandler(_theFrame.getOverview());
        SketchFrame frame = _sketchParser.getFrame();
        Sketch sketch = frame.getMModel();
        sketch.setDefaultCascading(c);
        sketch.setDefaultPartialCascading(cp);
        _newSketchNode = new SketchNode(sketchName, sketchX, sketchY, frame);
        _sketchNodes.put(sketchName, _newSketchNode);
    } else // know not to override the overview's
    if (qName.equals("view")) {
        _parsingView = true;
        _queryNodes = new HashMap<>();
        String viewName = atts.getValue("name");
        int x = Integer.parseInt(atts.getValue("x"));
        int y = Integer.parseInt(atts.getValue("y"));
        String edgeLabel = atts.getValue("viewDefinitionEdge");
        String sketchName = atts.getValue("on_sketch");
        ViewFrame viewFrame = new ViewFrame(_theFrame.getOverview(), _sketchNodes.get(sketchName).getFrame().getMModel());
        _newViewNode = new ViewNode(viewName, x, y, viewFrame);
        _viewDefEdge.put(edgeLabel, new ViewDefinitionEdge(_newViewNode, _sketchNodes.get(sketchName), edgeLabel));
        _viewDocInfo = new DocumentInfo(viewFrame);
        _viewNodes.put(viewName, _newViewNode);
        _sketchNodes.get(sketchName).getFrame().getMModel().addView(_newViewNode);
    } else if (qName.equals("queryNode")) {
        String name = atts.getValue("name");
        int x = Integer.parseInt(atts.getValue("x"));
        int y = Integer.parseInt(atts.getValue("y"));
        String query = atts.getValue("query");
        // exception so they can't be saved
        try {
            _queryNodes.put(name, new QueryNode(name, x, y, _newViewNode.getFrame().getMModel(), query));
        } catch (QueryException e) {
            e.printStackTrace();
        }
    } else if (qName.equals("View_Edge")) {
        View_Edge newEdge;
        String edgeType = atts.getValue("type");
        QueryNode source = _queryNodes.get(atts.getValue("source"));
        QueryNode target = _queryNodes.get(atts.getValue("target"));
        String id = atts.getValue("id");
        String cascadeAtt = atts.getValue("cascade");
        if (cascadeAtt == null) {
            // This is from an export before Easik had per-edge cascading
            // (in other words, before r583)
            // We use the global preferences for cascading
            String key = "sql_cascade", def = "restrict";
            if (edgeType.equals("partial")) {
                key = "sql_cascade_partial";
                def = "set_null";
            }
            cascadeAtt = Easik.getInstance().getSettings().getProperty(key, def);
        }
        @SuppressWarnings("unused") SketchEdge.Cascade cascade = cascadeAtt.equals("set_null") ? SketchEdge.Cascade.SET_NULL : cascadeAtt.equals("cascade") ? SketchEdge.Cascade.CASCADE : SketchEdge.Cascade.RESTRICT;
        if (edgeType.equals("injective")) {
            newEdge = new InjectiveViewEdge(source, target, id);
        } else if (edgeType.equals("partial")) {
            newEdge = new PartialViewEdge(source, target, id);
        } else {
            newEdge = new NormalViewEdge(source, target, id);
        }
        _viewEdges.put(id, newEdge);
    }
}
Also used : NormalViewEdge(easik.view.edge.NormalViewEdge) ViewFrame(easik.ui.ViewFrame) SketchNode(easik.overview.vertex.SketchNode) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) SketchFrame(easik.ui.SketchFrame) QueryException(easik.view.util.QueryException) SketchEdge(easik.sketch.edge.SketchEdge) QueryNode(easik.view.vertex.QueryNode) Sketch(easik.sketch.Sketch) ViewNode(easik.overview.vertex.ViewNode) Cascade(easik.model.edge.ModelEdge.Cascade) DocumentInfo(easik.DocumentInfo)

Example 2 with QueryException

use of easik.view.util.QueryException 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 3 with QueryException

use of easik.view.util.QueryException in project fql by CategoricalData.

the class DefineQueryNodeFromTreeAction method updateNode.

/**
 * Prompts user for name and query values and make appropriate updates on
 * query node.
 *
 * @param ourNode
 */
public static void updateNode(QueryNode ourNode) {
    ViewFrame ourFrame = ourNode.getMModel().getFrame();
    View ourView = ourFrame.getMModel();
    String originalName = ourNode.getName();
    DefineQueryNodeDialog dqnd = new DefineQueryNodeDialog(ourFrame, "Define Query Node", ourNode);
    if (!dqnd.isAccepted()) {
        return;
    }
    String errorMess = null;
    String name = dqnd.getName();
    if (name.equals("")) {
        errorMess = "Blank name field: did not update.";
    } else if (ourView.isNameUsed(name) && !originalName.equals(name)) {
        errorMess = "Name already in use: not update.";
    }
    if (errorMess != null) {
        JOptionPane.showMessageDialog(ourView.getParent(), errorMess, "Error", JOptionPane.ERROR_MESSAGE);
    } else if (!name.equals(originalName)) {
        ourNode.setName(name);
        ourFrame.getInfoTreeUI().refreshTree();
        ourView.getGraphLayoutCache().reload();
        ourView.repaint();
        ourView.setDirty();
    }
    String query = dqnd.getQuery();
    try {
        ourNode.setQuery(query);
    } catch (QueryException e) {
        JOptionPane.showMessageDialog(ourView.getParent(), "New Query not set. Not valid query.", "Error", JOptionPane.ERROR_MESSAGE);
    }
    ourView.clearSelection();
}
Also used : QueryException(easik.view.util.QueryException) DefineQueryNodeDialog(easik.ui.DefineQueryNodeDialog) ViewFrame(easik.ui.ViewFrame) View(easik.view.View)

Example 4 with QueryException

use of easik.view.util.QueryException in project fql by CategoricalData.

the class View method addNewNode.

/**
 * Add a new, empty entity at point X, Y
 *
 * @param name
 *            The name of the new entity being added
 * @param x
 *            X Coordinate of new entity
 * @param y
 *            Y Coordinate of new entity
 */
@Override
public void addNewNode(final String name, final double x, final double y) {
    final QueryNode newEntity;
    // this won't throw exception because query is blank
    try {
        newEntity = new QueryNode(name, (int) x, (int) y, this, "");
        addEntity(newEntity);
    } catch (QueryException e) {
        e.printStackTrace();
    }
}
Also used : QueryException(easik.view.util.QueryException) QueryNode(easik.view.vertex.QueryNode)

Example 5 with QueryException

use of easik.view.util.QueryException in project fql by CategoricalData.

the class NewQueryNodeAction method actionPerformed.

/**
 * Create the new query node.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    String defaultName = _theFrame.getMModel().getNewName();
    QueryNode newNode;
    try {
        newNode = new QueryNode(defaultName, (int) _newPoint.getX(), (int) _newPoint.getY(), _theFrame.getMModel(), "");
        DefineQueryNodeDialog dqnd = new DefineQueryNodeDialog(_theFrame, "New Query Node", newNode);
        if (!dqnd.isAccepted()) {
            return;
        }
        String name = dqnd.getName();
        while (name.equals("") || _theFrame.getMModel().isNameUsed(name)) {
            JOptionPane.showMessageDialog(_theFrame, "Error while naming entity.\n" + "Please ensure that entity name is:\n" + "1) Not blank\n" + "2) Not already in use", "Error", JOptionPane.ERROR_MESSAGE);
            name = (String) JOptionPane.showInputDialog(_theFrame, "Name for new entity:", "Get name", JOptionPane.QUESTION_MESSAGE, null, null, name);
            if (name == null) {
                return;
            }
            name = name.trim();
        }
        String query = dqnd.getQuery();
        newNode.setName(name);
        newNode.setQuery(query);
        _theFrame.getMModel().addEntity(newNode);
        _theFrame.getMModel().setDirty();
    } catch (QueryException e1) {
        // this can technically throw an exception in two spots but will
        // only really throw in the setQuery call
        // because the first call, a constructor call to queryNode, gives an
        // emptry query which is ok
        JOptionPane.showMessageDialog(_theFrame.getParent(), "New Query node not created. Not valid query.\n" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : QueryException(easik.view.util.QueryException) DefineQueryNodeDialog(easik.ui.DefineQueryNodeDialog) QueryNode(easik.view.vertex.QueryNode)

Aggregations

QueryException (easik.view.util.QueryException)6 DefineQueryNodeDialog (easik.ui.DefineQueryNodeDialog)3 ViewFrame (easik.ui.ViewFrame)3 QueryNode (easik.view.vertex.QueryNode)3 View (easik.view.View)2 DocumentInfo (easik.DocumentInfo)1 Cascade (easik.model.edge.ModelEdge.Cascade)1 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)1 SketchNode (easik.overview.vertex.SketchNode)1 ViewNode (easik.overview.vertex.ViewNode)1 Sketch (easik.sketch.Sketch)1 SketchEdge (easik.sketch.edge.SketchEdge)1 EntityNode (easik.sketch.vertex.EntityNode)1 SketchFrame (easik.ui.SketchFrame)1 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)1 NormalViewEdge (easik.view.edge.NormalViewEdge)1 PartialViewEdge (easik.view.edge.PartialViewEdge)1 View_Edge (easik.view.edge.View_Edge)1 ArrayList (java.util.ArrayList)1