use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class ProcedureValidator method validateName.
void validateName(Procedure procedure, ValidationResult validationResult) {
String name = procedure.getName();
// Must have name
if (Util.isEmptyString(name)) {
addFailure(validationResult, procedure, "Unnamed Procedure");
return;
}
DataMap map = procedure.getDataMap();
if (map == null) {
return;
}
// check for duplicate names in the parent context
for (final Procedure otherProcedure : map.getProcedures()) {
if (otherProcedure == procedure) {
continue;
}
if (name.equals(otherProcedure.getName())) {
addFailure(validationResult, procedure, "Duplicate Procedure name: %s", procedure.getName());
break;
}
}
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class DefaultDbImportAction method syncProcedures.
private boolean syncProcedures(DataMap targetDataMap, DataMap loadedDataMap, FiltersConfig filters) {
Collection<Procedure> procedures = loadedDataMap.getProcedures();
if (procedures.isEmpty()) {
return false;
}
boolean hasChanges = false;
for (Procedure procedure : procedures) {
PatternFilter proceduresFilter = filters.proceduresFilter(procedure.getCatalog(), procedure.getSchema());
if (proceduresFilter == null || !proceduresFilter.isIncluded(procedure.getName())) {
continue;
}
Procedure oldProcedure = targetDataMap.getProcedure(procedure.getName());
// maybe we need to compare oldProcedure's and procedure's fully qualified names?
if (oldProcedure != null) {
targetDataMap.removeProcedure(procedure.getName());
logger.info("Replace procedure " + procedure.getName());
} else {
logger.info("Add new procedure " + procedure.getName());
}
targetDataMap.addProcedure(procedure);
hasChanges = true;
}
return hasChanges;
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class ProcedureQueryView method initFromModel.
/**
* Updates the view from the current model state. Invoked when a currently displayed
* query is changed.
*/
void initFromModel() {
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null || !QueryDescriptor.PROCEDURE_QUERY.equals(query.getType())) {
setVisible(false);
return;
}
properties.setEnabled(true);
name.setText(query.getName());
comment.setText(getQueryComment(query));
// init root choices and title label..
// - ProcedureQuery supports Procedure roots
// TODO: now we only allow roots from the current map,
// since query root is fully resolved during map loading,
// making it impossible to reference other DataMaps.
DataMap map = mediator.getCurrentDataMap();
Procedure[] roots = map.getProcedures().toArray(new Procedure[0]);
if (roots.length > 1) {
Arrays.sort(roots, Comparators.getDataMapChildrenComparator());
}
DefaultComboBoxModel<Procedure> model = new DefaultComboBoxModel<>(roots);
model.setSelectedItem(query.getRoot());
queryRoot.setModel(model);
properties.initFromModel(query);
setVisible(true);
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class ProcedureTab method setComment.
void setComment(String comment) {
Procedure procedure = eventController.getCurrentProcedure();
if (procedure == null) {
return;
}
ObjectInfo.putToMetaData(eventController.getApplication().getMetaData(), procedure, ObjectInfo.COMMENT, comment);
eventController.fireProcedureEvent(new ProcedureEvent(this, procedure));
}
use of org.apache.cayenne.map.Procedure in project cayenne by apache.
the class ProcedureTab method currentProcedureChanged.
/**
* Invoked when currently selected Procedure object is changed.
*/
public void currentProcedureChanged(ProcedureDisplayEvent e) {
Procedure procedure = e.getProcedure();
if (procedure == null || !e.isProcedureChanged()) {
return;
}
name.setText(procedure.getName());
schema.setText(procedure.getSchema());
catalog.setText(procedure.getCatalog());
comment.setText(getComment(procedure));
ignoreChange = true;
returnsValue.setSelected(procedure.isReturningValue());
ignoreChange = false;
}
Aggregations