/** * Deletes a <code>PersistentObject</code> instance, in many cases one fetched through a call to * <code>findByKey()</code>. * * @param persistentObject object to delete. * @param ignoreChangedException If <code>true</code>, <code>ObjectHasChangedException</code> will * not be thrown, but ignored. * @throws ObjectHasChangeException when another user has already delete the record (i.e. an * optimistic lock error) and <code>ignoreChangedException</code> is <code>false</code>. * @see #findByKey(Object) * @see #getAllAsList() */ public void delete(PersistentObject persistentObject, boolean ignoreChangedException) throws ObjectHasChangedException { AbstractDomain domain = getDomain(fullDomainClassName); PersistentObject objectToDelete = persistentObject; try { if (!fullDomainClassName.equals(searchDomainClassName)) { // May have to fetch the composite object. objectToDelete = domain.find(persistentObject); if (objectToDelete == null) { throw new ObjectHasChangedException(persistentObject); } // Handle race condition. } domain.delete(objectToDelete); } catch (ObjectHasChangedException oe) { if (!ignoreChangedException) throw oe; } catch (Exception ex) { if (ex instanceof DatabaseException) throw (DatabaseException) ex; throw new DatabaseException(ex, "Unexpected delete exception"); } finally { releaseDomain(domain); } }