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:com.mec.DAO.Passport.UserDAO.java

public Usuario getUser(String nombre, String clave) {
    Usuario u = null;/*www.  j a v  a 2 s.c  o m*/
    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:org.zalando.stups.jpa.example.sp.ExampleSP.java

public ExampleSP(final DataSource dataSource) {
    LOG.info("inside NextNumberStoredProcedure datasource: {}", dataSource);

    setDataSource(dataSource);//w  w  w.j av a 2  s  .  c om
    setFunction(true);
    setSql(STORED_PROCEDURE_NAME);
    declareParameter(new SqlParameter(IN_PARAMETER_NAME, Types.OTHER));
    declareParameter(new SqlOutParameter(OUT_PARAMETER_NAME, Types.VARCHAR));
    compile();
}

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  a2 s  .co m
    return (List<GrantedAuthority>) jdbcCall.execute(in).entrySet().iterator().next().getValue();
}

From source file:om.edu.squ.squportal.portlet.dps.dao.db.DpsDbImpl.java

/**
 * // w  w w  . j a  va  2 s  .c  om
 * method name  : getHigherApprover
 * @param studentNo
 * @param formName
 * @param roleName
 * @param isSequenceRequired
 * @return
 * DpsDbImpl
 * return type  : Approver
 * 
 * purpose      : Get higher approver (at intial and final case it's same approver)
 *
 * Date          :   Jul 16, 2017 11:59:33 AM
 */
public Approver getHigherApprover(String studentNo, String formName, String roleName,
        String isSequenceRequired) {
    String SP_APPROVER_NEXT = queryProps.getProperty(Constants.CONST_SP_APPROVER_NEXT);
    Map resultProc = null;
    Approver approver = new Approver();

    simpleJdbcCallDps.withProcedureName(SP_APPROVER_NEXT);
    simpleJdbcCallDps.withoutProcedureColumnMetaDataAccess();
    simpleJdbcCallDps.useInParameterNames(Constants.CONST_PARAM_NAME_STUDENT_NO,
            Constants.CONST_PARAM_NAME_FORM_NAME, Constants.CONST_PARAM_NAME_ROLE_NAME,
            Constants.CONST_PARAM_NAME_IS_SEQUENCE_REQUIRED);
    simpleJdbcCallDps.declareParameters(new SqlParameter(Constants.CONST_PARAM_NAME_STUDENT_NO, Types.VARCHAR),
            new SqlParameter(Constants.CONST_PARAM_NAME_FORM_NAME, Types.VARCHAR),
            new SqlParameter(Constants.CONST_PARAM_NAME_ROLE_NAME, Types.VARCHAR),
            new SqlParameter(Constants.CONST_PARAM_NAME_IS_SEQUENCE_REQUIRED, Types.VARCHAR),
            new SqlOutParameter(Constants.CONST_PARAM_NAME_APPROVER_NAME_ENG, Types.VARCHAR),
            new SqlOutParameter(Constants.CONST_PARAM_NAME_APPROVER_NAME_AR, Types.VARCHAR),
            new SqlOutParameter(Constants.CONST_PARAM_NAME_APPROVER_EMAIL, Types.VARCHAR),
            new SqlOutParameter(Constants.CONST_PARAM_NAME_APPROVER_PHONE, Types.VARCHAR),
            new SqlOutParameter(Constants.CONST_PARAM_NAME_ROLE_NAME_ENG, Types.VARCHAR),
            new SqlOutParameter(Constants.CONST_PARAM_NAME_ROLE_NAME_AR, Types.VARCHAR),
            new SqlOutParameter(Constants.CONST_PARAM_NAME_IS_HIGHER_APPROVER, Types.VARCHAR));

    Map<String, String> paramIn = new HashMap<String, String>();
    paramIn.put(Constants.CONST_PARAM_NAME_STUDENT_NO, studentNo);
    paramIn.put(Constants.CONST_PARAM_NAME_FORM_NAME, formName);
    paramIn.put(Constants.CONST_PARAM_NAME_ROLE_NAME, roleName);
    paramIn.put(Constants.CONST_PARAM_NAME_IS_SEQUENCE_REQUIRED, isSequenceRequired);

    resultProc = simpleJdbcCallDps.execute(paramIn);

    approver.setNameEng((String) resultProc.get(Constants.CONST_PARAM_NAME_APPROVER_NAME_ENG));
    approver.setNameAr((String) resultProc.get(Constants.CONST_PARAM_NAME_APPROVER_NAME_AR));
    approver.setEmail((String) resultProc.get(Constants.CONST_PARAM_NAME_APPROVER_EMAIL));
    approver.setRoleNameEng((String) resultProc.get(Constants.CONST_PARAM_NAME_ROLE_NAME_ENG));
    approver.setRoleNameAr((String) resultProc.get(Constants.CONST_PARAM_NAME_ROLE_NAME_AR));
    if (((String) resultProc.get(Constants.CONST_PARAM_NAME_IS_HIGHER_APPROVER)).equals(Constants.CONST_YES)) {
        approver.setHigherSequence(true);
    } else {
        approver.setHigherSequence(false);
    }

    resultProc = null;

    return approver;
}

From source file:architecture.ee.jdbc.sqlquery.factory.impl.SqlQueryImpl.java

public Object call(String statement, Object... parameters) {
    BoundSql sql = getBoundSql(statement);

    List<SqlParameter> declaredParameters = new ArrayList<SqlParameter>();
    Map<String, Object> paramsToUse = new HashMap<String, Object>();

    //  ?? ? INPUT  OUTPU ? .

    for (ParameterMapping mapping : sql.getParameterMappings()) {

        mapping.getProperty();// www. ja  v  a2 s .c o m
        mapping.getJdbcType();
        mapping.getMode();

        if (mapping.getMode() == ParameterMapping.Mode.IN) {

            SqlParameter input = new SqlParameter(mapping.getProperty(), mapping.getJdbcType().ordinal());
            declaredParameters.add(input);
            paramsToUse.put(mapping.getProperty(), parameters[mapping.getIndex() - 1]);

        } else if (mapping.getMode() == ParameterMapping.Mode.OUT) {
            SqlOutParameter output = new SqlOutParameter(mapping.getProperty(),
                    mapping.getJdbcType().ordinal());
            declaredParameters.add(output);
        }
    }

    CallableStatementCreatorFactory callableStatementFactory = new CallableStatementCreatorFactory(sql.getSql(),
            declaredParameters);
    return jdbcTemplate.call(callableStatementFactory.newCallableStatementCreator(paramsToUse),
            declaredParameters);

}

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

public void testCaseInsensitiveResultsMap() throws Exception {

    MockControl ctrlCallable;/* w  w  w . ja va 2s  . com*/
    CallableStatement mockCallable;

    ctrlCallable = MockControl.createControl(CallableStatement.class);
    mockCallable = (CallableStatement) ctrlCallable.getMock();
    mockCallable.execute();
    ctrlCallable.setReturnValue(false);
    mockCallable.getUpdateCount();
    ctrlCallable.setReturnValue(-1);
    mockCallable.getObject(1);
    ctrlCallable.setReturnValue("X");
    if (debugEnabled) {
        mockCallable.getWarnings();
        ctrlCallable.setReturnValue(null);
    }
    mockCallable.close();
    ctrlCallable.setVoidCallable();

    mockConnection.prepareCall("my query");
    ctrlConnection.setReturnValue(mockCallable);

    ctrlCallable.replay();
    replay();

    JdbcTemplate template = new JdbcTemplate(mockDataSource);
    assertTrue("default should have been NOT case insensitive", !template.isResultsMapCaseInsensitive());

    template.setResultsMapCaseInsensitive(true);
    assertTrue("now it should have been set to case insensitive", template.isResultsMapCaseInsensitive());

    List params = new ArrayList();
    params.add(new SqlOutParameter("a", 12));

    Map out = template.call(new CallableStatementCreator() {
        public CallableStatement createCallableStatement(Connection conn) throws SQLException {
            return conn.prepareCall("my query");
        }
    }, params);
    assertTrue("this should have been a LinkedCaseInsensitiveMap", out instanceof LinkedCaseInsensitiveMap);
    assertNotNull("we should have gotten the result with upper case", out.get("A"));
    assertNotNull("we should have gotten the result with lower case", out.get("a"));

    ctrlCallable.verify();
}

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

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

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

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

    initializeAddInvoiceWithoutMetaData(false);

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

    SimpleJdbcCall adder = new SimpleJdbcCall(mockDataSource).withProcedureName("add_invoice");
    adder.declareParameters(new SqlParameter("amount", Types.INTEGER),
            new SqlParameter("custid", Types.INTEGER), new SqlOutParameter("newid", Types.INTEGER));
    Number newId = adder.executeObject(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 testAddInvoiceProcWithoutMetaDataUsingArrayParams() throws Exception {
    final int amount = 1103;
    final int custid = 3;

    initializeAddInvoiceWithoutMetaData(false);

    replay();/*from  w  w  w  . j  ava  2s .c om*/

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

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();//w w  w .j  a va2  s  . com

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