Пример #1
0
 /**
  * Fetches a specific object or object graph, in many cases one fetched through a call to <code>
  * getAllAsList()</code> or <code>getAllAsMap()</code>.
  *
  * @param key object key.
  * @return object under given key or <code>null</code> if not found.
  * @see #getAllAsList()
  * @see #getAllAsMap()
  */
 public PersistentObject findByKey(Object key) {
   AbstractDomain domain = getDomain(fullDomainClassName);
   try {
     // If a string decode to binary.
     if (key instanceof String) {
       key = domain.decodePrimaryKey((String) key);
     }
     return domain.find(key);
   } finally {
     releaseDomain(domain);
   }
 }
Пример #2
0
 /**
  * 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);
   }
 }