22
22
import org .springframework .jdbc .core .SqlParameterValue ;
23
23
24
24
/**
25
- * Class that provides helper methods for the use of {@link SqlParameterSource}
26
- * with {@code SimpleJdbc} classes .
25
+ * Class that provides helper methods for the use of {@link SqlParameterSource},
26
+ * in particular with {@link NamedParameterJdbcTemplate} .
27
27
*
28
28
* @author Thomas Risberg
29
29
* @since 2.5
30
30
*/
31
31
public class SqlParameterSourceUtils {
32
32
33
33
/**
34
- * Create an array of MapSqlParameterSource objects populated with data from the
35
- * values passed in. This will define what is included in a batch operation.
36
- * @param valueMaps array of Maps containing the values to be used
37
- * @return an array of SqlParameterSource
34
+ * Create an array of {@link MapSqlParameterSource} objects populated with data from
35
+ * the values passed in. This will define what is included in a batch operation.
36
+ * @param valueMaps array of {@link Map} instances containing the values to be used
37
+ * @return an array of {@link SqlParameterSource}
38
+ * @see MapSqlParameterSource
39
+ * @see NamedParameterJdbcTemplate#batchUpdate(String, Map[])
38
40
*/
39
41
public static SqlParameterSource [] createBatch (Map <String , ?>[] valueMaps ) {
40
42
MapSqlParameterSource [] batch = new MapSqlParameterSource [valueMaps .length ];
41
43
for (int i = 0 ; i < valueMaps .length ; i ++) {
42
- Map <String , ?> valueMap = valueMaps [i ];
43
- batch [i ] = new MapSqlParameterSource (valueMap );
44
+ batch [i ] = new MapSqlParameterSource (valueMaps [i ]);
44
45
}
45
46
return batch ;
46
47
}
47
48
48
49
/**
49
- * Create an array of BeanPropertySqlParameterSource objects populated with data
50
+ * Create an array of {@link BeanPropertySqlParameterSource} objects populated with data
50
51
* from the values passed in. This will define what is included in a batch operation.
51
52
* @param beans object array of beans containing the values to be used
52
- * @return an array of SqlParameterSource
53
+ * @return an array of {@link SqlParameterSource}
54
+ * @see BeanPropertySqlParameterSource
55
+ * @see NamedParameterJdbcTemplate#batchUpdate(String, SqlParameterSource[])
53
56
*/
54
57
public static SqlParameterSource [] createBatch (Object [] beans ) {
55
58
BeanPropertySqlParameterSource [] batch = new BeanPropertySqlParameterSource [beans .length ];
56
59
for (int i = 0 ; i < beans .length ; i ++) {
57
- Object bean = beans [i ];
58
- batch [i ] = new BeanPropertySqlParameterSource (bean );
60
+ batch [i ] = new BeanPropertySqlParameterSource (beans [i ]);
59
61
}
60
62
return batch ;
61
63
}
62
64
63
65
/**
64
66
* Create a wrapped value if parameter has type information, plain object if not.
65
- * @param source the source of paramer values and type information
67
+ * @param source the source of parameter values and type information
66
68
* @param parameterName the name of the parameter
67
69
* @return the value object
68
70
*/
@@ -83,13 +85,13 @@ public static Object getTypedValue(SqlParameterSource source, String parameterNa
83
85
84
86
/**
85
87
* Create a Map of case insensitive parameter names together with the original name.
86
- * @param parameterSource the source of paramer names
88
+ * @param parameterSource the source of parameter names
87
89
* @return the Map that can be used for case insensitive matching of parameter names
88
90
*/
89
91
public static Map <String , String > extractCaseInsensitiveParameterNames (SqlParameterSource parameterSource ) {
90
92
Map <String , String > caseInsensitiveParameterNames = new HashMap <String , String >();
91
93
if (parameterSource instanceof BeanPropertySqlParameterSource ) {
92
- String [] propertyNames = ((BeanPropertySqlParameterSource )parameterSource ).getReadablePropertyNames ();
94
+ String [] propertyNames = ((BeanPropertySqlParameterSource ) parameterSource ).getReadablePropertyNames ();
93
95
for (String name : propertyNames ) {
94
96
caseInsensitiveParameterNames .put (name .toLowerCase (), name );
95
97
}
0 commit comments