Search in sources :

Example 1 with InputParameter

use of org.apache.camel.component.sql.stored.template.ast.InputParameter in project camel by apache.

the class BatchCallableStatementCreatorFactory method createParams.

private List<SqlParameter> createParams() {
    List<SqlParameter> params = new ArrayList<>();
    for (Object parameter : template.getParameterList()) {
        if (parameter instanceof InputParameter) {
            InputParameter inputParameter = (InputParameter) parameter;
            params.add(new SqlParameter(inputParameter.getName(), inputParameter.getSqlType()));
        } else {
            throw new UnsupportedOperationException("Only IN parameters supported by batch!");
        }
    }
    return params;
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) ArrayList(java.util.ArrayList) InputParameter(org.apache.camel.component.sql.stored.template.ast.InputParameter)

Example 2 with InputParameter

use of org.apache.camel.component.sql.stored.template.ast.InputParameter in project camel by apache.

the class CallableStatementWrapper method addBatch.

@Override
public void addBatch(Object value, Exchange exchange) {
    if (this.batchFactory == null) {
        this.batchFactory = factory.getTemplateForBatch(template);
    }
    Map<String, Object> batchValues = new HashMap<>();
    //only IN-parameters supported by template
    for (Object param : this.batchFactory.getTemplate().getParameterList()) {
        InputParameter inputParameter = (InputParameter) param;
        Object paramValue = inputParameter.getValueExtractor().eval(exchange, value);
        batchValues.put(inputParameter.getName(), paramValue);
    }
    if (this.batchItems == null) {
        this.batchItems = new ArrayList<>();
    }
    batchItems.add(batchValues);
}
Also used : HashMap(java.util.HashMap) InputParameter(org.apache.camel.component.sql.stored.template.ast.InputParameter)

Example 3 with InputParameter

use of org.apache.camel.component.sql.stored.template.ast.InputParameter in project camel by apache.

the class ParserTest method shouldParseOk.

@Test
public void shouldParseOk() {
    Template template = parser.parseTemplate("addnumbers(INTEGER ${header.header1}," + "VARCHAR ${property.property1},BIGINT ${header.header2},OUT INTEGER header1)");
    Assert.assertEquals("addnumbers", template.getProcedureName());
    Assert.assertEquals(4, template.getParameterList().size());
    Exchange exchange = createExchangeWithBody(null);
    exchange.getIn().setHeader("header1", 1);
    exchange.setProperty("property1", "constant string");
    exchange.getIn().setHeader("header2", BigInteger.valueOf(2));
    InputParameter param1 = (InputParameter) template.getParameterList().get(0);
    Assert.assertEquals("_0", param1.getName());
    Assert.assertEquals(Types.INTEGER, param1.getSqlType());
    Assert.assertEquals(1, param1.getValueExtractor().eval(exchange, null));
    InputParameter param2 = (InputParameter) template.getParameterList().get(1);
    Assert.assertEquals("_1", param2.getName());
    Assert.assertEquals(Types.VARCHAR, param2.getSqlType());
    Assert.assertEquals("constant string", param2.getValueExtractor().eval(exchange, null));
    InputParameter param3 = (InputParameter) template.getParameterList().get(2);
    Assert.assertEquals("_2", param3.getName());
    Assert.assertEquals(Types.BIGINT, param3.getSqlType());
    Assert.assertEquals(BigInteger.valueOf(2L), param3.getValueExtractor().eval(exchange, null));
    OutParameter sptpOutputNode = (OutParameter) template.getParameterList().get(3);
    Assert.assertEquals("_3", sptpOutputNode.getName());
    Assert.assertEquals(Types.INTEGER, sptpOutputNode.getSqlType());
    Assert.assertEquals("header1", sptpOutputNode.getOutValueMapKey());
}
Also used : Exchange(org.apache.camel.Exchange) OutParameter(org.apache.camel.component.sql.stored.template.ast.OutParameter) InputParameter(org.apache.camel.component.sql.stored.template.ast.InputParameter) Template(org.apache.camel.component.sql.stored.template.ast.Template) Test(org.junit.Test)

Example 4 with InputParameter

use of org.apache.camel.component.sql.stored.template.ast.InputParameter in project camel by apache.

the class ParserTest method nableIssueSyntax.

@Test
public void nableIssueSyntax() {
    Map<String, String> params = new HashMap<>();
    params.put("P_STR_IN", "a");
    Template template = parser.parseTemplate("IBS.\"Z$IMS_INTERFACE_WS\".TEST_STR(VARCHAR :#P_STR_IN,OUT VARCHAR P_STR_OUT)");
    assertEquals("a", ((InputParameter) template.getParameterList().get(0)).getValueExtractor().eval(null, params));
    assertEquals("IBS.\"Z$IMS_INTERFACE_WS\".TEST_STR", template.getProcedureName());
}
Also used : HashMap(java.util.HashMap) InputParameter(org.apache.camel.component.sql.stored.template.ast.InputParameter) Template(org.apache.camel.component.sql.stored.template.ast.Template) Test(org.junit.Test)

Example 5 with InputParameter

use of org.apache.camel.component.sql.stored.template.ast.InputParameter in project camel by apache.

the class TemplateStoredProcedure method execute.

public Map execute(Exchange exchange, Object rowData) {
    Map<String, Object> params = new HashMap<>();
    for (InputParameter inputParameter : inputParameterList) {
        params.put(inputParameter.getName(), inputParameter.getValueExtractor().eval(exchange, rowData));
    }
    LOG.debug("Invoking stored procedure: {}", template.getProcedureName());
    return super.execute(params);
}
Also used : HashMap(java.util.HashMap) InputParameter(org.apache.camel.component.sql.stored.template.ast.InputParameter)

Aggregations

InputParameter (org.apache.camel.component.sql.stored.template.ast.InputParameter)6 HashMap (java.util.HashMap)3 Template (org.apache.camel.component.sql.stored.template.ast.Template)3 Test (org.junit.Test)3 Exchange (org.apache.camel.Exchange)2 ArrayList (java.util.ArrayList)1 OutParameter (org.apache.camel.component.sql.stored.template.ast.OutParameter)1 SqlParameter (org.springframework.jdbc.core.SqlParameter)1