KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > web > taglib > QueryTag


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/web/taglib/QueryTag.java#5 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2002 Kana Software, Inc.
7 // Copyright (C) 2002-2005 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // Andreas Voss, 22 March, 2002
12 */

13 package mondrian.web.taglib;
14
15 import javax.servlet.jsp.JspException JavaDoc;
16 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
17
18 /**
19  * A <code>QueryTag</code> creates a {@link ResultCache} object and initializes
20  * it with the MDX query. Example:<blockquote>
21  *
22  * <pre>&lt;query name="query1" resultCache="true"&gt;
23  * select
24  * {[Measures].[Unit Sales], [Measures].[Store Cost]} on columns,
25  * CrossJoin(
26  * { [Promotion Media].[All Promotion Media].[Radio],
27  * [Promotion Media].[All Promotion Media].[TV],
28  * [Promotion Media].[All Promotion Media].[Sunday Paper],
29  * [Promotion Media].[All Promotion Media].[Street Handout] },
30  * [Product].[All Products].[Drink].children) on rows
31  * from Sales
32  * where ([Time].[1997])
33  * &lt;/query&gt;</pre>
34  *
35  * </blockquote>
36  *
37  * Attributes are
38  * {@link #setName name},
39  * {@link #setResultCache resultCache}.
40  */

41
42 public class QueryTag extends BodyTagSupport JavaDoc {
43
44     public QueryTag() {
45     }
46
47     public int doAfterBody() throws JspException JavaDoc {
48         try {
49             ApplResources ar = ApplResources.getInstance(pageContext.getServletContext());
50             ResultCache rc = ResultCache.getInstance(pageContext.getSession(), pageContext.getServletContext(), name);
51             // if this is the first call, we have to parse the mdx query
52
if (!resultCache || rc.getQuery() == null) {
53                 String JavaDoc mdx = getBodyContent().getString();
54                 rc.parse(mdx);
55             }
56             return SKIP_BODY;
57         }
58         catch (Exception JavaDoc e) {
59             e.printStackTrace();
60             throw new JspException JavaDoc(e);
61         }
62     }
63
64     /** Sets string attribute <code>name</code>, which identifies this query
65      * within its page. The {@link TransformTag#setQuery &lt;transform
66      * query&gt;} attribute uses this. */

67     public void setName(String JavaDoc newName) {
68         name = newName;
69     }
70     public String JavaDoc getName() {
71         return name;
72     }
73     /** Sets boolean attribute <code>resultCache</code>; if true, the query is
74      * parsed, executed, and converted to an XML document at most once. This
75      * improves performance and consistency, but the results may become out of
76      * date. We also need a way to prevent the cache using too much memory. */

77     public void setResultCache(boolean newResultCache) {
78         resultCache = newResultCache;
79     }
80     public boolean isResultCache() {
81         return resultCache;
82     }
83     private String JavaDoc name;
84     private boolean resultCache;
85 }
86
87 // End QueryTag.java
88
Popular Tags