/** * Throw an exception wrapping the given nested exceptions. */ private void throwNestedExceptions(List<Exception> exceps, boolean datastore) { if (exceps == null || exceps.isEmpty()) return; if (datastore && exceps.size() == 1) throw (RuntimeException) exceps.get(0); boolean fatal = false; Throwable[] t = exceps.toArray(new Throwable[exceps.size()]); for (int i = 0; i < t.length; i++) { if (t[i] instanceof OpenJPAException && ((OpenJPAException) t[i]).isFatal()) fatal = true; } OpenJPAException err; if (datastore) err = new StoreException(_loc.get("nested-exceps")); else err = new UserException(_loc.get("nested-exceps")); throw err.setNestedThrowables(t).setFatal(fatal); }
/** * Translate the exception with the failed object. * * @param re exception raised by the delegate. * @param failed the context that failed. * * @return the translated exception. If the given input exception had not set * the failed instance, then sets the given instance as the failed context. */ protected RuntimeException translate(RuntimeException re, Object failed) { if (re instanceof OpenJPAException) { Object o = ((OpenJPAException) re).getFailedObject(); if (o == null || "null".equals(o)) { ((OpenJPAException) re).setFailedObject(Exceptions.toString(failed)); } } return (_trans == null) ? re : _trans.translate(re); }
/** * Translate the given store exception. */ private static Throwable translateStoreException(OpenJPAException ke) { Exception e; switch (ke.getSubtype()) { case StoreException.OBJECT_NOT_FOUND: e = new org.apache.openjpa.persistence.EntityNotFoundException (ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); break; case StoreException.OPTIMISTIC: case StoreException.LOCK: e = new org.apache.openjpa.persistence.OptimisticLockException (ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); break; case StoreException.OBJECT_EXISTS: e = new org.apache.openjpa.persistence.EntityExistsException (ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); break; default: e = new org.apache.openjpa.persistence.PersistenceException (ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } e.setStackTrace(ke.getStackTrace()); return e; }
/** * Return a new exception that wraps <code>causes</code>. * However, the details of exactly what type of exception is returned can * be determined by the implementation. This may take into account * DB-specific exception information in <code>causes</code>. */ public OpenJPAException newStoreException(String msg, SQLException[] causes, Object failed) { if (causes != null && causes.length > 0) { OpenJPAException ret = narrow(msg, causes[0], failed); ret.setFailedObject(failed).setNestedThrowables(causes); return ret; } return new StoreException(msg).setFailedObject(failed). setNestedThrowables(causes); }
/** * Translate the given general exception. */ private static Throwable translateGeneralException(OpenJPAException ke) { Exception e = new org.apache.openjpa.persistence.PersistenceException (ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); e.setStackTrace(ke.getStackTrace()); return e; }
return t; ke = new org.apache.openjpa.util.GeneralException(t.getMessage()); ke.setStackTrace(t.getStackTrace()); return ke; if (ke.getNestedThrowables().length == 1 && isPersistenceException(ke.getCause())) return ke.getCause(); if (ke.getType() == OpenJPAException.USER && ke.getSubtype() == UserException.CALLBACK && ke.getNestedThrowables().length == 1) { Throwable e = ke.getCause(); if (e instanceof InvocationTargetException) e = e.getCause(); switch (ke.getType()) { case OpenJPAException.STORE: return translateStoreException(ke);
failedObject = ((OpenJPAException)t[0]).getFailedObject(); setNestedThrowables(t).setFatal(true).setFailedObject(failedObject);
/** * Remove the given previously dereferenced dependent object from the * cache. It is now referenced. */ void removeDereferencedDependent(StateManagerImpl sm) { lock(); try { boolean removed = false; if (_derefAdditions != null) removed = _derefAdditions.remove(sm); if (!removed && (_derefCache == null || !_derefCache.remove(sm))) throw new InvalidStateException(_loc.get("not-derefed", Exceptions.toString(sm.getManagedInstance()))). setFailedObject(sm.getManagedInstance()). setFatal(true); } finally { unlock(); } }
Throwable cause = ke.getCause(); if (cause instanceof ObjectNotFoundException) { return new EntityNotFoundException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else if (cause instanceof ObjectExistsException) { return new EntityExistsException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else if (cause instanceof NoTransactionException) { return new TransactionRequiredException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else if (cause instanceof OptimisticException) { return new OptimisticLockException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else { return new org.apache.openjpa.persistence.ArgumentException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal());
/** * Convert the specified exception into a {@link StoreException}. */ public static OpenJPAException getStore(String msg, SQLException se, Object failed, DBDictionary dict, int level) { if (msg == null) msg = se.getClass().getName(); SQLException[] ses = getSQLExceptions(se); OpenJPAException storeEx = (dict == null) ? new StoreException(msg).setFailedObject(failed) .setNestedThrowables(ses) : dict.newStoreException(msg, ses, failed); if (level != -1 && storeEx.getSubtype() == StoreException.LOCK) { LockException lockEx = (LockException) storeEx; lockEx.setLockLevel(level); } return storeEx; }
/** * Return the failed object for the given exception, performing any * necessary conversions. */ private static Object getFailedObject(OpenJPAException ke) { Object o = ke.getFailedObject(); if (o == null) return null; if (o instanceof Broker) return JPAFacadeHelper.toEntityManager((Broker) o); return JPAFacadeHelper.fromOpenJPAObjectId(o); }
/** * Convert the specified exception into a {@link StoreException}. */ public static OpenJPAException getStore(String msg, SQLException se, Object failed, DBDictionary dict) { if (msg == null) msg = se.getClass().getName(); SQLException[] ses = getSQLExceptions(se); if (dict == null) return new StoreException(msg).setFailedObject(failed). setNestedThrowables(ses); return dict.newStoreException(msg, ses, failed); }
throw new UserException(_loc.get("bad-externalized-value", new Object[] { val, extValues.keySet(), this })) .setFatal(true).setFailedObject(val); } else { return foundVal;
/** * Translate the nested throwables of the given openjpa exception into * nested throwables for a persistence exception. */ private static Throwable[] getNestedThrowables(OpenJPAException ke) { Throwable[] nested = ke.getNestedThrowables(); if (nested.length == 0) return nested; Throwable[] trans = new Throwable[nested.length]; for (int i = 0; i < nested.length; i++) trans[i] = translateException(nested[i], false); return trans; }
private static Exception translateWrappedException(OpenJPAException ke) { Throwable t = ke.getCause(); if (t instanceof Exception) return (Exception)t; return translateCause(ke); }
return t; ke = new org.apache.openjpa.util.GeneralException(t.getMessage()); ke.setStackTrace(t.getStackTrace()); return ke; if (ke.getNestedThrowables().length == 1 && isPersistenceException(ke.getCause())) return ke.getCause(); if (ke.getType() == OpenJPAException.USER && ke.getSubtype() == UserException.CALLBACK && ke.getNestedThrowables().length == 1) { Throwable e = ke.getCause(); if (e instanceof InvocationTargetException) e = e.getCause(); switch (ke.getType()) { case OpenJPAException.STORE: return translateStoreException(ke);
failedObject = ((OpenJPAException)t[0]).getFailedObject(); setNestedThrowables(t).setFatal(true).setFailedObject(failedObject);
/** * Remove the given previously dereferenced dependent object from the * cache. It is now referenced. */ void removeDereferencedDependent(StateManagerImpl sm) { lock(); try { boolean removed = false; if (_derefAdditions != null) removed = _derefAdditions.remove(sm); if (!removed && (_derefCache == null || !_derefCache.remove(sm))) throw new InvalidStateException(_loc.get("not-derefed", Exceptions.toString(sm.getManagedInstance()))). setFailedObject(sm.getManagedInstance()). setFatal(true); } finally { unlock(); } }
/** * Translate the given general exception. */ private static Throwable translateGeneralException(OpenJPAException ke) { Exception e = new org.apache.openjpa.persistence.PersistenceException (ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); e.setStackTrace(ke.getStackTrace()); return e; }
Throwable cause = ke.getCause(); if (cause instanceof ObjectNotFoundException) { return new EntityNotFoundException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else if (cause instanceof ObjectExistsException) { return new EntityExistsException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else if (cause instanceof NoTransactionException) { return new TransactionRequiredException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else if (cause instanceof OptimisticException) { return new OptimisticLockException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); } else { return new org.apache.openjpa.persistence.ArgumentException( ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal());