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.");
}
}
Aggregations