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