Example usage for org.springframework.jdbc.core SqlOutParameter SqlOutParameter

List of usage examples for org.springframework.jdbc.core SqlOutParameter SqlOutParameter

Introduction

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

Prototype

public SqlOutParameter(String name, int sqlType) 

Source Link

Document

Create a new SqlOutParameter.

Usage

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();/*  w  ww.  jav  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:rapture.repo.jdbc.JDBCStructuredStore.java

@Override
public StoredProcedureResponse callProcedure(CallingContext context, String procName,
        StoredProcedureParams params) {/*from  www .j av a2s . 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);
    }

}