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

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

Introduction

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

Prototype

@Override
    public Map<String, Object> execute(SqlParameterSource parameterSource) 

Source Link

Usage

From source file:com.mec.DAO.Passport.UserDAO.java

public List<GrantedAuthority> getUserRoles(Integer userID) {
    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(ds).withCatalogName("SqlSp")
            .withProcedureName("paRolesGetByIdUsuario").withoutProcedureColumnMetaDataAccess()
            .declareParameters(new SqlParameter("idAplicacion", Types.INTEGER))
            .declareParameters(new SqlParameter("idUsuario", Types.INTEGER))
            .declareParameters(new SqlOutParameter("ErrText", Types.VARCHAR))
            .returningResultSet("items", new MyRowMapper());
    SqlParameterSource in = new MapSqlParameterSource().addValue("idAplicacion", 1).addValue("idUsuario",
            userID);//from  w  w  w  .  ja  v a  2s .co m
    return (List<GrantedAuthority>) jdbcCall.execute(in).entrySet().iterator().next().getValue();
}

From source file:com.mec.DAO.Passport.UserDAO.java

public Usuario getUser(String nombre, String clave) {
    Usuario u = null;/*from   ww w  . ja  va  2 s. c om*/
    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(ds).withCatalogName("dbo")
            .withProcedureName("paValidarUsuario").withoutProcedureColumnMetaDataAccess()
            .declareParameters(new SqlParameter("NombreUsuario", Types.VARCHAR))
            .declareParameters(new SqlParameter("Clave", Types.VARCHAR))
            .declareParameters(new SqlOutParameter("UserId", Types.INTEGER))
            .declareParameters(new SqlOutParameter("ErrText", Types.VARCHAR));
    SqlParameterSource in = new MapSqlParameterSource().addValue("NombreUsuario", nombre).addValue("Clave",
            clave);
    Map<String, Object> r = jdbcCall.execute(in);
    Integer userId = null;
    String errText = "";
    for (Map.Entry<String, Object> entry : r.entrySet()) {
        String key = entry.getKey();
        if (key.equals("UserId")) {
            userId = (Integer) entry.getValue();
        } else if (key.equals("ErrText")) {
            errText = (String) entry.getValue();
        }
    }
    if (userId != null && errText.equals("Ok")) {
        List<GrantedAuthority> roles = getUserRoles(userId);
        u = new Usuario(userId, roles);
    }
    return u;
}

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

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

}