001: /*
002:
003: Derby - Class org.apache.derby.impl.load.LoadError
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.load;
023:
024: import java.sql.SQLException;
025: import org.apache.derby.iapi.error.ExceptionSeverity;
026: import org.apache.derby.iapi.reference.SQLState;
027: import org.apache.derby.iapi.error.StandardException;
028: import org.apache.derby.iapi.error.PublicAPI;
029:
030: /**
031: * These exceptions are thrown by the import and export modules.
032: *
033: *
034: * @author Mamta Satoor
035: @see SQLException
036: */
037: class LoadError {
038:
039: /**
040: Raised if, the Cloudscape database connection is null.
041: */
042:
043: static SQLException connectionNull() {
044: return PublicAPI.wrapStandardException(StandardException
045: .newException(SQLState.CONNECTION_NULL));
046: }
047:
048: /**
049: Raised if, there is data found between the stop delimiter and field/record spearator.
050: @param lineNumber Found invalid data on this line number in the data file
051: @param columnNumber Found invalid data for this column number in the data file
052: */
053: static SQLException dataAfterStopDelimiter(int lineNumber,
054: int columnNumber) {
055: return PublicAPI.wrapStandardException(StandardException
056: .newException(SQLState.DATA_AFTER_STOP_DELIMITER,
057: new Integer(lineNumber), new Integer(
058: columnNumber)));
059: }
060:
061: /**
062: Raised if, the passed data file can't be found.
063: @param fileName the data file name
064: */
065: static SQLException dataFileNotFound(String fileName) {
066:
067: return PublicAPI.wrapStandardException(StandardException
068: .newException(SQLState.DATA_FILE_NOT_FOUND, fileName));
069: }
070:
071: /**
072: Raised if, null is passed for data file url.
073: */
074: static SQLException dataFileNull() {
075: return PublicAPI.wrapStandardException(StandardException
076: .newException(SQLState.DATA_FILE_NULL));
077: }
078:
079: /**
080: Raised if, the entity (ie table/view) for import/export is missing in the database.
081: */
082:
083: static SQLException entityNameMissing() {
084: return PublicAPI.wrapStandardException(StandardException
085: .newException(SQLState.ENTITY_NAME_MISSING));
086:
087: }
088:
089: /**
090: Raised if, field & record separators are substring of each other.
091: */
092: static SQLException fieldAndRecordSeparatorsSubset() {
093: return PublicAPI
094: .wrapStandardException(StandardException
095: .newException(SQLState.FIELD_IS_RECORD_SEPERATOR_SUBSET));
096: }
097:
098: /**
099: Raised if, no column by given name is found in the resultset while importing.
100: @param columnName the resultset doesn't have this column name
101: */
102: static SQLException invalidColumnName(String columnName) {
103: return PublicAPI
104: .wrapStandardException(StandardException.newException(
105: SQLState.INVALID_COLUMN_NAME, columnName));
106:
107: }
108:
109: /**
110: Raised if, no column by given number is found in the resultset while importing.
111: @param numberOfColumns the resultset doesn't have this column number
112: */
113: static SQLException invalidColumnNumber(int numberOfColumns) {
114:
115: return PublicAPI.wrapStandardException(StandardException
116: .newException(SQLState.INVALID_COLUMN_NUMBER,
117: new Integer(numberOfColumns)));
118: }
119:
120: /**
121: Raised if, trying to export/import from an entity which has non supported
122: type columns in it.
123: */
124: static SQLException nonSupportedTypeColumn(String columnName,
125: String typeName) {
126: return PublicAPI.wrapStandardException(StandardException
127: .newException(SQLState.UNSUPPORTED_COLUMN_TYPE,
128: columnName, typeName));
129: }
130:
131: /**
132: Raised if, in case of fixed format, don't find the record separator for a row in the data file.
133: @param lineNumber the line number with the missing record separator in the data file
134: */
135: static SQLException recordSeparatorMissing(int lineNumber) {
136:
137: return PublicAPI.wrapStandardException(StandardException
138: .newException(SQLState.RECORD_SEPERATOR_MISSING,
139: new Integer(lineNumber)));
140: }
141:
142: /**
143: Raised if, in case of fixed format, reach end of file before reading data for all the columns.
144: */
145: static SQLException unexpectedEndOfFile(int lineNumber) {
146: return PublicAPI.wrapStandardException(StandardException
147: .newException(SQLState.UNEXPECTED_END_OF_FILE,
148: new Integer(lineNumber)));
149: }
150:
151: /**
152: Raised if, got IOException while writing data to the file.
153: */
154: static SQLException errorWritingData() {
155: return PublicAPI.wrapStandardException(StandardException
156: .newException(SQLState.ERROR_WRITING_DATA));
157: }
158:
159: /*
160: * Raised if period(.) is used a character delimiter
161: */
162: static SQLException periodAsCharDelimiterNotAllowed() {
163: return PublicAPI
164: .wrapStandardException(StandardException
165: .newException(SQLState.PERIOD_AS_CHAR_DELIMITER_NOT_ALLOWED));
166: }
167:
168: /*
169: * Raised if same delimiter character is used for more than one delimiter
170: * type . For eg using ';' for both column delimter and character delimter
171: */
172: static SQLException delimitersAreNotMutuallyExclusive() {
173: return PublicAPI
174: .wrapStandardException(StandardException
175: .newException(SQLState.DELIMITERS_ARE_NOT_MUTUALLY_EXCLUSIVE));
176: }
177:
178: static SQLException tableNotFound(String tableName) {
179:
180: return PublicAPI.wrapStandardException(StandardException
181: .newException(SQLState.TABLE_NOT_FOUND, tableName));
182: }
183:
184: /* Wrapper to throw an unknown excepton duing Import/Export.
185: * Typically this can be some IO error which is not generic error
186: * like the above error messages.
187: */
188:
189: static SQLException unexpectedError(Throwable t) {
190: if (!(t instanceof SQLException)) {
191: return PublicAPI.wrapStandardException(StandardException
192: .plainWrapException(t));
193: } else
194: return (SQLException) t;
195: }
196:
197: }
|