Search in sources :

Example 1 with Procedure

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;
        }
    }
}
Also used : Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

Example 2 with Procedure

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;
}
Also used : PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) Procedure(org.apache.cayenne.map.Procedure)

Example 3 with Procedure

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);
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ProcedureQueryDescriptor(org.apache.cayenne.map.ProcedureQueryDescriptor) Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

Example 4 with Procedure

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));
}
Also used : ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) Procedure(org.apache.cayenne.map.Procedure)

Example 5 with 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;
}
Also used : Procedure(org.apache.cayenne.map.Procedure)

Aggregations

Procedure (org.apache.cayenne.map.Procedure)38 DataMap (org.apache.cayenne.map.DataMap)14 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)8 DbEntity (org.apache.cayenne.map.DbEntity)7 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)7 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)6 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)6 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)5 Embeddable (org.apache.cayenne.map.Embeddable)5 ObjEntity (org.apache.cayenne.map.ObjEntity)5 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)5 Test (org.junit.Test)4 ProjectController (org.apache.cayenne.modeler.ProjectController)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DataRow (org.apache.cayenne.DataRow)2 DataNode (org.apache.cayenne.access.DataNode)2 PatternFilter (org.apache.cayenne.dbsync.reverse.filters.PatternFilter)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)2