42
42
import org .springframework .dao .DataAccessException ;
43
43
import org .springframework .dao .EmptyResultDataAccessException ;
44
44
import org .springframework .jdbc .core .JdbcTemplate ;
45
+ import org .springframework .jdbc .core .RowMapper ;
45
46
import org .springframework .jdbc .core .namedparam .MapSqlParameterSource ;
46
47
import org .springframework .jdbc .core .namedparam .NamedParameterJdbcDaoSupport ;
47
- import org .springframework .jdbc .core .simple .ParameterizedRowMapper ;
48
- import org .springframework .jdbc .core .simple .SimpleJdbcTemplate ;
48
+ import org .springframework .jdbc .core .namedparam .NamedParameterJdbcTemplate ;
49
49
import org .springframework .jdbc .support .GeneratedKeyHolder ;
50
50
import org .springframework .jdbc .support .KeyHolder ;
51
51
@@ -66,11 +66,11 @@ public class JdbcMessageDAO extends NamedParameterJdbcDaoSupport implements
66
66
private static final String RESPONSE_HEADER_TIME = "headerTime" ;
67
67
private static final String RESPONSE_CONTENT_TIME = "contentTime" ;
68
68
69
- private static final ParameterizedRowMapper <MutableBufferedRequest > REQUEST_MAPPER = new RequestMapper ();
70
- private static final ParameterizedRowMapper <MutableBufferedResponse > RESPONSE_MAPPER = new ResponseMapper ();
71
- private static final ParameterizedRowMapper <byte []> CONTENT_MAPPER = new ContentMapper ();
72
- private static final ParameterizedRowMapper <Integer > ID_MAPPER = new IdMapper ();
73
- private static final ParameterizedRowMapper <Conversation > CONVERSATION_MAPPER = new ConversationMapper ();
69
+ private static final RowMapper <MutableBufferedRequest > REQUEST_MAPPER = new RequestMapper ();
70
+ private static final RowMapper <MutableBufferedResponse > RESPONSE_MAPPER = new ResponseMapper ();
71
+ private static final RowMapper <byte []> CONTENT_MAPPER = new ContentMapper ();
72
+ private static final RowMapper <Integer > ID_MAPPER = new IdMapper ();
73
+ private static final RowMapper <Conversation > CONVERSATION_MAPPER = new ConversationMapper ();
74
74
75
75
private final static String INSERT_CONTENT = "INSERT INTO contents (content, size) VALUES (:content, :size)" ;
76
76
@@ -188,9 +188,8 @@ public Collection<Integer> listConversationsSince(int id)
188
188
MapSqlParameterSource params = new MapSqlParameterSource ();
189
189
try {
190
190
params .addValue (ID , id , Types .INTEGER );
191
- SimpleJdbcTemplate template = new SimpleJdbcTemplate (
192
- getNamedParameterJdbcTemplate ());
193
- return template .query (SELECT_CONVERSATIONS , ID_MAPPER , params );
191
+ NamedParameterJdbcTemplate template = getNamedParameterJdbcTemplate ();
192
+ return template .query (SELECT_CONVERSATIONS , params , ID_MAPPER );
194
193
} catch (EmptyResultDataAccessException erdae ) {
195
194
return Collections .emptyList ();
196
195
}
@@ -205,9 +204,8 @@ public int getMessageContentId(int headerId) throws DataAccessException {
205
204
try {
206
205
MapSqlParameterSource params = new MapSqlParameterSource ();
207
206
params .addValue (ID , headerId , Types .INTEGER );
208
- SimpleJdbcTemplate template = new SimpleJdbcTemplate (
209
- getNamedParameterJdbcTemplate ());
210
- return template .queryForInt (SELECT_CONTENT_ID , params );
207
+ NamedParameterJdbcTemplate template = getNamedParameterJdbcTemplate ();
208
+ return template .queryForObject (SELECT_CONTENT_ID , params , Integer .class );
211
209
} catch (EmptyResultDataAccessException erdae ) {
212
210
return -1 ;
213
211
}
@@ -222,9 +220,8 @@ public int getMessageContentSize(int id) throws DataAccessException {
222
220
try {
223
221
MapSqlParameterSource params = new MapSqlParameterSource ();
224
222
params .addValue (ID , id , Types .INTEGER );
225
- SimpleJdbcTemplate template = new SimpleJdbcTemplate (
226
- getNamedParameterJdbcTemplate ());
227
- return template .queryForInt (SELECT_CONTENT_SIZE , params );
223
+ NamedParameterJdbcTemplate template = getNamedParameterJdbcTemplate ();
224
+ return template .queryForObject (SELECT_CONTENT_SIZE , params , Integer .class );
228
225
} catch (EmptyResultDataAccessException erdae ) {
229
226
return -1 ;
230
227
}
@@ -239,10 +236,8 @@ public Conversation getConversation(int id) throws DataAccessException {
239
236
try {
240
237
MapSqlParameterSource params = new MapSqlParameterSource ();
241
238
params .addValue (ID , id , Types .INTEGER );
242
- SimpleJdbcTemplate template = new SimpleJdbcTemplate (
243
- getNamedParameterJdbcTemplate ());
244
- return template .queryForObject (SELECT_SUMMARY , CONVERSATION_MAPPER ,
245
- params );
239
+ NamedParameterJdbcTemplate template = getNamedParameterJdbcTemplate ();
240
+ return template .queryForObject (SELECT_SUMMARY , params , CONVERSATION_MAPPER );
246
241
} catch (EmptyResultDataAccessException erdae ) {
247
242
return null ;
248
243
}
@@ -286,10 +281,8 @@ public byte[] loadMessageContent(int id) throws DataAccessException {
286
281
try {
287
282
MapSqlParameterSource params = new MapSqlParameterSource ();
288
283
params .addValue (ID , id , Types .INTEGER );
289
- SimpleJdbcTemplate template = new SimpleJdbcTemplate (
290
- getNamedParameterJdbcTemplate ());
291
- return template .queryForObject (SELECT_CONTENT , CONTENT_MAPPER ,
292
- params );
284
+ NamedParameterJdbcTemplate template = getNamedParameterJdbcTemplate ();
285
+ return template .queryForObject (SELECT_CONTENT , params , CONTENT_MAPPER );
293
286
} catch (EmptyResultDataAccessException erdae ) {
294
287
return null ;
295
288
}
@@ -319,10 +312,8 @@ public RequestHeader loadRequestHeader(int id) throws DataAccessException {
319
312
MapSqlParameterSource params = new MapSqlParameterSource ();
320
313
try {
321
314
params .addValue (ID , id , Types .INTEGER );
322
- SimpleJdbcTemplate template = new SimpleJdbcTemplate (
323
- getNamedParameterJdbcTemplate ());
324
- return template .queryForObject (SELECT_REQUEST , REQUEST_MAPPER ,
325
- params );
315
+ NamedParameterJdbcTemplate template = getNamedParameterJdbcTemplate ();
316
+ return template .queryForObject (SELECT_REQUEST , params , REQUEST_MAPPER );
326
317
} catch (EmptyResultDataAccessException erdae ) {
327
318
return null ;
328
319
}
@@ -354,10 +345,8 @@ public MutableResponseHeader loadResponseHeader(int id)
354
345
try {
355
346
MapSqlParameterSource params = new MapSqlParameterSource ();
356
347
params .addValue (ID , id , Types .INTEGER );
357
- SimpleJdbcTemplate template = new SimpleJdbcTemplate (
358
- getNamedParameterJdbcTemplate ());
359
- return template .queryForObject (SELECT_RESPONSE , RESPONSE_MAPPER ,
360
- params );
348
+ NamedParameterJdbcTemplate template = getNamedParameterJdbcTemplate ();
349
+ return template .queryForObject (SELECT_RESPONSE , params , RESPONSE_MAPPER );
361
350
} catch (EmptyResultDataAccessException erdae ) {
362
351
return null ;
363
352
}
@@ -478,7 +467,7 @@ private void saveMessageHeader(MutableMessageHeader header, int contentId) {
478
467
}
479
468
480
469
private static class RequestMapper implements
481
- ParameterizedRowMapper <MutableBufferedRequest > {
470
+ RowMapper <MutableBufferedRequest > {
482
471
483
472
public MutableBufferedRequest mapRow (ResultSet rs , int rowNum )
484
473
throws SQLException {
@@ -504,7 +493,7 @@ public MutableBufferedRequest mapRow(ResultSet rs, int rowNum)
504
493
}
505
494
506
495
private static class ResponseMapper implements
507
- ParameterizedRowMapper <MutableBufferedResponse > {
496
+ RowMapper <MutableBufferedResponse > {
508
497
509
498
public MutableBufferedResponse mapRow (ResultSet rs , int rowNum )
510
499
throws SQLException {
@@ -529,22 +518,22 @@ public MutableBufferedResponse mapRow(ResultSet rs, int rowNum)
529
518
}
530
519
531
520
private static class ContentMapper implements
532
- ParameterizedRowMapper <byte []> {
521
+ RowMapper <byte []> {
533
522
534
523
public byte [] mapRow (ResultSet rs , int rowNum ) throws SQLException {
535
524
return rs .getBytes (CONTENT );
536
525
}
537
526
}
538
527
539
- private static class IdMapper implements ParameterizedRowMapper <Integer > {
528
+ private static class IdMapper implements RowMapper <Integer > {
540
529
541
530
public Integer mapRow (ResultSet rs , int rowNum ) throws SQLException {
542
531
return Integer .valueOf (rs .getInt (ID ));
543
532
}
544
533
}
545
534
546
535
private static class ConversationMapper implements
547
- ParameterizedRowMapper <Conversation > {
536
+ RowMapper <Conversation > {
548
537
549
538
public Conversation mapRow (ResultSet rs , int rowNum )
550
539
throws SQLException {
0 commit comments