[jboss-user] [JBoss Seam] - Factory pattern and CRUD operations

asookazian do-not-reply at jboss.com
Wed Oct 31 19:51:21 EDT 2007


So one of the tables/entities is being updated in the table after I submit my use case for a particular employee/row.

I have not coded any explicit calls to the DAO methods.  The submit() method in my SFSB simply has a log4j output statement.

So how is the update transaction actually happening?  This app was reverse-engineering using JPA reverse engineering (via MyEclipse).  So is this a feature of EJB3 (I saw in the server.log that the SFSB was being serialized at one point)?  The only reference to ".merge" in my entire project were commented in the submit() method below.  Only references to "update" are in the DAO classes.

so what's the explanation here for the save/update?

here's the entire SFSB:

package com.cox.beans.session;
  | 
  | import java.util.ArrayList;
  | import java.util.List;
  | 
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.faces.model.SelectItem;
  | import javax.persistence.EntityManager;
  | import javax.persistence.PersistenceContext;
  | 
  | import org.apache.log4j.Logger;
  | import org.jboss.seam.annotations.AutoCreate;
  | import org.jboss.seam.annotations.Destroy;
  | import org.jboss.seam.annotations.Factory;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Out;
  | import org.jboss.seam.annotations.datamodel.DataModel;
  | import org.jboss.seam.annotations.datamodel.DataModelSelection;
  | import org.jboss.seam.security.Identity;
  | 
  | import com.cox.beans.entity.TblSecurityAuditNote;
  | import com.cox.beans.entity.User;
  | 
  | 
  | 
  | @Stateful
  | //@Restrict("#{identity.loggedIn}")
  | @Name("securityAuditAction")
  | public class SecurityAuditAction implements SecurityAuditLocal {
  | 		
  | 	@PersistenceContext(unitName="boIcomsSecurityAudit")
  | 	private EntityManager em;
  | 	
  | 	private String currentEmployeeName = "";
  | 	
  | 	@In(required=false) @Out
  | 	private User user;
  | 	
  | 	@In
  | 	private Identity identity;
  | 	
  | 	@In
  | 	private TblSecurityAuditNote myNotes[][];
  | 	
  | 	@In(create=true)
  | 	private NoteLocal noteAction;
  | 		
  | 	Logger log = Logger.getLogger(this.getClass());
  | 	
  | 	private List<SelectItem> myRadioButtonList;
  | 	
  | 	@DataModel
  | 	private List myAuditList;
  | 		
  | 	@DataModelSelection
  | 	private Object myAuditListSelection;
  | 	
  | 	public SecurityAuditAction() {
  | 		log.info("in SecurityAuditAction()");
  | 	}
  | 		
  |     @Factory("myAuditList")
  |     public void findAuditList()
  |     {
  |     	
  |     	log.info("in getAuditList(): user.getUserId() = " + user.getUserId());   	
  |     	log.info("in getAuditList(): user.getBillingId() = " + user.getBillingId());
  |     		
  |     	int employeeId;
  |     	
  |     	String networkId = noteAction.getNetworkId()==null?"":noteAction.getNetworkId();
  |     	
  |     	if (!networkId.equals("")) {   //user entered a networkId from UI to run for another person, so get new guy's billingId
  |     		    		    		    		    		
  |     		List myList = em.createQuery("from User u where u.networkId = :networkId").setParameter("networkId", networkId).getResultList(); 
  |     		User newUser = (User)myList.get(0);
  |     		
  |     		employeeId = newUser.getEmployeeId().intValue();
  |     		    		    		
  |     		myAuditList = em.createQuery("SELECT gem, tsaw "+
  | 					"FROM TblSecurityAuditWorking tsaw, "+
  | 					"GlobalEmployeeMaster gem "+
  | 					"WHERE tsaw.id.siteId = gem.id.siteId "+
  | 					"AND tsaw.id.employeeNumber = gem.id.employeeNumber "+
  | 					"AND tsaw.reportToId = :employeeId")
  | 					.setParameter("employeeId", employeeId)
  | 					.getResultList();    	
  |     	}    
  |     	else {
  |     		
  |     		List myList = em.createQuery("from User u where u.networkId = :networkId").setParameter("networkId", identity.getUsername()).getResultList(); 
  |     		User user = (User)myList.get(0);
  |     		
  |     		employeeId = user.getEmployeeId().intValue();
  |     		
  | 	    	myAuditList = em.createQuery("SELECT gem, tsaw "+
  | 	    							"FROM TblSecurityAuditWorking tsaw, "+
  | 	    							"GlobalEmployeeMaster gem "+
  | 	    							"WHERE tsaw.id.siteId = gem.id.siteId "+
  | 	    							"AND tsaw.id.employeeNumber = gem.id.employeeNumber "+
  | 	    							"AND tsaw.reportToId = :employeeId")
  | 	    							.setParameter("employeeId", employeeId)
  | 	    							.getResultList();
  |     	}
  |     	
  |     	log.info("in find(): myAuditList.size() = " + myAuditList.size());
  |     	
  |     }
  |     
  |     public List<SelectItem> getSecurityAuditRadioButtons() {
  | 		myRadioButtonList = new ArrayList<SelectItem>();
  | 		myRadioButtonList.add(new SelectItem("true", "Yes", "Yes it is"));
  | 		myRadioButtonList.add(new SelectItem("false", "No", "No it isn't"));
  | 		return myRadioButtonList;
  | 	}
  |     
  |     public void test() {
  |     	log.info("in test()");
  |     	    	
  |     }
  |     
  |     public String getHeader() {
  |     	log.info("in getHeader()");
  |     	return "Please enter your note for the associate";
  | 		//return "Please enter your note for " + currentEmployeeName;		
  | 	}
  |         
  |     
  |     public void submit() {
  |     	
  |     	
  |     	log.info("in submit()");
  |     	
  |     	/*
  |     	
  |     	Iterator it = myAuditList.iterator();
  | 
  |     	while (it.hasNext()) {
  |     	    Object[] result = (Object[])it.next();
  |     	    TblSecurityAuditSnapshot tblSecurityAuditSnapshot = (TblSecurityAuditSnapshot)result[0];
  |     	    em.merge(tblSecurityAuditSnapshot);
  |     	    //why was I updating GlobalEmployeeMaster view?
  |     	    //GlobalEmployeeMaster globalEmployeeMaster = (GlobalEmployeeMaster)result[1];
  |     	    //em.merge(globalEmployeeMaster);    	    
  |     	}
  |     	
  |     	for (int i = 0; i < myNotes.length; i++) {
  |     		log.info("i = " + i);
  |     		for (int j = 0; j < myNotes.length; j++) {
  |     			log.info("j = " + j);
  |     			em.persist(myNotes[j]);
  |     		}
  |     	}
  |     	*/
  |     	
  |     }
  |     
  |     //moved networkId methods to the NoteAction SLSB for now...
  |     
  |     /*public String getNetworkId() {
  |     	if (networkId.equals("")) 
  |     		return identity.getUsername();    	
  |     	else 
  |     		return networkId;
  |     }
  | 	
  |     public void setNetworkId(String networkId) {
  |     	log.info("in setNetworkId(): networkId = " + networkId);
  |     	this.networkId = networkId;
  |     }*/
  |     
  |     public void setCurrentEmployeeName(String employeeName) {
  |     	log.info("in setCurrentEmployeeName: employeeName = " + employeeName);
  |     	currentEmployeeName = employeeName;
  |     }
  |     
  | 	
  | 	
  | 	@Remove @Destroy
  | 	public void destroy() {
  | 		log.info("in destroy()");
  | 	}
  | 
  | 		
  | 	 
  | 
  | }

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

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



More information about the jboss-user mailing list