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

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

Introduction

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

Prototype

public SqlInOutParameter(String name, int sqlType) 

Source Link

Document

Create a new SqlInOutParameter.

Usage

From source file:org.metis.jdbc.WdsStoredProcedure.java

public WdsStoredProcedure(SqlStmnt stmt) throws Exception {

    super(stmt.getJdbcTemplate(), stmt.getStoredProcName());

    setFunction(stmt.isFunction());/*from   www  .  ja v a  2 s  .  co m*/
    myStmt = stmt;

    // Parameters should be declared in the same order that
    // they are declared in the stored procedure. The one exception
    // are result sets, which must be defined first!!
    //
    // Here's something I found as to why - When you make any private
    // static class of StoreProcedure, then in its constructor you must
    // declare SqlReturnResultSet before you declare SqlParameter.
    // Otherwise you will not be able to find return data from
    // StoredProcedure execution. Still not sure what this means
    // and why its so.
    //
    for (SqlToken sqlToken : myStmt.getSortedKeyTokens()) {
        if (sqlToken.isRset()) {
            declareParameter(new SqlReturnResultSet(sqlToken.getKey(), myStmt));
        }
    }

    // now do the other parameters
    // iterate through tokens in proper sequence; parameters must be
    // declared according to the sequence in which they appear in the
    // statement
    for (SqlToken sqlToken : myStmt.getSortedKeyTokens()) {

        // skip result sets
        if (sqlToken.isRset()) {
            continue;
        }

        switch (sqlToken.getMode()) {
        case IN:
            declareParameter(new SqlParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType()));
            break;
        case OUT:
            // look for CURSOR types
            if (sqlToken.isCursor()) {
                // if it is a cursor then check to see if it is Oracle or
                // some other DBMS and set the type accrodingly
                int type = (myStmt.getMetisController().isOracle()) ? ORACLE_CURSOR : Types.OTHER;
                declareParameter(new SqlOutParameter(sqlToken.getKey(), type, myStmt));
            } else {
                declareParameter(new SqlOutParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType()));
            }
            break;
        case INOUT:
            // note: you can't have cursors as IN params - doesn't
            // make sense, so don't check for them when its an INOUT
            declareParameter(new SqlInOutParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType()));
            break;
        default:
            throw new Exception("WdsStoredProcedure: this invalid mode was provided: " + sqlToken.getMode());
        }
    }

    // specify whether this is a function
    super.setFunction(myStmt.isFunction());

    // compile the statement
    compile();
}

From source file:org.springframework.jdbc.core.metadata.GenericCallMetaDataProvider.java

@Override
public SqlParameter createDefaultInOutParameter(String parameterName, CallParameterMetaData meta) {
    return new SqlInOutParameter(parameterName, meta.getSqlType());
}

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

@Override
public StoredProcedureResponse callProcedure(CallingContext context, String procName,
        StoredProcedureParams params) {/*from  w  w  w  .j a va2  s.c  o  m*/

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

}