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