1 package action; 2 3 import java.util.List ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 8 import org.apache.struts.action.Action; 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionForward; 11 import org.apache.struts.action.ActionMapping; 12 import org.objectstyle.cayenne.access.DataContext; 13 import org.objectstyle.cayenne.conf.ServletUtil; 14 import org.objectstyle.cayenne.exp.Expression; 15 import org.objectstyle.cayenne.exp.ExpressionFactory; 16 import org.objectstyle.cayenne.query.SelectQuery; 17 18 import webtest.Gallery; 19 import webtest.Painting; 20 21 public class SubmitPaintingToGalleryAction extends Action { 22 23 public ActionForward execute( 24 ActionMapping mapping, 25 ActionForm form, 26 HttpServletRequest request, 27 HttpServletResponse response) 28 throws Exception { 29 30 DataContext ctxt = 31 ServletUtil.getSessionContext(request.getSession()); 32 33 String paintingTitle = request.getParameter("title"); 34 String galleryName = request.getParameter("galleryName"); 35 36 Expression qual = ExpressionFactory.matchExp("paintingTitle", paintingTitle); 37 38 SelectQuery query = new SelectQuery(Painting.class, qual); 39 40 List paintings = ctxt.performQuery(query); 41 42 Painting painting = (Painting) paintings.get(0); 43 qual = ExpressionFactory.matchExp("galleryName", galleryName); 44 query = new SelectQuery("Gallery", qual); 45 46 List galleries = ctxt.performQuery(query); 47 Gallery gallery = (Gallery) galleries.get(0); 48 49 gallery.addToPaintingArray(painting); 50 51 ctxt.commitChanges(); 53 54 return mapping.findForward("success"); 55 } 56 } 57 | Popular Tags |