01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.springframework.dao;
18:
19: /**
20: * Data access exception thrown when a result was not of the expected size,
21: * for example when expecting a single row but getting 0 or more than 1 rows.
22: *
23: * @author Juergen Hoeller
24: * @since 1.0.2
25: * @see EmptyResultDataAccessException
26: */
27: public class IncorrectResultSizeDataAccessException extends
28: DataRetrievalFailureException {
29:
30: private int expectedSize;
31:
32: private int actualSize;
33:
34: /**
35: * Constructor for IncorrectResultSizeDataAccessException.
36: * @param expectedSize the expected result size
37: */
38: public IncorrectResultSizeDataAccessException(int expectedSize) {
39: super ("Incorrect result size: expected " + expectedSize);
40: this .expectedSize = expectedSize;
41: this .actualSize = -1;
42: }
43:
44: /**
45: * Constructor for IncorrectResultSizeDataAccessException.
46: * @param expectedSize the expected result size
47: * @param actualSize the actual result size (or -1 if unknown)
48: */
49: public IncorrectResultSizeDataAccessException(int expectedSize,
50: int actualSize) {
51: super ("Incorrect result size: expected " + expectedSize
52: + ", actual " + actualSize);
53: this .expectedSize = expectedSize;
54: this .actualSize = actualSize;
55: }
56:
57: /**
58: * Constructor for IncorrectResultSizeDataAccessException.
59: * @param msg the detail message
60: * @param expectedSize the expected result size
61: */
62: public IncorrectResultSizeDataAccessException(String msg,
63: int expectedSize) {
64: super (msg);
65: this .expectedSize = expectedSize;
66: this .actualSize = -1;
67: }
68:
69: /**
70: * Constructor for IncorrectResultSizeDataAccessException.
71: * @param msg the detail message
72: * @param expectedSize the expected result size
73: * @param actualSize the actual result size (or -1 if unknown)
74: */
75: public IncorrectResultSizeDataAccessException(String msg,
76: int expectedSize, int actualSize) {
77: super (msg);
78: this .expectedSize = expectedSize;
79: this .actualSize = actualSize;
80: }
81:
82: /**
83: * Return the expected result size.
84: */
85: public int getExpectedSize() {
86: return expectedSize;
87: }
88:
89: /**
90: * Return the actual result size (or -1 if unknown).
91: */
92: public int getActualSize() {
93: return actualSize;
94: }
95:
96: }
|