001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jdbc;
018
019import org.springframework.dao.DataRetrievalFailureException;
020
021/**
022 * Data access exception thrown when a result set did not have the correct column count,
023 * for example when expecting a single column but getting 0 or more than 1 columns.
024 *
025 * @author Juergen Hoeller
026 * @since 2.0
027 * @see org.springframework.dao.IncorrectResultSizeDataAccessException
028 */
029@SuppressWarnings("serial")
030public class IncorrectResultSetColumnCountException extends DataRetrievalFailureException {
031
032        private int expectedCount;
033
034        private int actualCount;
035
036
037        /**
038         * Constructor for IncorrectResultSetColumnCountException.
039         * @param expectedCount the expected column count
040         * @param actualCount the actual column count
041         */
042        public IncorrectResultSetColumnCountException(int expectedCount, int actualCount) {
043                super("Incorrect column count: expected " + expectedCount + ", actual " + actualCount);
044                this.expectedCount = expectedCount;
045                this.actualCount = actualCount;
046        }
047
048        /**
049         * Constructor for IncorrectResultCountDataAccessException.
050         * @param msg the detail message
051         * @param expectedCount the expected column count
052         * @param actualCount the actual column count
053         */
054        public IncorrectResultSetColumnCountException(String msg, int expectedCount, int actualCount) {
055                super(msg);
056                this.expectedCount = expectedCount;
057                this.actualCount = actualCount;
058        }
059
060
061        /**
062         * Return the expected column count.
063         */
064        public int getExpectedCount() {
065                return this.expectedCount;
066        }
067
068        /**
069         * Return the actual column count.
070         */
071        public int getActualCount() {
072                return this.actualCount;
073        }
074
075}