Search in sources :

Example 26 with QueryEvent

use of org.apache.cayenne.configuration.event.QueryEvent in project cayenne by apache.

the class BaseQueryMainTab method setQueryName.

/**
 * Initializes Query name from string.
 */
void setQueryName(String newName) {
    if (newName != null && newName.trim().length() == 0) {
        newName = null;
    }
    QueryDescriptor query = getQuery();
    if (query == null) {
        return;
    }
    if (Util.nullSafeEquals(newName, query.getName())) {
        return;
    }
    if (newName == null) {
        throw new ValidationException("SelectQuery name is required.");
    }
    DataMap map = mediator.getCurrentDataMap();
    QueryDescriptor matchingQuery = map.getQueryDescriptor(newName);
    if (matchingQuery == null) {
        // completely new name, set new name for entity
        QueryEvent e = new QueryEvent(this, query, query.getName());
        ProjectUtil.setQueryName(map, query, newName);
        mediator.fireQueryEvent(e);
    } else if (matchingQuery != query) {
        // there is a query with the same name
        throw new ValidationException("There is another query named '" + newName + "'. Use a different name.");
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)26 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)13 ProcedureQueryDescriptor (org.apache.cayenne.map.ProcedureQueryDescriptor)4 ValidationException (org.apache.cayenne.validation.ValidationException)4 DataMap (org.apache.cayenne.map.DataMap)3 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)3 ArrayList (java.util.ArrayList)2 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)2 SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)2 EntityEvent (org.apache.cayenne.map.event.EntityEvent)2 ProjectController (org.apache.cayenne.modeler.ProjectController)2 DataMapDisplayEvent (org.apache.cayenne.modeler.event.DataMapDisplayEvent)2 Ordering (org.apache.cayenne.query.Ordering)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 EventObject (java.util.EventObject)1 BadLocationException (javax.swing.text.BadLocationException)1 Document (javax.swing.text.Document)1 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)1