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.jdbc;
18:
19: import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException;
20:
21: /**
22: * Exception thrown when a JDBC update affects an unexpected number of rows.
23: * Typically we expect an update to affect a single row, meaning it's an
24: * error if it affects multiple rows.
25: *
26: * @author Rod Johnson
27: * @author Juergen Hoeller
28: */
29: public class JdbcUpdateAffectedIncorrectNumberOfRowsException extends
30: IncorrectUpdateSemanticsDataAccessException {
31:
32: /** Number of rows that should have been affected */
33: private int expected;
34:
35: /** Number of rows that actually were affected */
36: private int actual;
37:
38: /**
39: * Constructor for JdbcUpdateAffectedIncorrectNumberOfRowsException.
40: * @param sql SQL we were tring to execute
41: * @param expected the expected number of rows affected
42: * @param actual the actual number of rows affected
43: */
44: public JdbcUpdateAffectedIncorrectNumberOfRowsException(String sql,
45: int expected, int actual) {
46: super ("SQL update '" + sql + "' affected " + actual
47: + " rows, not " + expected + " as expected");
48: this .expected = expected;
49: this .actual = actual;
50: }
51:
52: /**
53: * Return the number of rows that should have been affected.
54: */
55: public int getExpectedRowsAffected() {
56: return this .expected;
57: }
58:
59: /**
60: * Return the number of rows that have actually been affected.
61: */
62: public int getActualRowsAffected() {
63: return this .actual;
64: }
65:
66: public boolean wasDataUpdated() {
67: return (getActualRowsAffected() > 0);
68: }
69:
70: }
|