18
18
19
19
import java .util .List ;
20
20
import java .util .Map ;
21
+ import java .util .stream .Stream ;
21
22
22
23
import javax .sql .DataSource ;
23
24
52
53
* @author Rod Johnson
53
54
* @author Juergen Hoeller
54
55
* @author Thomas Risberg
56
+ * @author Yanming Zhou
55
57
* @param <T> the result type
56
58
* @see SqlUpdate
57
59
*/
@@ -94,6 +96,23 @@ public List<T> execute(Object @Nullable [] params, @Nullable Map<?, ?> context)
94
96
return getJdbcTemplate ().query (newPreparedStatementCreator (params ), rowMapper );
95
97
}
96
98
99
+ /**
100
+ * Central execution method for Stream. All un-named parameter execution goes through this method.
101
+ * @param params parameters, similar to JDO query parameters.
102
+ * Primitive parameters must be represented by their Object wrapper type.
103
+ * The ordering of parameters is significant.
104
+ * @param context the contextual information passed to the {@code mapRow}
105
+ * callback method. The JDBC operation itself doesn't rely on this parameter,
106
+ * but it can be useful for creating the objects of the result list.
107
+ * @return a result Stream of objects, one per row of the ResultSet. Normally all these
108
+ * will be of the same class, although it is possible to use different types.
109
+ */
110
+ public Stream <T > executeForStream (Object @ Nullable [] params , @ Nullable Map <?, ?> context ) throws DataAccessException {
111
+ validateParameters (params );
112
+ RowMapper <T > rowMapper = newRowMapper (params , context );
113
+ return getJdbcTemplate ().queryForStream (newPreparedStatementCreator (params ), rowMapper );
114
+ }
115
+
97
116
/**
98
117
* Convenient method to execute without context.
99
118
* @param params parameters for the query. Primitive parameters must
@@ -104,6 +123,16 @@ public List<T> execute(Object... params) throws DataAccessException {
104
123
return execute (params , null );
105
124
}
106
125
126
+ /**
127
+ * Convenient method to execute for Stream without context.
128
+ * @param params parameters for the query. Primitive parameters must
129
+ * be represented by their Object wrapper type. The ordering of parameters is
130
+ * significant.
131
+ */
132
+ public Stream <T > executeForStream (Object ... params ) throws DataAccessException {
133
+ return executeForStream (params , null );
134
+ }
135
+
107
136
/**
108
137
* Convenient method to execute without parameters.
109
138
* @param context the contextual information for object creation
@@ -112,13 +141,28 @@ public List<T> execute(Map<?, ?> context) throws DataAccessException {
112
141
return execute ((Object []) null , context );
113
142
}
114
143
144
+ /**
145
+ * Convenient method to execute for Stream without parameters.
146
+ * @param context the contextual information for object creation
147
+ */
148
+ public Stream <T > executeForStream (Map <?, ?> context ) throws DataAccessException {
149
+ return executeForStream ((Object []) null , context );
150
+ }
151
+
115
152
/**
116
153
* Convenient method to execute without parameters nor context.
117
154
*/
118
155
public List <T > execute () throws DataAccessException {
119
156
return execute ((Object []) null , null );
120
157
}
121
158
159
+ /**
160
+ * Convenient method to execute for Stream without parameters nor context.
161
+ */
162
+ public Stream <T > executeForStream () throws DataAccessException {
163
+ return executeForStream ((Object []) null , null );
164
+ }
165
+
122
166
/**
123
167
* Convenient method to execute with a single int parameter and context.
124
168
* @param p1 single int parameter
0 commit comments