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

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

Introduction

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

Prototype

@Nullable
public String getTypeName() 

Source Link

Document

Return the type name of the parameter, if any.

Usage

From source file:cc.tooyoung.common.db.JdbcTemplate.java

/**
 * Extract output parameters from the completed stored procedure.
 * @param cs JDBC wrapper for the stored procedure
 * @param parameters parameter list for the stored procedure
 * @return Map that contains returned results
 *//* w  w w .  j  a v  a2s . c o  m*/
@SuppressWarnings("unchecked")
protected Map extractOutputParameters(CallableStatement cs, List parameters) throws SQLException {
    Map returnedResults = new HashMap();
    int sqlColIndex = 1;
    for (int i = 0; i < parameters.size(); i++) {
        SqlParameter param = (SqlParameter) parameters.get(i);
        if (param instanceof SqlOutParameter) {
            SqlOutParameter outParam = (SqlOutParameter) param;
            if (outParam.isReturnTypeSupported()) {
                Object out = outParam.getSqlReturnType().getTypeValue(cs, sqlColIndex, outParam.getSqlType(),
                        outParam.getTypeName());
                returnedResults.put(outParam.getName(), out);
            } else {
                Object out = cs.getObject(sqlColIndex);
                if (out instanceof ResultSet) {
                    if (outParam.isResultSetSupported()) {
                        returnedResults.putAll(processResultSet((ResultSet) out, outParam));
                    } else {
                        String rsName = outParam.getName();
                        SqlReturnResultSet rsParam = new SqlReturnResultSet(rsName, new ColumnMapRowMapper());
                        returnedResults.putAll(processResultSet(cs.getResultSet(), rsParam));
                        ApiLogger.info("Added default SqlReturnResultSet parameter named " + rsName);
                    }
                } else {
                    returnedResults.put(outParam.getName(), out);
                }
            }
        }
        if (!(param.isResultsParameter())) {
            sqlColIndex++;
        }
    }
    return returnedResults;
}

From source file:org.springframework.jdbc.core.JdbcTemplate.java

/**
 * Extract output parameters from the completed stored procedure.
 * @param cs JDBC wrapper for the stored procedure
 * @param parameters parameter list for the stored procedure
 * @return parameters to the stored procedure
 * @return Map that contains returned results
 *//*  w  w w .java  2s . c om*/
protected Map extractOutputParameters(CallableStatement cs, List parameters) throws SQLException {
    Map returnedResults = new HashMap();
    int sqlColIndex = 1;
    for (int i = 0; i < parameters.size(); i++) {
        Object param = parameters.get(i);
        if (param instanceof SqlOutParameter) {
            SqlOutParameter outParam = (SqlOutParameter) param;
            if (outParam.isReturnTypeSupported()) {
                Object out = outParam.getSqlReturnType().getTypeValue(cs, sqlColIndex, outParam.getSqlType(),
                        outParam.getTypeName());
                returnedResults.put(outParam.getName(), out);
            } else {
                Object out = cs.getObject(sqlColIndex);
                if (out instanceof ResultSet) {
                    if (outParam.isResultSetSupported()) {
                        returnedResults.putAll(processResultSet((ResultSet) out, outParam));
                    } else {
                        logger.warn("ResultSet returned from stored procedure but a corresponding "
                                + "SqlOutParameter with a RowCallbackHandler was not declared");
                        returnedResults.put(outParam.getName(), "ResultSet was returned but not processed.");
                    }
                } else {
                    returnedResults.put(outParam.getName(), out);
                }
            }
        }
        if (!(param instanceof SqlReturnResultSet)) {
            sqlColIndex++;
        }
    }
    return returnedResults;
}