コード例 #1
0
 /**
  * Create request mode means that the user requests the application to create a new persistent
  * bean with supplied information.. In create request mode, new data is stored in persistent
  * storage. The request should provide data for all properties of the {@link PersistentBean},
  * except the {@link PersistentBean#getId()}. If the create operation succeeds, the data is simply
  * displayed in a non-editable way. If the create operation fails, the data is displayed in an
  * HTML form, so that it can be corrected.
  *
  * @pre form != null;
  * @pre form.getPersistentBean() != null;
  * @pre request != null;
  */
 private void templateCreate(final CrudDynaActionForm form, final HttpServletRequest request)
     throws CompoundPropertyException, TechnicalException {
   assert form != null;
   assert request != null;
   if (LOG.isDebugEnabled()) {
     LOG.debug("create action ..."); // $NON-NLS-1$
   }
   form.initBean();
   /*
    * BeanInstantiationException; this means that the app is wrongly
    * configured; this will generate a general error page.
    */
   assert form.getPersistentBean() != null;
   assert form.getPersistentBean().getId() == null;
   form.setViewModeDeleted(false);
   AsynchronousCRUD asyncCRUD = createAsynchronousCRUD(request);
   try {
     asyncCRUD.startTransaction();
     form.formToBean(asyncCRUD); // PropertyException, inside transaction
     form.getPersistentBean().setId(null);
     asyncCRUD.createPersistentBean(form.getPersistentBean());
     // PropertyException
     form.beanToId();
     form.beanToForm(asyncCRUD); // inside transaction
     asyncCRUD.commitTransaction(form.getPersistentBean());
     form.setViewModeEdit(false);
     CreatedEvent pbnEvent = new CreatedEvent(form.getPersistentBean());
     fireCommittedEvent(pbnEvent);
     assert !form.isViewModeNew();
     assert !form.isViewModeDeleted();
     if (LOG.isDebugEnabled()) {
       LOG.debug("create action succeeded"); // $NON-NLS-1$
     }
   } catch (CompoundPropertyException cpExc) {
     form.beanToForm(asyncCRUD);
     asyncCRUD.cancelTransaction();
     form.setViewModeNew(true);
     assert form.isViewModeEdit();
     assert !form.isViewModeDeleted();
     throw cpExc;
   } finally {
     releaseAsynchronousCRUD(asyncCRUD);
   }
 }
コード例 #2
0
 /**
  * New request mode means that the user requests the application to present a form with default
  * information, to be able to request the application to create a new object in the next step. In
  * new request mode, a new persistent bean is created with default data and displayed in an HTML
  * form, so that it can be edited. All the data that is already in this request is used to display
  * the new entity the first time.
  *
  * @throws BeanInstantiationException Could not create a new bean of the expected type.
  * @throws TechnicalException Could evaluate data for a technical reason
  * @throws CompoundPropertyException Some of the provided data is wrong.
  */
 private void templateNew(final CrudDynaActionForm form, final HttpServletRequest request)
     throws BeanInstantiationException, TechnicalException, CompoundPropertyException {
   if (LOG.isDebugEnabled()) {
     LOG.debug("new action ..."); // $NON-NLS-1$
   }
   form.initBean(); // bean contains programmatic defaults
   /*
    * BeanInstantiationException; this means that the app is wrongly
    * configured; this will generate a general error page.
    */
   assert form.getPersistentBean() != null;
   assert form.getPersistentBean().getId() == null;
   form.beanToId();
   AsynchronousCRUD asyncCRUD = createAsynchronousCRUD(request);
   CompoundPropertyException cpExcStore = null;
   try {
     // @todo (dvankeer): Why re-use the data?
     try {
       form.formToBean(asyncCRUD);
       /* get the data that is already in this request,
       overwriting programmatic defaults */
     } catch (CompoundPropertyException cpExc) {
       cpExcStore = cpExc;
       // remember this exception
     }
     // we are not doing this in a transaction, deliberately
     // @todo (jand): is this a good idea?
     form.beanToForm(asyncCRUD);
     // copy default data and data already set into the form
   } finally {
     releaseAsynchronousCRUD(asyncCRUD);
   }
   form.setViewModeNew(true);
   assert form.isViewModeEdit();
   assert !form.isViewModeDeleted();
   if (LOG.isDebugEnabled()) {
     LOG.debug("new action succeeded"); // $NON-NLS-1$
   }
   if (cpExcStore != null) {
     throw cpExcStore;
   }
 }
コード例 #3
0
 /**
  * Delete request mode means that the user requests the application to delete an existing bean. In
  * delete request mode, existing data is deleted from persistent storage. The request should
  * provide data for the {@link PersistentBean#getId()}. If the delete operation succeeds, the data
  * is displayed in a non-editable way, with a notice that signifies successful deletion. If the
  * delete operation fails, the data is displayed in a non-editable way, with an error notice. This
  * method first sets the id of the persistent bean from the request. Next, the persistent bean is
  * retrieved from the database. Only after that, the persistent bean will be deleted. This is done
  * to have an early warning of errors in the key, or access violations.
  *
  * @idea (jand) This would also make it possible to check here whether all information in the
  *     request matches the information in persistent storage during this transaction.
  * @pre form != null;
  * @pre form.getPersistentBean() != null;
  * @pre request != null;
  */
 private void templateDelete(final CrudDynaActionForm form, final HttpServletRequest request)
     throws CompoundPropertyException, IdException, TechnicalException {
   assert form != null;
   // assert form.getPersistentBean() != null;
   assert request != null;
   if (LOG.isDebugEnabled()) {
     LOG.debug("delete action ..."); // $NON-NLS-1$
   }
   form.setViewModeEdit(false);
   AsynchronousCRUD asyncCRUD = createAsynchronousCRUD(request);
   DeletedEvent pbdEvent = null;
   try {
     asyncCRUD.startTransaction();
     retrieveWithId(form, asyncCRUD); // IdException
     assert form.getPersistentBean() != null;
     pbdEvent = new DeletedEvent(form.getPersistentBean());
     asyncCRUD.deletePersistentBean(form.getPersistentBean());
     asyncCRUD.commitTransaction(form.getPersistentBean());
     assert form.getPersistentBean().getId() == null;
     form.beanToId(); // must be null
     form.setViewModeDeleted(true); // rae.isEmpty());
     if (LOG.isDebugEnabled()) {
       LOG.debug("delete action succeeded"); // $NON-NLS-1$
     }
   } catch (CompoundPropertyException cpExc) {
     asyncCRUD.cancelTransaction();
     form.setViewModeDeleted(false);
     throw cpExc;
   } catch (IdException pkvExc) {
     asyncCRUD.cancelTransaction();
     form.setViewModeDeleted(false);
     throw pkvExc;
   } finally {
     form.beanToForm(asyncCRUD);
     releaseAsynchronousCRUD(asyncCRUD);
   }
   fireCommittedEvent(pbdEvent);
   assert !form.isViewModeNew();
   assert !form.isViewModeEdit();
 }