|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2008 the original author or authors. |
| 2 | + * Copyright 2002-2010 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -380,6 +380,21 @@ <T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse
|
380 | 380 | */
|
381 | 381 | <T> T query(String sql, Object[] args, ResultSetExtractor<T> rse) throws DataAccessException;
|
382 | 382 |
|
| 383 | + /** |
| 384 | + * Query given SQL to create a prepared statement from SQL and a list |
| 385 | + * of arguments to bind to the query, reading the ResultSet with a |
| 386 | + * ResultSetExtractor. |
| 387 | + * @param sql SQL query to execute |
| 388 | + * @param rse object that will extract results |
| 389 | + * @param args arguments to bind to the query |
| 390 | + * (leaving it to the PreparedStatement to guess the corresponding SQL type); |
| 391 | + * may also contain {@link SqlParameterValue} objects which indicate not |
| 392 | + * only the argument value but also the SQL type and optionally the scale |
| 393 | + * @return an arbitrary result object, as returned by the ResultSetExtractor |
| 394 | + * @throws DataAccessException if the query fails |
| 395 | + */ |
| 396 | + <T> T query(String sql, ResultSetExtractor<T> rse, Object... args) throws DataAccessException; |
| 397 | + |
383 | 398 | /**
|
384 | 399 | * Query using a prepared statement, reading the ResultSet on a per-row
|
385 | 400 | * basis with a RowCallbackHandler.
|
@@ -437,6 +452,20 @@ void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch)
|
437 | 452 | */
|
438 | 453 | void query(String sql, Object[] args, RowCallbackHandler rch) throws DataAccessException;
|
439 | 454 |
|
| 455 | + /** |
| 456 | + * Query given SQL to create a prepared statement from SQL and a list of |
| 457 | + * arguments to bind to the query, reading the ResultSet on a per-row basis |
| 458 | + * with a RowCallbackHandler. |
| 459 | + * @param sql SQL query to execute |
| 460 | + * @param rch object that will extract results, one row at a time |
| 461 | + * @param args arguments to bind to the query |
| 462 | + * (leaving it to the PreparedStatement to guess the corresponding SQL type); |
| 463 | + * may also contain {@link SqlParameterValue} objects which indicate not |
| 464 | + * only the argument value but also the SQL type and optionally the scale |
| 465 | + * @throws DataAccessException if the query fails |
| 466 | + */ |
| 467 | + void query(String sql, RowCallbackHandler rch, Object... args) throws DataAccessException; |
| 468 | + |
440 | 469 | /**
|
441 | 470 | * Query using a prepared statement, mapping each row to a Java object
|
442 | 471 | * via a RowMapper.
|
@@ -497,6 +526,21 @@ <T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMap
|
497 | 526 | */
|
498 | 527 | <T> List<T> query(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException;
|
499 | 528 |
|
| 529 | + /** |
| 530 | + * Query given SQL to create a prepared statement from SQL and a list |
| 531 | + * of arguments to bind to the query, mapping each row to a Java object |
| 532 | + * via a RowMapper. |
| 533 | + * @param sql SQL query to execute |
| 534 | + * @param rowMapper object that will map one object per row |
| 535 | + * @param args arguments to bind to the query |
| 536 | + * (leaving it to the PreparedStatement to guess the corresponding SQL type); |
| 537 | + * may also contain {@link SqlParameterValue} objects which indicate not |
| 538 | + * only the argument value but also the SQL type and optionally the scale |
| 539 | + * @return the result List, containing mapped objects |
| 540 | + * @throws DataAccessException if the query fails |
| 541 | + */ |
| 542 | + <T> List<T> query(String sql, RowMapper<T> rowMapper, Object... args) throws DataAccessException; |
| 543 | + |
500 | 544 | /**
|
501 | 545 | * Query given SQL to create a prepared statement from SQL and a list
|
502 | 546 | * of arguments to bind to the query, mapping a single result row to a
|
@@ -533,6 +577,24 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> row
|
533 | 577 | <T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper)
|
534 | 578 | throws DataAccessException;
|
535 | 579 |
|
| 580 | + /** |
| 581 | + * Query given SQL to create a prepared statement from SQL and a list |
| 582 | + * of arguments to bind to the query, mapping a single result row to a |
| 583 | + * Java object via a RowMapper. |
| 584 | + * @param sql SQL query to execute |
| 585 | + * @param rowMapper object that will map one object per row |
| 586 | + * @param args arguments to bind to the query |
| 587 | + * (leaving it to the PreparedStatement to guess the corresponding SQL type); |
| 588 | + * may also contain {@link SqlParameterValue} objects which indicate not |
| 589 | + * only the argument value but also the SQL type and optionally the scale |
| 590 | + * @return the single mapped object |
| 591 | + * @throws IncorrectResultSizeDataAccessException if the query does not |
| 592 | + * return exactly one row |
| 593 | + * @throws DataAccessException if the query fails |
| 594 | + */ |
| 595 | + <T> T queryForObject(String sql, RowMapper<T> rowMapper, Object... args) |
| 596 | + throws DataAccessException; |
| 597 | + |
536 | 598 | /**
|
537 | 599 | * Query given SQL to create a prepared statement from SQL and a
|
538 | 600 | * list of arguments to bind to the query, expecting a result object.
|
@@ -572,6 +634,25 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> require
|
572 | 634 | */
|
573 | 635 | <T> T queryForObject(String sql, Object[] args, Class<T> requiredType) throws DataAccessException;
|
574 | 636 |
|
| 637 | + /** |
| 638 | + * Query given SQL to create a prepared statement from SQL and a |
| 639 | + * list of arguments to bind to the query, expecting a result object. |
| 640 | + * <p>The query is expected to be a single row/single column query; the returned |
| 641 | + * result will be directly mapped to the corresponding object type. |
| 642 | + * @param sql SQL query to execute |
| 643 | + * @param requiredType the type that the result object is expected to match |
| 644 | + * @param args arguments to bind to the query |
| 645 | + * (leaving it to the PreparedStatement to guess the corresponding SQL type); |
| 646 | + * may also contain {@link SqlParameterValue} objects which indicate not |
| 647 | + * only the argument value but also the SQL type and optionally the scale |
| 648 | + * @return the result object of the required type, or <code>null</code> in case of SQL NULL |
| 649 | + * @throws IncorrectResultSizeDataAccessException if the query does not return |
| 650 | + * exactly one row, or does not return exactly one column in that row |
| 651 | + * @throws DataAccessException if the query fails |
| 652 | + * @see #queryForObject(String, Class) |
| 653 | + */ |
| 654 | + <T> T queryForObject(String sql, Class<T> requiredType, Object... args) throws DataAccessException; |
| 655 | + |
575 | 656 | /**
|
576 | 657 | * Query given SQL to create a prepared statement from SQL and a
|
577 | 658 | * list of arguments to bind to the query, expecting a result Map.
|
@@ -725,6 +806,25 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
|
725 | 806 | */
|
726 | 807 | <T> List<T> queryForList(String sql, Object[] args, Class<T> elementType) throws DataAccessException;
|
727 | 808 |
|
| 809 | + /** |
| 810 | + * Query given SQL to create a prepared statement from SQL and a |
| 811 | + * list of arguments to bind to the query, expecting a result list. |
| 812 | + * <p>The results will be mapped to a List (one entry for each row) of |
| 813 | + * result objects, each of them matching the specified element type. |
| 814 | + * @param sql SQL query to execute |
| 815 | + * @param elementType the required type of element in the result list |
| 816 | + * (for example, <code>Integer.class</code>) |
| 817 | + * @param args arguments to bind to the query |
| 818 | + * (leaving it to the PreparedStatement to guess the corresponding SQL type); |
| 819 | + * may also contain {@link SqlParameterValue} objects which indicate not |
| 820 | + * only the argument value but also the SQL type and optionally the scale |
| 821 | + * @return a List of objects that match the specified element type |
| 822 | + * @throws DataAccessException if the query fails |
| 823 | + * @see #queryForList(String, Class) |
| 824 | + * @see SingleColumnRowMapper |
| 825 | + */ |
| 826 | + <T> List<T> queryForList(String sql, Class<T> elementType, Object... args) throws DataAccessException; |
| 827 | + |
728 | 828 | /**
|
729 | 829 | * Query given SQL to create a prepared statement from SQL and a
|
730 | 830 | * list of arguments to bind to the query, expecting a result list.
|
|
0 commit comments