KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > action > SubmitPaintingToGalleryAction


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 SubmitPaintingToGalleryAction 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
38         SelectQuery query = new SelectQuery(Painting.class, qual);
39
40         List JavaDoc 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 JavaDoc galleries = ctxt.performQuery(query);
47         Gallery gallery = (Gallery) galleries.get(0);
48
49         gallery.addToPaintingArray(painting);
50
51         // commit to the database
52
ctxt.commitChanges();
53
54         return mapping.findForward("success");
55     }
56 }
57
Popular Tags