[jboss-user] [JBoss Seam] - Re: DataModel, Factory and Stale Data

tony.herstell@gmail.com do-not-reply at jboss.com
Tue Mar 6 12:42:57 EST 2007


If I understand you well enough then....

if you are going to use a SSB then you pretty much have to manage the data it contains if you are going to update the contents of that data in another conversation...

I have added addOrganisationToExistingList and other "call back" methods that are called by "external" conversations that fix up the data in my SSB (see below - addOrganisationToExistingList)

Caching is helping you not hit the database.. but you got to manage cleaning up the "various" caches if you do stuff invisible to it... if that makes sense.



  | 
  | /** 
  |  * @author Tony Herstell 
  |  * @version $Revision: 1.4 $ $Date: 2007-02-08 00:05:32 $ 
  |  */ 
  | public interface FindOrganisationController {
  | 	
  | 	public void initOrganisations();
  | 
  | 	public String startFind();
  | 
  | 	public String applyFilter();
  | 
  | 	public void destroy();
  | 
  | 	// GUI Support Methods
  | 	public void selectedSearchCriteriaPanelChanged(ValueChangeEvent event);
  | 	
  | 	public void setSelectedSearchCriteriaPanel(String selectedPanel);
  | 	
  | 	public String getSelectedSearchCriteriaPanel();
  | 
  | 	public String getALL_OPTION();
  | 
  | 	public String getFILTERED_OPTION();
  | 
  | 	public boolean getAscending();
  | 	
  | 	public void setAscending(boolean ascending);
  | 	
  | 	public String getSortColumn();
  | 	
  | 	public void setSortColumn(String sortColumn);
  | 
  | 	public void physicalDontCareValueChanged(ValueChangeEvent event);
  | 	
  | 	public String getPhysicalValueRequiredPanel();
  | 	
  | 	public String getPHYSICAL_VALUE_REQUIRED();
  | 	
  | 	public String getPHYSICAL_VALUE_NOT_REQUIRED();
  | 	
  | 	public boolean getPhysicalDontCare();
  | 	
  | 	public void setPhysicalDontCare(boolean physicalDontCare);
  | 	
  | 	
  | 	/*
  | 	 * Used by external rountines to update the session organisations list object.
  | 	 */
  | 	public void addOrganisationToExistingList(Organisation organisation);
  | 
  | 	public void updateOrganisationInExistingList(Organisation organisation);
  | 
  | 	public void deleteOrganisationFromExistingList(Organisation organisation);
  | 	
  | }
  | 
  | 



Gavin will probably have sleepless nights over this code... :)



  | 
  | 	public void addOrganisationToExistingList(Organisation createdOrganisation) {
  | 		log.info("> addOrganisationToExistingList");
  | 		List<Organisation> organisationsList = new ArrayList<Organisation>();
  | 		organisationsList.add(createdOrganisation);
  | 		organisations = organisationsList.toArray(new Organisation[0]);
  | 		sort();
  | 		log.info("< addOrganisationToExistingList");
  | 	}
  | 
  | 	public void deleteOrganisationFromExistingList(Organisation deletedOrganisation) {
  | 		log.info("> deleteOrganisationFromExistingList");
  | 		List<Organisation> organisationsList = new ArrayList<Organisation>();
  | 		for (Organisation eachOrganisation : organisations) {
  | 			if (deletedOrganisation.getId().compareTo(eachOrganisation.getId()) != 0) {
  | 				organisationsList.add(eachOrganisation);
  | 			}
  | 		}
  | 		organisations = organisationsList.toArray(new Organisation[0]);
  | 		log.info("< deleteOrganisationFromExistingList");
  | 	}
  | 
  | 	public void updateOrganisationInExistingList(Organisation updatedOrganisation) {
  | 		log.info("> updateOrganisationInExistingList");
  | 		List<Organisation> organisationsList = new ArrayList<Organisation>();
  | 		for (Organisation eachOrganisation : organisations) {
  | 			if (updatedOrganisation.getId().compareTo(eachOrganisation.getId()) != 0) {
  | 				organisationsList.add(eachOrganisation);
  | 			} else {
  | 				em.refresh(eachOrganisation); // Force the update of the organisation in the em cache.
  | 				if (eachOrganisation.getPicture() != null) {
  | 					em.refresh(eachOrganisation.getPicture()); // Force the update of the picture (for the user) in the em cache.
  | 				}
  | 				log.info(" from the DBase (refreshed) => " + eachOrganisation);
  | 				organisationsList.add(eachOrganisation);
  | 			}
  | 		}
  | 		organisations = organisationsList.toArray(new Organisation[0]);
  | 		applyCurrentQuery();
  | 		log.info("< updateOrganisationInExistingList");
  | 	}
  | 
  | 
  | 


and inside my Crud Controller:


  | @Stateful
  | @Name("cRUDOrganisationController")
  | @Conversational
  | public class CRUDOrganisationControllerImpl implements Serializable, CRUDOrganisationController {
  | 

Inject my SSB so I can call back to it.. to tell it its been updated!

  | 	/*
  | 	 * When we update the organisation then we have to laise with the FindOrganisationsController to refine its list of organisations.
  | 	 */
  | 	@In(create=true)
  | 	@Out
  | 	private FindOrganisationController findOrganisationController;
  | 
  | 

And at the end of this external conversation, i call back to the SSB...


  | 	@End
  | 	@TransactionAttribute(TransactionAttributeType.REQUIRED)
  | 	public String update() {
  | 		log.info("> update");
  | 		em.merge(organisation);
  | 		em.flush();
  | 		facesMessages.addFromResourceBundle("organisation_update_successful");
  | 
  | 		/*
  | 		 * We need to update this organisation in the list of organisations in the session scoped FindOrganisationController
  | 		 */
  | 		if (findOrganisationController != null) {
  | 			log.info("Organisation sent to database => " + organisation);
  | 			findOrganisationController.updateOrganisationInExistingList(organisation);
  | 		}
  | 		
  | 		log.info("< update");
  | 		return "findOrganisation";
  | 	}
  | 


Other prople may have other solutions.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4025505#4025505

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4025505



More information about the jboss-user mailing list