KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > action > RemovePaintingFromGalleryAction


1 package action;
2
3 import java.util.List JavaDoc;
4
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc request,
27         HttpServletResponse JavaDoc response)
28         throws Exception JavaDoc {
29
30         DataContext ctxt =
31             ServletUtil.getSessionContext(request.getSession());
32
33         String JavaDoc paintingTitle = request.getParameter("title");
34         String JavaDoc galleryName = request.getParameter("galleryName");
35
36         Expression qual = ExpressionFactory.matchExp("paintingTitle", paintingTitle);
37         SelectQuery query = new SelectQuery(Painting.class, qual);
38
39         List JavaDoc 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 JavaDoc galleries = ctxt.performQuery(query);
48         Gallery gallery = (Gallery) galleries.get(0);
49
50         gallery.removeFromPaintingArray(painting);
51
52         // commit to the database
53
ctxt.commitChanges();
54
55         return mapping.findForward("success");
56     }
57 }
58
Popular Tags