Search in sources :

Example 11 with ProcedureParameter

use of org.apache.cayenne.map.ProcedureParameter in project cayenne by apache.

the class ProcedureColumnLoader method loadProcedureParams.

private ProcedureParameter loadProcedureParams(ResultSet rs, String key, Procedure procedure) throws SQLException {
    String columnName = rs.getString("COLUMN_NAME");
    // skip ResultSet columns, as they are not described in Cayenne procedures yet...
    short type = rs.getShort("COLUMN_TYPE");
    if (type == DatabaseMetaData.procedureColumnResult) {
        LOGGER.debug("skipping ResultSet column: " + key + "." + columnName);
        return null;
    }
    if (columnName == null) {
        if (type == DatabaseMetaData.procedureColumnReturn) {
            LOGGER.debug("null column name, assuming result column: " + key);
            columnName = "_return_value";
            procedure.setReturningValue(true);
        } else {
            LOGGER.info("invalid null column name, skipping column : " + key);
            return null;
        }
    }
    int columnType = rs.getInt("DATA_TYPE");
    // ignore precision of non-decimal columns
    int decimalDigits = -1;
    if (TypesMapping.isDecimal(columnType)) {
        decimalDigits = rs.getShort("SCALE");
        if (rs.wasNull()) {
            decimalDigits = -1;
        }
    }
    ProcedureParameter column = new ProcedureParameter(columnName);
    column.setDirection(getDirection(type));
    column.setType(columnType);
    column.setMaxLength(rs.getInt("LENGTH"));
    column.setPrecision(decimalDigits);
    column.setProcedure(procedure);
    return column;
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter)

Example 12 with ProcedureParameter

use of org.apache.cayenne.map.ProcedureParameter in project cayenne by apache.

the class ProcedureAction method readProcedureOutParameters.

/**
 * Helper method that reads OUT parameters of a CallableStatement.
 */
protected void readProcedureOutParameters(CallableStatement statement, OperationObserver delegate) throws SQLException, Exception {
    long t1 = System.currentTimeMillis();
    // build result row...
    DataRow result = null;
    List<ProcedureParameter> parameters = getProcedure().getCallParameters();
    for (int i = 0; i < parameters.size(); i++) {
        ProcedureParameter parameter = parameters.get(i);
        if (!parameter.isOutParam()) {
            continue;
        }
        if (result == null) {
            result = new DataRow(2);
        }
        ColumnDescriptor descriptor = new ColumnDescriptor(parameter);
        ExtendedType type = dataNode.getAdapter().getExtendedTypes().getRegisteredType(descriptor.getJavaClass());
        Object val = type.materializeObject(statement, i + 1, descriptor.getJdbcType());
        result.put(descriptor.getDataRowKey(), val);
    }
    if (result != null && !result.isEmpty()) {
        // treat out parameters as a separate data row set
        dataNode.getJdbcEventLogger().logSelectCount(1, System.currentTimeMillis() - t1);
        delegate.nextRows(query, Collections.singletonList(result));
    }
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) ExtendedType(org.apache.cayenne.access.types.ExtendedType) DataRow(org.apache.cayenne.DataRow)

Example 13 with ProcedureParameter

use of org.apache.cayenne.map.ProcedureParameter in project cayenne by apache.

the class ProcedureParameterTab method actionPerformed.

public void actionPerformed(ActionEvent e) {
    ProcedureParameterTableModel model = (ProcedureParameterTableModel) table.getModel();
    ProcedureParameter parameter = model.getParameter(table.getSelectedRow());
    int index = -1;
    if (e.getSource() == moveUp || e.getSource() == moveUpMenu) {
        index = model.moveRowUp(parameter);
    } else if (e.getSource() == moveDown || e.getSource() == moveDownMenu) {
        index = model.moveRowDown(parameter);
    }
    if (index >= 0) {
        table.select(index);
        // note that 'setCallParameters' is donw by copy internally
        parameter.getProcedure().setCallParameters(model.getObjectList());
        eventController.fireProcedureEvent(new ProcedureEvent(this, parameter.getProcedure(), MapEvent.CHANGE));
    }
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent)

Example 14 with ProcedureParameter

use of org.apache.cayenne.map.ProcedureParameter in project cayenne by apache.

the class ProcedureParameterTab method processExistingSelection.

public void processExistingSelection(EventObject e) {
    if (e instanceof ChangeEvent) {
        table.clearSelection();
    }
    ProcedureParameter[] parameters = new ProcedureParameter[0];
    boolean enableUp = false;
    boolean enableDown = false;
    boolean enableRemoveButton = false;
    int selectedRow = table.getSelectedRow();
    if (selectedRow >= 0) {
        enableRemoveButton = true;
        ProcedureParameterTableModel model = (ProcedureParameterTableModel) table.getModel();
        int[] sel = table.getSelectedRows();
        parameters = new ProcedureParameter[sel.length];
        for (int i = 0; i < sel.length; i++) {
            parameters[i] = model.getParameter(sel[i]);
        }
        if (sel.length == 1) {
            // scroll table
            UIUtil.scrollToSelectedRow(table);
            int rowCount = table.getRowCount();
            if (rowCount > 1) {
                if (selectedRow > 0) {
                    enableUp = true;
                }
                if (selectedRow < (rowCount - 1)) {
                    enableDown = true;
                }
            }
        }
    }
    removeParameterButton.setEnabled(enableRemoveButton);
    moveUp.setEnabled(enableUp);
    moveDown.setEnabled(enableDown);
    syncButtons();
    ProcedureParameterDisplayEvent ppde = new ProcedureParameterDisplayEvent(this, parameters, eventController.getCurrentProcedure(), eventController.getCurrentDataMap(), (DataChannelDescriptor) eventController.getProject().getRootNode());
    eventController.fireProcedureParameterDisplayEvent(ppde);
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) ProcedureParameterDisplayEvent(org.apache.cayenne.modeler.event.ProcedureParameterDisplayEvent) ChangeEvent(javax.swing.event.ChangeEvent)

Example 15 with ProcedureParameter

use of org.apache.cayenne.map.ProcedureParameter in project cayenne by apache.

the class ProcedureParameterTableModel method setUpdatedValueAt.

@Override
public void setUpdatedValueAt(Object newVal, int rowIndex, int columnIndex) {
    ProcedureParameter parameter = getParameter(rowIndex);
    if (parameter == null) {
        return;
    }
    String value = (String) newVal;
    ProcedureParameterEvent event = new ProcedureParameterEvent(eventSource, parameter);
    switch(columnIndex) {
        case PARAMETER_NAME:
            event.setOldName(parameter.getName());
            setParameterName(value, parameter);
            fireTableCellUpdated(rowIndex, columnIndex);
            break;
        case PARAMETER_DIRECTION:
            setParameterDirection(value, parameter);
            break;
        case PARAMETER_TYPE:
            setParameterType(value, parameter);
            break;
        case PARAMETER_LENGTH:
            setMaxLength(value, parameter);
            break;
        case PARAMETER_PRECISION:
            setPrecision(value, parameter);
            break;
    }
    mediator.fireProcedureParameterEvent(event);
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) ProcedureParameterEvent(org.apache.cayenne.configuration.event.ProcedureParameterEvent)

Aggregations

ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)22 Procedure (org.apache.cayenne.map.Procedure)7 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)5 ProjectController (org.apache.cayenne.modeler.ProjectController)5 DataMap (org.apache.cayenne.map.DataMap)4 ProcedureParameterEvent (org.apache.cayenne.configuration.event.ProcedureParameterEvent)3 ProcedureParameterDisplayEvent (org.apache.cayenne.modeler.event.ProcedureParameterDisplayEvent)3 ArrayList (java.util.ArrayList)2 DataRow (org.apache.cayenne.DataRow)2 ExtendedType (org.apache.cayenne.access.types.ExtendedType)2 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbEntity (org.apache.cayenne.map.DbEntity)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 Embeddable (org.apache.cayenne.map.Embeddable)2 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)2