/** * Convenient method to execute without context. * @param paramMap parameters associated with the name specified while declaring * the SqlParameters. Primitive parameters must be represented by their Object wrapper * type. The ordering of parameters is not significant. */ public List<T> executeByNamedParam(Map<String, ?> paramMap) throws DataAccessException { return executeByNamedParam(paramMap, null); }
/** * Generic object finder method for named parameters. * @param paramMap a Map of parameter name to parameter object, * matching named parameters specified in the SQL statement. * Ordering is not significant. * @param context contextual information passed to the {@code mapRow} * callback method. The JDBC operation itself doesn't rely on this parameter, * but it can be useful for creating the objects of the result list. * @return a List of objects, one per row of the ResultSet. Normally all these * will be of the same class, although it is possible to use different types. */ @Nullable public T findObjectByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException { List<T> results = executeByNamedParam(paramMap, context); return DataAccessUtils.singleResult(results); }
private void doTestCustomerQuery(SqlQuery<?> query, boolean namedParameters) throws SQLException { given(resultSet.next()).willReturn(true); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); given(resultSet.next()).willReturn(true, false); given(preparedStatement.executeQuery()).willReturn(resultSet); given(connection.prepareStatement(SELECT_ID_FORENAME_NAMED_PARAMETERS_PARSED)).willReturn(preparedStatement); List<?> queryResults; if (namedParameters) { Map<String, Object> params = new HashMap<>(2); params.put("id", 1); params.put("country", "UK"); queryResults = query.executeByNamedParam(params); } else { Object[] params = new Object[] {1, "UK"}; queryResults = query.execute(params); } assertTrue("Customer was returned correctly", queryResults.size() == 1); Customer cust = (Customer) queryResults.get(0); assertTrue("Customer id was assigned correctly", cust.getId() == 1); assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod")); verify(resultSet).close(); verify(preparedStatement).setObject(1, 1, Types.INTEGER); verify(preparedStatement).setString(2, "UK"); verify(preparedStatement).close(); }
/** * Convenient method to execute without context. * @param paramMap parameters associated with the name specified while declaring * the SqlParameters. Primitive parameters must be represented by their Object wrapper * type. The ordering of parameters is not significant. */ public List<T> executeByNamedParam(Map<String, ?> paramMap) throws DataAccessException { return executeByNamedParam(paramMap, null); }
/** * Convenient method to execute without context. * @param paramMap parameters associated with the name specified while declaring * the SqlParameters. Primitive parameters must be represented by their Object wrapper * type. The ordering of parameters is not significant. */ public List<T> executeByNamedParam(Map<String, ?> paramMap) throws DataAccessException { return executeByNamedParam(paramMap, null); }
/** * Generic object finder method for named parameters. * @param paramMap Map of parameter name to parameter object, * matching named parameters specified in the SQL statement. * Ordering is not significant. * @param context contextual information passed to the {@code mapRow} * callback method. The JDBC operation itself doesn't rely on this parameter, * but it can be useful for creating the objects of the result list. * @return a List of objects, one per row of the ResultSet. Normally all these * will be of the same class, although it is possible to use different types. */ public T findObjectByNamedParam(Map<String, ?> paramMap, Map context) throws DataAccessException { List<T> results = executeByNamedParam(paramMap, context); return DataAccessUtils.singleResult(results); }