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 RemovePaintingFromGalleryAction 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 SelectQuery query = new SelectQuery(Painting.class, qual); 38 39 List paintings = ctxt.performQuery(query); 40 41 Painting painting = (Painting) paintings.get(0); 42 System.err.println("painting: " + painting); 43 44 qual = ExpressionFactory.matchExp("galleryName", galleryName); 45 query = new SelectQuery(Gallery.class, qual); 46 47 List galleries = ctxt.performQuery(query); 48 Gallery gallery = (Gallery) galleries.get(0); 49 50 gallery.removeFromPaintingArray(painting); 51 52 ctxt.commitChanges(); 54 55 return mapping.findForward("success"); 56 } 57 } 58 | Popular Tags |