1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.dao;
  17. /**
  18. * Data access exception thrown when a result was not of the expected size,
  19. * for example when expecting a single row but getting 0 or more than 1 rows.
  20. * @author Juergen Hoeller
  21. * @since 26.05.2004
  22. */
  23. public class IncorrectResultSizeDataAccessException extends InvalidDataAccessApiUsageException {
  24. private final int expectedSize;
  25. private final int actualSize;
  26. /**
  27. * Constructor for IncorrectResultSizeDataAccessException.
  28. * @param expectedSize the expected result size
  29. * @param actualSize the actual result size (or -1 if unknown)
  30. */
  31. public IncorrectResultSizeDataAccessException(int expectedSize, int actualSize) {
  32. super("Incorrect result size: expected " + expectedSize + ", actual " + actualSize);
  33. this.expectedSize = expectedSize;
  34. this.actualSize = actualSize;
  35. }
  36. /**
  37. * Constructor for IncorrectResultSizeDataAccessException.
  38. * @param msg message
  39. * @param expectedSize the expected result size
  40. * @param actualSize the actual result size (or -1 if unknown)
  41. */
  42. public IncorrectResultSizeDataAccessException(String msg, int expectedSize, int actualSize) {
  43. super(msg);
  44. this.expectedSize = expectedSize;
  45. this.actualSize = actualSize;
  46. }
  47. /**
  48. * Return the expected result size.
  49. */
  50. public int getExpectedSize() {
  51. return expectedSize;
  52. }
  53. /**
  54. * Return the actual result size (or -1 if unknown).
  55. */
  56. public int getActualSize() {
  57. return actualSize;
  58. }
  59. }