001: /*
002: * Copyright 2003 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: PostgreSQLSQLState.java,v 1.1 2003/10/18 19:54:01 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.store;
012:
013: import java.util.Arrays;
014:
015: /**
016: * A SQLSTATE diagnostic code for PostgreSQL.
017: *
018: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
019: * @version $Revision: 1.1 $
020: *
021: * @see DatabaseAdapter
022: */
023:
024: public class PostgreSQLSQLState extends SQLState {
025: /**
026: * Constructs a SQLState object from the specified SQLSTATE string.
027: *
028: * @param s
029: * A 5-character SQLSTATE string.
030: *
031: * @exception IllegalArgumentException
032: * if <var>s</var> is not a valid 5-character SQLSTATE string.
033: */
034:
035: public PostgreSQLSQLState(String s) throws IllegalArgumentException {
036: super (s);
037: }
038:
039: public boolean isWorthRetrying() {
040: if (Arrays.binarySearch(ClassCode.NOT_RETRYABLE, classCode()) >= 0)
041: return false;
042: else
043: return true;
044: }
045:
046: /**
047: * Contains constants for known SQLSTATE class codes.
048: * This list comes from pgsql/src/include/utils/errcodes.h
049: */
050:
051: public static class ClassCode {
052: /** Private constructor prevents instantiation. */
053: private ClassCode() {
054: }
055:
056: public static final String SUCCESSFUL_COMPLETION = "00",
057: WARNING = "01", NO_DATA = "02",
058: SQL_STATEMENT_NOT_YET_COMPLETE = "03",
059: CONNECTION_EXCEPTION = "08",
060: TRIGGERED_ACTION_EXCEPTION = "09",
061: FEATURE_NOT_SUPPORTED = "0A",
062: INVALID_TRANSACTION_INITIATION = "0B",
063: LOCATOR_EXCEPTION = "0F", INVALID_GRANTOR = "0L",
064: INVALID_ROLE_SPECIFICATION = "0P",
065: CARDINALITY_VIOLATION = "21", DATA_EXCEPTION = "22",
066: INTEGRITY_CONSTRAINT_VIOLATION = "23",
067: INVALID_CURSOR_STATE = "24",
068: INVALID_TRANSACTION_STATE = "25",
069: INVALID_SQL_STATEMENT_NAME = "26",
070: TRIGGERED_DATA_CHANGE_VIOLATION = "27",
071: INVALID_AUTHORIZATION_SPECIFICATION = "28",
072: DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST = "2B",
073: INVALID_TRANSACTION_TERMINATION = "2D",
074: SQL_ROUTINE_EXCEPTION = "2F",
075: INVALID_CURSOR_NAME = "34",
076: EXTERNAL_ROUTINE_EXCEPTION = "38",
077: EXTERNAL_ROUTINE_INVOCATION_EXCEPTION = "39",
078: INVALID_CATALOG_NAME = "3D",
079: INVALID_SCHEMA_NAME = "3F",
080: TRANSACTION_ROLLBACK = "40",
081: SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION = "42",
082: WITH_CHECK_OPTION_VIOLATION = "44",
083: INSUFFICIENT_RESOURCES = "53",
084: PROGRAM_LIMIT_EXCEEDED = "54",
085: OBJECT_NOT_IN_PREREQUISITE_STATE = "55",
086: OPERATOR_INTERVENTION = "57", SYSTEM_ERROR = "58",
087: CONFIG_FILE_ERROR = "F0", INTERNAL_ERROR = "XX";
088:
089: /**
090: * An array representing all those class codes that are known
091: * <em>not</em> to be worth retrying.
092: * The array is sorted for efficient searching.
093: */
094: public static final String[] NOT_RETRYABLE = {
095: /* Take care to keep this list sorted by value. */
096: SUCCESSFUL_COMPLETION,
097: WARNING,
098: NO_DATA,
099: SQL_STATEMENT_NOT_YET_COMPLETE,
100: //CONNECTION_EXCEPTION,
101: TRIGGERED_ACTION_EXCEPTION,
102: FEATURE_NOT_SUPPORTED,
103: INVALID_TRANSACTION_INITIATION,
104: LOCATOR_EXCEPTION,
105: INVALID_GRANTOR,
106: INVALID_ROLE_SPECIFICATION,
107: CARDINALITY_VIOLATION,
108: DATA_EXCEPTION,
109: INTEGRITY_CONSTRAINT_VIOLATION,
110: //INVALID_CURSOR_STATE,
111: //INVALID_TRANSACTION_STATE,
112: INVALID_SQL_STATEMENT_NAME,
113: TRIGGERED_DATA_CHANGE_VIOLATION,
114: INVALID_AUTHORIZATION_SPECIFICATION,
115: DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST,
116: //INVALID_TRANSACTION_TERMINATION,
117: SQL_ROUTINE_EXCEPTION, INVALID_CURSOR_NAME,
118: EXTERNAL_ROUTINE_EXCEPTION,
119: EXTERNAL_ROUTINE_INVOCATION_EXCEPTION,
120: INVALID_CATALOG_NAME, INVALID_SCHEMA_NAME,
121: //TRANSACTION_ROLLBACK,
122: SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION,
123: WITH_CHECK_OPTION_VIOLATION,
124: //INSUFFICIENT_RESOURCES,
125: PROGRAM_LIMIT_EXCEEDED,
126: //OBJECT_NOT_IN_PREREQUISITE_STATE,
127: //OPERATOR_INTERVENTION,
128: //SYSTEM_ERROR,
129: CONFIG_FILE_ERROR, INTERNAL_ERROR };
130: }
131: }
|