1 10 11 package com.triactive.jdo.store; 12 13 import java.util.Arrays ; 14 15 16 51 52 public class SQLState 53 { 54 private static final int LENGTH = 5; 55 56 private final String value; 57 58 59 68 69 public SQLState(String s) throws IllegalArgumentException 70 { 71 if (s.length() != LENGTH) 72 throw new IllegalArgumentException (s); 73 74 s = s.toUpperCase(); 75 76 for (int i = 0; i < LENGTH; ++i) 77 { 78 if (!isValidChar(s.charAt(i))) 79 throw new IllegalArgumentException (s); 80 } 81 82 value = s; 83 } 84 85 86 private static boolean isValidChar(char c) 87 { 88 return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'); 89 } 90 91 92 private static boolean isStandardChar(char c) 93 { 94 return (c >= '0' && c <= '4') || (c >= 'A' && c <= 'H'); 95 } 96 97 98 102 103 public final String classCode() 104 { 105 return value.substring(0, 2); 106 } 107 108 109 113 114 public final String subclassCode() 115 { 116 return value.substring(2, 5); 117 } 118 119 120 128 129 public final boolean isStandard() 130 { 131 return isStandardChar(value.charAt(0)) && isStandardChar(value.charAt(2)); 132 } 133 134 135 149 150 public boolean isWorthRetrying() 151 { 152 if (Arrays.binarySearch(ClassCode.NOT_RETRYABLE, classCode()) >= 0) 153 return false; 154 else 155 return true; 156 } 157 158 159 164 165 public static class ClassCode 166 { 167 168 private ClassCode() {} 169 170 public static final String 171 SUCCESSFUL_COMPLETION = "00", 172 SUCCESS_WITH_WARNING = "01", 173 NO_DATA = "02", 174 DYNAMIC_SQL_ERROR = "07", 175 CONNECTION_EXCEPTION = "08", 176 FEATURE_NOT_SUPPORTED = "0A", 177 CARDINALITY_VIOLATION = "21", 178 DATA_EXCEPTION = "22", 179 INTEGRITY_CONSTRAINT_VIOLATION = "23", 180 INVALID_CURSOR_STATE = "24", 181 INVALID_TRANSACTION_STATE = "25", 182 INVALID_SQL_STATEMENT_NAME = "26", 183 TRIGGERED_DATA_CHANGE_VIOLATION = "27", 184 INVALID_AUTHORIZATION_SPECIFICATION = "28", 185 SYNTAX_ERROR_OR_ACCESS_VIOLATION_IN_DIRECT_SQL_STATEMENT = "2A", 186 DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST = "2B", 187 INVALID_CHARACTER_SET_NAME = "2C", 188 INVALID_TRANSACTION_TERMINATION = "2D", 189 INVALID_CONNECTION_NAME = "2E", 190 INVALID_SQL_DESCRIPTOR_NAME = "33", 191 INVALID_CURSOR_NAME = "34", 192 INVALID_EXCEPTION_NUMBER = "35", 193 SYNTAX_ERROR_OR_ACCESS_VIOLATION_IN_DYNAMIC_SQL_STATEMENT = "37", 194 AMBIGUOUS_CURSOR_NAME = "3C", 195 INVALID_CATALOG_NAME = "3D", 196 INVALID_SCHEMA_NAME = "3F", 197 TRANSACTION_ROLLBACK = "40", 198 SYNTAX_ERROR_OR_ACCESS_VIOLATION = "42", 199 WITH_CHECK_OPTION_VIOLATION = "44", 200 REMOTE_DATABASE_ACCESS_ERROR = "HZ"; 201 202 207 public static final String [] NOT_RETRYABLE = 208 { 209 210 SUCCESSFUL_COMPLETION, 211 SUCCESS_WITH_WARNING, 212 NO_DATA, 213 DYNAMIC_SQL_ERROR, 214 FEATURE_NOT_SUPPORTED, 216 CARDINALITY_VIOLATION, 217 DATA_EXCEPTION, 218 INTEGRITY_CONSTRAINT_VIOLATION, 219 INVALID_SQL_STATEMENT_NAME, 222 TRIGGERED_DATA_CHANGE_VIOLATION, 223 INVALID_AUTHORIZATION_SPECIFICATION, 224 SYNTAX_ERROR_OR_ACCESS_VIOLATION_IN_DIRECT_SQL_STATEMENT, 225 DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST, 226 INVALID_CHARACTER_SET_NAME, 227 INVALID_CONNECTION_NAME, 229 INVALID_SQL_DESCRIPTOR_NAME, 230 INVALID_CURSOR_NAME, 231 INVALID_EXCEPTION_NUMBER, 232 SYNTAX_ERROR_OR_ACCESS_VIOLATION_IN_DYNAMIC_SQL_STATEMENT, 233 AMBIGUOUS_CURSOR_NAME, 234 INVALID_CATALOG_NAME, 235 INVALID_SCHEMA_NAME, 236 SYNTAX_ERROR_OR_ACCESS_VIOLATION, 238 WITH_CHECK_OPTION_VIOLATION, 239 }; 241 } 242 } 243 244 469 | Popular Tags |