Example usage for org.springframework.jdbc.core.simple SimpleJdbcCall SimpleJdbcCall

List of usage examples for org.springframework.jdbc.core.simple SimpleJdbcCall SimpleJdbcCall

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.simple SimpleJdbcCall SimpleJdbcCall.

Prototype

public SimpleJdbcCall(JdbcTemplate jdbcTemplate) 

Source Link

Document

Alternative Constructor that takes one parameter with the JdbcTemplate to be used.

Usage

From source file:org.springframework.jdbc.core.simple.SimpleJdbcCallTests.java

public void testAddInvoiceFuncWithoutMetaDataUsingMapParamSource() throws Exception {
    final int amount = 1103;
    final int custid = 3;

    initializeAddInvoiceWithoutMetaData(true);

    replay();/*from   w  w  w.j  a  v a  2 s  .  c o  m*/

    SimpleJdbcCall adder = new SimpleJdbcCall(mockDataSource).withFunctionName("add_invoice");
    adder.declareParameters(new SqlOutParameter("return", Types.INTEGER),
            new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER));
    Number newId = adder.executeFunction(Number.class,
            new MapSqlParameterSource().addValue("amount", amount).addValue("custid", custid));
    assertEquals(4, newId.intValue());
}

From source file:org.springframework.jdbc.core.simple.SimpleJdbcCallTests.java

public void testAddInvoiceFuncWithoutMetaDataUsingArrayParams() throws Exception {
    final int amount = 1103;
    final int custid = 3;

    initializeAddInvoiceWithoutMetaData(true);

    replay();/*ww w  . j  av  a  2s .c  o m*/

    SimpleJdbcCall adder = new SimpleJdbcCall(mockDataSource).withFunctionName("add_invoice");
    adder.declareParameters(new SqlOutParameter("return", Types.INTEGER),
            new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER));
    Number newId = adder.executeFunction(Number.class, amount, custid);
    assertEquals(4, newId.intValue());
}

From source file:org.springframework.jdbc.core.simple.SimpleJdbcCallTests.java

public void testAddInvoiceFuncWithMetaDataUsingMapParamSource() throws Exception {
    final int amount = 1103;
    final int custid = 3;

    MockControl ctrlResultSet = initializeAddInvoiceWithMetaData(true);

    ctrlResultSet.replay();/*w  ww.  j  av  a 2  s.c o m*/
    replay();

    SimpleJdbcCall adder = new SimpleJdbcCall(mockDataSource).withFunctionName("add_invoice");
    Number newId = adder.executeFunction(Number.class,
            new MapSqlParameterSource().addValue("amount", amount).addValue("custid", custid));
    assertEquals(4, newId.intValue());

    ctrlResultSet.verify();
}

From source file:org.springframework.jdbc.core.simple.SimpleJdbcCallTests.java

public void testAddInvoiceFuncWithMetaDataUsingArrayParams() throws Exception {
    final int amount = 1103;
    final int custid = 3;

    MockControl ctrlResultSet = initializeAddInvoiceWithMetaData(true);

    ctrlResultSet.replay();//from   ww w.  j a va 2s. com
    replay();

    SimpleJdbcCall adder = new SimpleJdbcCall(mockDataSource).withFunctionName("add_invoice");
    Number newId = adder.executeFunction(Number.class, amount, custid);
    assertEquals(4, newId.intValue());

    ctrlResultSet.verify();
}

From source file:rapture.repo.jdbc.JDBCStructuredStore.java

@Override
public StoredProcedureResponse callProcedure(CallingContext context, String procName,
        StoredProcedureParams params) {//  w w  w  . jav  a 2 s .  c om

    // TODO RAP-3548 Need to check entitlements

    SimpleJdbcCall call = new SimpleJdbcCall(jdbc).withProcedureName(procName)
            .withoutProcedureColumnMetaDataAccess();
    MapSqlParameterSource paramSource = new MapSqlParameterSource();

    Map<String, Object> inParams = (params == null) ? null : params.getInParams();
    Map<String, Integer> outParams = (params == null) ? null : params.getOutParams();
    Map<String, Object> inOutParams = (params == null) ? null : params.getInOutParams();

    if (inParams != null) {
        // Declare Parameters
        Map<String, Integer> inParamTypes = getInputParamTypes(inParams);
        for (Map.Entry<String, Integer> entry : inParamTypes.entrySet()) {
            call.declareParameters(new SqlParameter(entry.getKey(), entry.getValue()));
        }

        // Give Input Parameters
        for (Map.Entry<String, Object> entry : inParams.entrySet()) {
            paramSource.addValue(entry.getKey(), entry.getValue());
        }
    }

    if (inOutParams != null) {
        Map<String, Integer> inOutParamTypes = getInputParamTypes(inOutParams);
        for (Map.Entry<String, Integer> entry : inOutParamTypes.entrySet()) {
            call.declareParameters(new SqlInOutParameter(entry.getKey(), entry.getValue()));
        }

        // Give Input Parameters
        for (Map.Entry<String, Object> entry : inOutParams.entrySet()) {
            paramSource.addValue(entry.getKey(), entry.getValue());
        }
    }

    if (outParams != null) {
        for (Map.Entry<String, Integer> entry : outParams.entrySet()) {
            call.declareParameters(new SqlOutParameter(entry.getKey(), entry.getValue()));
        }
    }

    try {
        return packageStoredProcedureReturn(call.execute(paramSource), true);
    } catch (BadSqlGrammarException e) {
        log.error(e.getSQLException());
        return packageStoredProcedureReturn(null, false);
    }

}

From source file:xc.mst.repo.RepositoryDAO.java

@Override
public void setDataSource(DataSource dataSource) {
    super.setDataSource(dataSource);
    this.getNextOaiId = new SimpleJdbcCall(jdbcTemplate).withFunctionName("get_next_oai_id");
}