001: /*
002: Derby - Class org.apache.derby.common.error.ExceptionUtil
003:
004: Licensed to the Apache Software Foundation (ASF) under one or more
005: contributor license agreements. See the NOTICE file distributed with
006: this work for additional information regarding copyright ownership.
007: The ASF licenses this file to you under the Apache License, Version 2.0
008: (the "License"); you may not use this file except in compliance with
009: the License. You may obtain a copy of the License at
010:
011: http://www.apache.org/licenses/LICENSE-2.0
012:
013: Unless required by applicable law or agreed to in writing, software
014: distributed under the License is distributed on an "AS IS" BASIS,
015: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: See the License for the specific language governing permissions and
017: limitations under the License.
018:
019: */
020: package org.apache.derby.shared.common.error;
021:
022: import org.apache.derby.shared.common.error.ExceptionSeverity;
023:
024: /**
025: * This class provides utility routines for exceptions
026: */
027: public class ExceptionUtil {
028: /**
029: * Convert a message identifer from
030: * org.apache.derby.shared.common.reference.SQLState to
031: * a SQLState five character string.
032: *
033: * @param messageID - the sql state id of the message from cloudscape
034: * @return String - the 5 character code of the SQLState ID to returned to the user
035: */
036: public static String getSQLStateFromIdentifier(String messageID) {
037:
038: if (messageID.length() == 5)
039: return messageID;
040: return messageID.substring(0, 5);
041: }
042:
043: /**
044: * Get the severity given a message identifier from SQLState.
045: */
046: public static int getSeverityFromIdentifier(String messageID) {
047:
048: int lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;
049:
050: switch (messageID.length()) {
051: case 5:
052: switch (messageID.charAt(0)) {
053: case '0':
054: switch (messageID.charAt(1)) {
055: case '1':
056: lseverity = ExceptionSeverity.WARNING_SEVERITY;
057: break;
058: case 'A':
059: case '7':
060: lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
061: break;
062: case '8':
063: lseverity = ExceptionSeverity.SESSION_SEVERITY;
064: break;
065: }
066: break;
067: case '2':
068: case '3':
069: lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
070: break;
071: case '4':
072: switch (messageID.charAt(1)) {
073: case '0':
074: lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;
075: break;
076: case '2':
077: lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
078: break;
079: }
080: break;
081: }
082: break;
083:
084: default:
085: switch (messageID.charAt(6)) {
086: case 'M':
087: lseverity = ExceptionSeverity.SYSTEM_SEVERITY;
088: break;
089: case 'D':
090: lseverity = ExceptionSeverity.DATABASE_SEVERITY;
091: break;
092: case 'C':
093: lseverity = ExceptionSeverity.SESSION_SEVERITY;
094: break;
095: case 'T':
096: lseverity = ExceptionSeverity.TRANSACTION_SEVERITY;
097: break;
098: case 'S':
099: lseverity = ExceptionSeverity.STATEMENT_SEVERITY;
100: break;
101: case 'U':
102: lseverity = ExceptionSeverity.NO_APPLICABLE_SEVERITY;
103: break;
104: }
105: break;
106: }
107:
108: return lseverity;
109: }
110:
111: }
|