KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > JdbcUpdateAffectedIncorrectNumberOfRowsException


1 /*
2  * Copyright 2002-2006 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
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 IncorrectUpdateSemanticsDataAccessException {
30
31     /** Number of rows that should have been affected */
32     private int expected;
33
34     /** Number of rows that actually were affected */
35     private int actual;
36
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 JavaDoc sql, int expected, int actual) {
45         super("SQL update '" + sql + "' affected " + actual + " rows, not " + expected + " as expected");
46         this.expected = expected;
47         this.actual = actual;
48     }
49
50
51     /**
52      * Return the number of rows that should have been affected.
53      */

54     public int getExpectedRowsAffected() {
55         return this.expected;
56     }
57
58     /**
59      * Return the number of rows that have actually been affected.
60      */

61     public int getActualRowsAffected() {
62         return this.actual;
63     }
64
65     public boolean wasDataUpdated() {
66         return (getActualRowsAffected() > 0);
67     }
68
69 }
70
Popular Tags