Search in sources :

Example 6 with ProcedureParameter

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

the class OracleUnitDbAdapter method tweakProcedure.

@Override
public void tweakProcedure(Procedure proc) {
    if (DataContextProcedureQueryIT.SELECT_STORED_PROCEDURE.equals(proc.getName()) && proc.getCallParameters().size() == 2) {
        List params = new ArrayList(proc.getCallParameters());
        proc.clearCallParameters();
        proc.addCallParameter(new ProcedureParameter("result", OracleAdapter.getOracleCursorType(), ProcedureParameter.OUT_PARAMETER));
        Iterator it = params.iterator();
        while (it.hasNext()) {
            ProcedureParameter param = (ProcedureParameter) it.next();
            proc.addCallParameter(param);
        }
        proc.setReturningValue(true);
    }
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with ProcedureParameter

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

the class OracleProcedureAction method readProcedureOutParameters.

/**
 * Helper method that reads OUT parameters of a CallableStatement.
 */
@Override
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;
        }
        // ==== start Oracle-specific part
        if (parameter.getType() == OracleAdapter.getOracleCursorType()) {
            try (ResultSet rs = (ResultSet) statement.getObject(i + 1)) {
                RowDescriptor rsDescriptor = describeResultSet(rs, processedResultSets++);
                readResultSet(rs, rsDescriptor, query, delegate);
            }
        } else // ==== end Oracle-specific part
        {
            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) ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor) ResultSet(java.sql.ResultSet) ExtendedType(org.apache.cayenne.access.types.ExtendedType) DataRow(org.apache.cayenne.DataRow) RowDescriptor(org.apache.cayenne.access.jdbc.RowDescriptor)

Example 8 with ProcedureParameter

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

the class NameBuilderTest method testName_ProcedureContext.

@Test
public void testName_ProcedureContext() {
    Procedure procedure = new Procedure();
    ProcedureParameter p0 = new ProcedureParameter();
    p0.setName(NameBuilder.builder(p0).in(procedure).name());
    assertEquals("UntitledProcedureParameter", p0.getName());
    procedure.addCallParameter(p0);
    ProcedureParameter p1 = new ProcedureParameter();
    p1.setName(NameBuilder.builder(p1).in(procedure).name());
    assertEquals("UntitledProcedureParameter1", p1.getName());
    procedure.addCallParameter(p1);
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) Procedure(org.apache.cayenne.map.Procedure) Test(org.junit.Test)

Example 9 with ProcedureParameter

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

the class ProcedureHandler method addProcedureParameter.

private void addProcedureParameter(Attributes attributes) throws SAXException {
    String name = attributes.getValue("name");
    if (name == null) {
        throw new SAXException("ProcedureHandler::addProcedureParameter() - no procedure parameter name.");
    }
    ProcedureParameter parameter = new ProcedureParameter(name);
    String type = attributes.getValue("type");
    if (type != null) {
        parameter.setType(TypesMapping.getSqlTypeByName(type));
    }
    String length = attributes.getValue("length");
    if (length != null) {
        parameter.setMaxLength(Integer.parseInt(length));
    }
    String precision = attributes.getValue("precision");
    if (precision != null) {
        parameter.setPrecision(Integer.parseInt(precision));
    }
    String direction = attributes.getValue("direction");
    if ("in".equals(direction)) {
        parameter.setDirection(ProcedureParameter.IN_PARAMETER);
    } else if ("out".equals(direction)) {
        parameter.setDirection(ProcedureParameter.OUT_PARAMETER);
    } else if ("in_out".equals(direction)) {
        parameter.setDirection(ProcedureParameter.IN_OUT_PARAMETER);
    }
    procedure.addCallParameter(parameter);
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) SAXException(org.xml.sax.SAXException)

Example 10 with ProcedureParameter

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

the class ProcedureColumnLoader method processResultSetRow.

@Override
protected void processResultSetRow(CatalogFilter catalog, SchemaFilter schema, DbLoadDataStore map, ResultSet rs) throws SQLException {
    String procSchema = rs.getString("PROCEDURE_SCHEM");
    String procCatalog = rs.getString("PROCEDURE_CAT");
    String name = rs.getString("PROCEDURE_NAME");
    String key = Procedure.generateFullyQualifiedName(procCatalog, procSchema, name);
    Procedure procedure = map.getProcedure(key);
    if (procedure == null) {
        return;
    }
    ProcedureParameter column = loadProcedureParams(rs, key, procedure);
    if (column == null) {
        return;
    }
    procedure.addCallParameter(column);
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) Procedure(org.apache.cayenne.map.Procedure)

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