001: /*
002: * SqlStatementResult.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.executequery.databasemediators;
023:
024: import java.sql.ResultSet;
025: import java.sql.SQLException;
026: import java.sql.SQLWarning;
027: import org.executequery.Constants;
028:
029: /* ----------------------------------------------------------
030: * CVS NOTE: Changes to the CVS repository prior to the
031: * release of version 3.0.0beta1 has meant a
032: * resetting of CVS revision numbers.
033: * ----------------------------------------------------------
034: */
035:
036: /**
037: *
038: * @author Takis Diakoumis
039: * @version $Revision: 1.4 $
040: * @date $Date: 2006/05/14 06:56:54 $
041: */
042: public class SqlStatementResult {
043:
044: private int type;
045:
046: private int updateCount;
047:
048: private String message;
049:
050: private String otherErrorMessage;
051:
052: private ResultSet resultSet;
053:
054: private SQLException sqlException;
055:
056: private SQLWarning sqlWarning;
057:
058: private Object otherResult;
059:
060: /** Creates a new instance of SqlStatementResult */
061: public SqlStatementResult() {
062: }
063:
064: public SqlStatementResult(ResultSet resultSet,
065: SQLException sqlException, SQLWarning sqlWarning) {
066: this .resultSet = resultSet;
067: this .sqlException = sqlException;
068: this .sqlWarning = sqlWarning;
069: }
070:
071: public void reset(ResultSet resultSet, SQLException sqlException,
072: SQLWarning sqlWarning) {
073: updateCount = -1;
074: this .resultSet = resultSet;
075: this .sqlException = sqlException;
076: this .sqlWarning = sqlWarning;
077: }
078:
079: public void reset() {
080: updateCount = -1;
081: message = Constants.EMPTY;
082: resultSet = null;
083: sqlException = null;
084: sqlWarning = null;
085: otherResult = null;
086: otherErrorMessage = null;
087: }
088:
089: public ResultSet getResultSet() {
090: return resultSet;
091: }
092:
093: public String getErrorMessage() {
094:
095: if (sqlException == null && otherErrorMessage == null) {
096: return message;
097: } else if (otherErrorMessage != null) {
098: return otherErrorMessage;
099: }
100:
101: String text = sqlException.getMessage();
102: if (text != null) {
103:
104: int errorCode = 0;
105: StringBuffer message = new StringBuffer();
106: SQLException sqlExc = sqlException;
107: while (true) {
108: if (sqlExc == null) {
109: break;
110: }
111: String _message = sqlExc.getMessage();
112: message.append(_message);
113: if (!_message.endsWith("\n")) {
114: message.append("\n");
115: }
116:
117: errorCode = sqlException.getErrorCode();
118: if (errorCode > 0) {
119: message.append("[Error Code: ").append(errorCode)
120: .append("]\n");
121: }
122:
123: text = sqlException.getSQLState();
124: if (text != null) {
125: message.append("[SQL State: ").append(text).append(
126: "]\n");
127: }
128:
129: sqlExc = sqlExc.getNextException();
130: }
131: return message.toString();
132: } else {
133: return "An indeterminate error has occurred";
134: }
135:
136: }
137:
138: public boolean isResultSet() {
139: return resultSet != null;
140: }
141:
142: public void setResultSet(ResultSet resultSet) {
143: this .resultSet = resultSet;
144: }
145:
146: public SQLException getSqlException() {
147: return sqlException;
148: }
149:
150: public void setSqlException(SQLException sqlException) {
151: this .sqlException = sqlException;
152: }
153:
154: public SQLWarning getSqlWarning() {
155: return sqlWarning;
156: }
157:
158: public void setSqlWarning(SQLWarning sqlWarning) {
159: this .sqlWarning = sqlWarning;
160: }
161:
162: public int getUpdateCount() {
163: return updateCount;
164: }
165:
166: public void setUpdateCount(int updateCount) {
167: this .updateCount = updateCount;
168: }
169:
170: public String getMessage() {
171: return message;
172: }
173:
174: public void setMessage(String message) {
175: this .message = message;
176: }
177:
178: public int getType() {
179: return type;
180: }
181:
182: public void setType(int type) {
183: this .type = type;
184: }
185:
186: public Object getOtherResult() {
187: return otherResult;
188: }
189:
190: public void setOtherResult(Object otherResult) {
191: this .otherResult = otherResult;
192: }
193:
194: public String getOtherErrorMessage() {
195: return otherErrorMessage;
196: }
197:
198: public void setOtherErrorMessage(String otherErrorMessage) {
199: this.otherErrorMessage = otherErrorMessage;
200: }
201:
202: }
|