@Test public void sqlParameterValueRegistersSqlType() throws Exception { MapSqlParameterSource msps = new MapSqlParameterSource("FOO", new SqlParameterValue(2, "Foo")); assertEquals("Correct SQL Type not registered", 2, msps.getSqlType("FOO")); MapSqlParameterSource msps2 = new MapSqlParameterSource(); msps2.addValues(msps.getValues()); assertEquals("Correct SQL Type not registered", 2, msps2.getSqlType("FOO")); }
/** * Create a Map of case insensitive parameter names together with the original name. * @param parameterSource the source of paramer names * @return the Map that can be used for case insensitive matching of parameter names */ public static Map extractCaseInsensitiveParameterNames(SqlParameterSource parameterSource) { Map caseInsensitiveParameterNames = new HashMap(); if (parameterSource instanceof BeanPropertySqlParameterSource) { String[] propertyNames = ((BeanPropertySqlParameterSource)parameterSource).getReadablePropertyNames(); for (int i = 0; i < propertyNames.length; i++) { String name = propertyNames[i]; caseInsensitiveParameterNames.put(name.toLowerCase(), name); } } else if (parameterSource instanceof MapSqlParameterSource) { for (String name : ((MapSqlParameterSource) parameterSource).getValues().keySet()) { caseInsensitiveParameterNames.put(name.toLowerCase(), name); } } return caseInsensitiveParameterNames; }
protected String generateQuery(String sql, MapSqlParameterSource args) { if (sql == null) { return null; } String preparedSql = NamedParameterUtils.substituteNamedParameters(sql, args); List<?> valueList = Arrays.asList(NamedParameterUtils.buildValueArray(sql, args.getValues())); preparedSql = preparedSql.replaceAll(" ", " "); for (Object value : valueList) { preparedSql = prepareParsedSQLLog(preparedSql, value); } return preparedSql; } private String prepareParsedSQLLog(String parsedSql, Object v) {
Map<String,Object> argPairs = Collections.emptyMap(); if (args != null) { argPairs = args.getValues();
Map<String, Object> parameters = args != null ? args.getValues() : new HashMap<String, Object>();
MapSqlParameterSource mapSqlParameterSource = (MapSqlParameterSource) sqlParameterSource; Iterator<SqlParameter> declaredParameterIterator = declaredParameters.iterator(); Set<String> parameterNameSet = mapSqlParameterSource.getValues().keySet(); while (declaredParameterIterator.hasNext()) { SqlParameter parameter = declaredParameterIterator.next();
throws SQLException { Map<String, Object> values = paramSource.getValues(); for (Map.Entry<String, SqlCallParameter> paramOrderEntry : paramOrder.entrySet()) { String paramName = paramOrderEntry.getKey();
msp.addValues(((MapSqlParameterSource) arg).getValues()); continue;
private <S, T> MapSqlParameterSource getPropertyMap(final S instance, RelationalPersistentEntity<S> persistentEntity, String prefix) { MapSqlParameterSource parameters = new MapSqlParameterSource(); PersistentPropertyAccessor<S> propertyAccessor = persistentEntity.getPropertyAccessor(instance); persistentEntity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) property -> { if (property.isEntity() && !property.isEmbedded()) { return; } if(property.isEmbedded()){ Object value = propertyAccessor.getProperty(property); final RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType()); final MapSqlParameterSource additionalParameters = getPropertyMap((T)value, (RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix()); parameters.addValues(additionalParameters.getValues()); } else { Object value = propertyAccessor.getProperty(property); Object convertedValue = converter.writeValue(value, ClassTypeInformation.from(property.getColumnType())); parameters.addValue(prefix + property.getColumnName(), convertedValue, JdbcUtil.sqlTypeFor(property.getColumnType())); } }); return parameters; }