Package org.springframework.jdbc.core.namedparam

Examples of org.springframework.jdbc.core.namedparam.MapSqlParameterSource


   * @return the number of rows affected by the update
   */
  public int updateByNamedParam(Map paramMap, KeyHolder generatedKeyHolder) throws DataAccessException {
    validateNamedParameters(paramMap);
    ParsedSql parsedSql = getParsedSql();
    MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
    int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder);
    checkRowsAffected(rowsAffected);
    return rowsAffected;
View Full Code Here


   * will be of the same class, although it is possible to use different types.
   */
  public List executeByNamedParam(Map paramMap, Map context) throws DataAccessException {
    validateNamedParameters(paramMap);
    ParsedSql parsedSql = getParsedSql();
    MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
    String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
    Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
    RowMapper rowMapper = newRowMapper(params, context);
     return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
  }
View Full Code Here

  /**
   * Creates a {@link MapSqlParameterSource} based on data values from the
   * supplied {@link Pet} instance.
   */
  private MapSqlParameterSource createPetParameterSource(Pet pet) {
    return new MapSqlParameterSource()
      .addValue("id", pet.getId())
      .addValue("name", pet.getName())
      .addValue("birth_date", pet.getBirthDate())
      .addValue("type_id", pet.getType().getId())
      .addValue("owner_id", pet.getOwner().getId());
View Full Code Here

  /**
   * Creates a {@link MapSqlParameterSource} based on data values from the
   * supplied {@link Visit} instance.
   */
  private MapSqlParameterSource createVisitParameterSource(Visit visit) {
    return new MapSqlParameterSource()
      .addValue("id", visit.getId())
      .addValue("visit_date", visit.getDate())
      .addValue("description", visit.getDescription())
      .addValue("pet_id", visit.getPet().getId());
  }
View Full Code Here

    int arg1 = 24;
    String arg2 = "foo";

    MockControl mc = MockControl.createControl(NamedParameterJdbcOperations.class);
    NamedParameterJdbcOperations npjo = (NamedParameterJdbcOperations) mc.getMock();
    SqlParameterSource args = new MapSqlParameterSource().addValue("id", arg1).addValue("xy", arg2);
    npjo.queryForInt(sql, args);
    mc.setDefaultMatcher(new ArrayMatcher());
    mc.setReturnValue(expectedResult);
    mc.replay();
View Full Code Here

    args.put("3", 3);
    testDelegation("queryForList", new Object[]{"sql"}, new Object[]{args}, new LinkedList());
  }

  public void testQueryForListWithSqlParameterSource() throws Exception {
    MapSqlParameterSource args = new MapSqlParameterSource();
    args.addValue("1", 1);
    args.addValue("2", 2);
    args.addValue("3", 3);
    testDelegation("queryForList", new Object[]{"sql"}, new Object[]{args}, new LinkedList());
  }
View Full Code Here

    args.put("3", 3);
    testDelegation("queryForMap", new Object[]{"sql"}, new Object[]{args}, new HashMap());
  }

  public void testQueryForMapWithSqlParameterSource() throws Exception {
    MapSqlParameterSource args = new MapSqlParameterSource();
    args.addValue("1", 1);
    args.addValue("2", 2);
    args.addValue("3", 3);
    testDelegation("queryForMap", new Object[]{"sql"}, new Object[]{args}, new HashMap());
  }
View Full Code Here

    args.put("3", 3);
    testDelegation("update", new Object[]{"sql"}, new Object[]{args}, 666);
  }

  public void testUpdateWithSqlParameterSource() throws Exception {
    MapSqlParameterSource args = new MapSqlParameterSource();
    args.addValue("1", 1);
    args.addValue("2", 2);
    args.addValue("3", 3);
    testDelegation("update", new Object[]{"sql"}, new Object[]{args}, 666);
  }
View Full Code Here

    ctrlDataSource.setDefaultReturnValue(mockConnection);

    final String sqlToUse = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
    final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id";
    final SqlParameterSource[] ids = new SqlParameterSource[2];
    ids[0] = new MapSqlParameterSource("id", 100);
    ids[1] = new MapSqlParameterSource("id", 200);
    final int[] rowsAffected = new int[] { 1, 2 };


    MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class);
    PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock();
View Full Code Here

    List<SqlParameter> parameters = new ArrayList<SqlParameter>();
    parameters.add(new SqlParameter("id", Types.NUMERIC));
    parameters.add(new SqlInOutParameter("name", Types.NUMERIC));
    parameters.add(new SqlOutParameter("customer_no", Types.NUMERIC));

    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("id", 1);
    parameterSource.addValue("name", "Sven");
    parameterSource.addValue("customer_no", "12345XYZ");

    context.setProcedureName(TABLE);
    context.initializeMetaData(mockDataSource);
    context.processParameters(parameters);
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.namedparam.MapSqlParameterSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.