1 2 12 package com.versant.core.common; 13 14 import com.versant.core.jdo.*; 15 import java.util.NoSuchElementException ; 16 import java.lang.reflect.InvocationTargetException ; 17 import javax.jdo.*; 18 19 20 21 67 68 public class BindingSupportImpl 69 { 70 71 72 73 private static BindingSupportImpl theInstance = new BindingSupportImpl(); 74 75 public static BindingSupportImpl getInstance() 76 { 77 return theInstance; 78 } 79 80 81 private BindingSupportImpl() {} 82 83 public RuntimeException noSuchElement(String msg) 84 { 85 return new NoSuchElementException (msg); 86 } 87 88 public RuntimeException illegalArgument(String msg) 89 { 90 return new IllegalArgumentException (msg); 91 } 92 93 public RuntimeException security(String msg) 94 { 95 return new SecurityException (msg); 96 } 97 98 public RuntimeException runtime(String msg) 99 { 100 return new JDOFatalUserException(msg); 101 } 102 103 public RuntimeException license(String msg, Throwable t) 104 { 105 return runtime(msg); 106 } 107 108 112 public Throwable findCause(Throwable e) { 113 if (e instanceof InvocationTargetException ) { 114 Throwable te = ((InvocationTargetException )e).getTargetException(); 115 if (te != null) return findCause(te); 116 } 117 return e; 118 } 119 120 public RuntimeException runtime(String msg, Throwable e) 121 { 122 return new JDOFatalUserException(msg, findCause(e)); 123 } 124 125 public RuntimeException unsupported(String m) 126 { 127 return new JDOUnsupportedOptionException(m); 128 } 129 130 public RuntimeException unsupported() 131 { 132 return new JDOUnsupportedOptionException(); 133 } 134 135 public RuntimeException unsupportedOperation(String msg) 136 { 137 return new UnsupportedOperationException (msg); 138 } 139 140 public RuntimeException indexOutOfBounds(String msg) 141 { 142 return new IndexOutOfBoundsException (msg); 143 } 144 145 public RuntimeException arrayIndexOutOfBounds(String msg) 146 { 147 return new ArrayIndexOutOfBoundsException (msg); 148 } 149 150 public RuntimeException arrayIndexOutOfBounds(int val) 151 { 152 return new ArrayIndexOutOfBoundsException (val); 153 } 154 155 public RuntimeException internal(String msg, Throwable cause) 156 { 157 return new JDOFatalInternalException(msg, findCause(cause)); 158 } 159 160 public RuntimeException internal(String msg, Throwable [] cause) 161 { 162 return new JDOFatalInternalException(msg, cause); 163 } 164 165 public RuntimeException internal(String msg) 166 { 167 return new JDOFatalInternalException(msg); 168 } 169 170 public RuntimeException objectNotFound(String msg) 171 { 172 return new JDOObjectNotFoundException(msg); 173 } 174 175 public RuntimeException exception(String msg) 176 { 177 return new JDOException(msg); 178 } 179 180 public RuntimeException exception(String msg, Throwable nested) 181 { 182 return new JDOException(msg, findCause(nested)); 183 } 184 185 public RuntimeException exception(String msg, Throwable [] nested) 186 { 187 return new JDOException(msg, nested); 188 } 189 190 public RuntimeException exception(String msg, Throwable nested, Object failed) 191 { 192 return new JDOException(msg, findCause(nested), failed); 193 } 194 195 public RuntimeException duplicateKey(String msg, Throwable nested, 196 Object failed) 197 { 198 return new VersantDuplicateKeyException(msg, findCause(nested)); 199 } 200 201 public RuntimeException lockNotGranted(String msg, Throwable [] nested, 202 Object failed) 203 { 204 if (nested==null) 205 return new VersantLockTimeoutException(msg); 206 return new VersantLockTimeoutException(msg, nested); 207 } 208 209 public RuntimeException fatal(String msg) 210 { 211 return new JDOFatalException(msg); 212 } 213 214 public RuntimeException fatal(String msg, Throwable t) 215 { 216 return new JDOFatalException(msg, findCause(t)); 217 } 218 219 public RuntimeException concurrentUpdate(String msg, Object failed) 220 { 221 return new JDOOptimisticVerificationException(msg); 222 } 223 224 public RuntimeException optimisticVerification(String msg, Object failed) 225 { 226 return new JDOOptimisticVerificationException(msg); 227 } 228 229 public RuntimeException fieldDetached() 230 { 231 return new VersantDetachedFieldAccessException(); 232 } 233 234 public RuntimeException datastore(String msg, Throwable t) 235 { 236 return new JDODataStoreException(msg, findCause(t)); 237 } 238 239 public RuntimeException datastore(String msg) 240 { 241 return new JDODataStoreException(msg); 242 } 243 244 public RuntimeException fatalDatastore(String msg, Throwable t) 245 { 246 return new JDOFatalDataStoreException(msg, findCause(t)); 247 } 248 249 public RuntimeException fatalDatastore(String msg) 250 { 251 return new JDOFatalDataStoreException(msg); 252 } 253 254 public RuntimeException poolFull(String msg) 255 { 256 return new VersantConnectionPoolFullException(msg); 257 } 258 259 public RuntimeException nullElement(String msg) 260 { 261 return new VersantNullElementException(msg); 262 } 263 264 public RuntimeException invalidObjectId(String msg, Throwable cause) 265 { 266 return new JDOUserException(msg, findCause(cause)); } 268 269 public RuntimeException query(String msg, Throwable cause) 270 { 271 return new JDOUserException(msg, findCause(cause)); } 273 274 public RuntimeException query(String msg) 275 { 276 return new JDOUserException(msg, (Throwable )null); } 278 279 public boolean isOwnQueryException(Throwable e) 280 { 281 return e instanceof JDOUserException; } 283 284 public boolean isOwnInvalidObjectIdException(Throwable e) 285 { 286 return e instanceof JDOUserException; } 288 289 public boolean isOwnException(Throwable e) 290 { 291 return e instanceof JDOException; 292 } 293 294 public boolean isOwnFatalUserException(Throwable e) 295 { 296 return e instanceof JDOFatalUserException; 297 } 298 299 public boolean isOwnFatalException(Throwable e) 300 { 301 return e instanceof JDOFatalException; 302 } 303 304 public boolean isOwnInternalException(Throwable t) 305 { 306 return t instanceof JDOFatalInternalException; 307 } 308 309 public boolean isOwnDatastoreException(Throwable t) 310 { 311 return t instanceof JDODataStoreException; 312 } 313 314 public boolean isOwnFatalDatastoreException(Throwable t) 315 { 316 return t instanceof JDOFatalDataStoreException; 317 } 318 319 public boolean isOwnConcurrentUpdateException(Throwable t) 320 { 321 return t instanceof JDOOptimisticVerificationException; 322 } 323 324 public boolean isOwnObjectNotFoundException(Throwable t) 325 { 326 return t instanceof JDOObjectNotFoundException; 327 } 328 329 public boolean isOwnUnsupportedException(Throwable t) 330 { 331 return t instanceof JDOUnsupportedOptionException; 332 } 333 334 public boolean isOutOfMemoryError(Throwable t) { 335 return t instanceof OutOfMemoryError ; 336 } 337 338 public boolean isError(Throwable t) { 339 return t instanceof Error ; 340 } 341 342 public Object getFailedObject(Exception e) 343 { 344 return ((JDOException)e).getFailedObject(); 345 } 346 347 public RuntimeException invalidOperation(String msg, Throwable cause) 348 { 349 return new JDOUserException(msg, findCause(cause)); 350 } 351 354 public RuntimeException objectNotEnhanced(Object o) 355 { 356 String cl = (o == null ? "Class of passed object" 357 : "Class "+o.getClass().getName()); 358 String msg = cl+" is not declared persistent or not enhanced."; 359 return new JDOFatalUserException(msg); 360 } 361 362 public RuntimeException transactionConflict(Object obj) 363 { 364 return transactionConflict("Object conflicts with other PersistenceManager", obj); 365 } 366 367 public RuntimeException transactionConflict(String msg, Object obj) 368 { 369 return new JDOUserException(msg, obj); 372 } 373 374 public RuntimeException notImplemented(String m) 375 { 376 return new NotImplementedException(m); 377 } 378 379 public RuntimeException invalidOperation(String msg) 380 { 381 return new JDOUserException(msg); 382 } 383 384 } 385 | Popular Tags |