org.makumba.list.tags
Class QueryTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by org.makumba.analyser.AnalysableElement
          extended by org.makumba.analyser.AnalysableTag
              extended by org.makumba.commons.tags.GenericMakumbaTag
                  extended by org.makumba.list.tags.GenericListTag
                      extended by org.makumba.list.tags.QueryTag
All Implemented Interfaces:
Serializable, IterationTag, JspTag, Tag
Direct Known Subclasses:
ObjectTag, ResultListTag

public class QueryTag
extends GenericListTag
implements IterationTag

Display of OQL query results in nested loops. The Query FROM, WHERE, GROUPBY and ORDERBY are indicated in the head of the tag. The query projections are indicated by Value tags in the body of the tag. The sub-tags will generate subqueries of their enclosing tag queries (i.e. their WHERE, GROUPBY and ORDERBY are concatenated). Attributes of the environment can be passed as $attrName to the query

Version:
$Id: QueryTag.java 5153 2010-05-18 21:37:50Z rosso_nero $
Author:
Cristian Bogdan
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.makumba.analyser.AnalysableElement
AnalysableElement.FilePositionElementComparator
 
Field Summary
protected  String authorize
           
(package private)  String countVar
           
(package private)  String editable
           
(package private)  String editPage
           
(package private)  QueryExecution execution
           
(package private) static String lastFinishedListKey
           
(package private)  String limit
           
(package private)  String logicClass
           
(package private)  String maxCountVar
           
(package private)  String offset
           
(package private) static Integer one
           
(package private) static String queryExecuted
           
(package private)  String[] queryProps
           
(package private) static String runningListKeyStack
           
(package private)  String separator
           
(package private) static String standardCountVar
           
(package private) static String standardLastCountVar
           
(package private) static String standardMaxCountVar
           
(package private) static String standardMaxResultsKey
           
(package private) static String standardMaxResultsVar
           
(package private) static String standardNextCountVar
           
(package private)  Object upperCount
           
(package private)  Object upperMaxCount
           
(package private)  Object upperMaxResults
           
(package private) static Integer zero
           
 
Fields inherited from class org.makumba.list.tags.GenericListTag
fdp
 
Fields inherited from class org.makumba.commons.tags.GenericMakumbaTag
extraFormatting, extraFormattingParams, NEEDED_RESOURCES, params
 
Fields inherited from class org.makumba.analyser.AnalysableTag
ATTRIBUTE_VALUES_TRUE_FALSE, tagData, tagKey, TYPES
 
Fields inherited from class org.makumba.analyser.AnalysableElement
ANALYSIS_STATE
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
QueryTag()
           
 
Method Summary
 boolean allowsIdenticalKey()
          Determines whether the tag can have the same key as others in the page
static ComposedQuery cacheQuery(PageCache pc, MultipleKey key, String[] sections, MultipleKey parentKey)
          Gets a composed query from the cache, and if none is found, creates one and caches it.
 boolean canHaveBody()
          Determines whether this tag can have a body or not.
static int count()
          Gives the value of the iteration in progress
 int doAfterBody()
          Decides whether to do further iterations.
protected  void doAnalyzedCleanup()
          Called by doEndTag in its finally block.
 int doAnalyzedEndTag(PageCache pageCache)
          Cleans up variables, especially for the rootList.
 int doAnalyzedStartTag(PageCache pageCache)
          Decides if there will be any tag iteration.
 void doEndAnalyze(PageCache pageCache)
          Ends the analysis of the tag, after all tags in the page were visited.
 void doStartAnalyze(PageCache pageCache)
          Starts the analysis of the tag, without knowing what tags follow it in the page.
 int getCurrentIterationNumber()
          Gets the number of the current iteration
 String getEditable()
           
 String getEditPage()
           
 int getLimitInt()
           
 String getLogicClass()
           
 int getNumberOfIterations()
          Gets the number of iterations of this list
 int getOffsetInt()
           
static AnalysableTag getParentList(AnalysableTag tag)
          Finds the parentList of a list
static MultipleKey getParentListKey(AnalysableTag tag, PageCache pageCache)
          Finds the key of the parentList of the Tag
static ComposedQuery getQuery(PageCache pc, MultipleKey key)
          Gets the query for a given key
static Stack<MultipleKey> getRunningQueryTagStack(PageContext pageContext)
          Gets the stack of currently running (nested) Query Tags from the pageContext
static int lastCount()
          Gives the total number of iterations of the previous iterationGroup
static int lastCountById(String id)
          Gives the total number of iterations of the iterationGroup identified by the given ID string
static int maxCount()
          Gives the maximum number of iteration of the iterationGroup
static int maxResults()
          Gives the maximum number of results returned as if the query would not contain any limit / offset.
static int nextCount()
          Gives the total number of iterations of the next iterationGroup.
static int nextCountById(String id)
          Gives the total number of iterations of the next iterationGroup.
protected  void onlyOuterListArgument(String s)
           
 void setAuthorize(String s)
           
 void setCountVar(String s)
           
 void setDefaultLimit(String s)
           
 void setEditable(String s)
           
 void setEditPage(String editPage)
           
 void setFrom(String s)
           
 void setGroupBy(String s)
           
 void setLimit(String s)
           
 void setLogicClass(String logicClass)
           
 void setMaxCountVar(String s)
           
protected  void setNumberOfIterations(int n)
          Sets the number of iterations in the iterationGroup.
 void setOffset(String s)
           
 void setOrderBy(String s)
           
 void setSeparator(String s)
           
 void setTagKey(PageCache pageCache)
          Computes and set the tagKey.
 void setVariableFrom(String s)
           
 void setWhere(String s)
           
 
Methods inherited from class org.makumba.list.tags.GenericListTag
addToParentListKey, doEndTag, getDatabaseName, getDataSourceName, onlyRootArgument, setDb
 
Methods inherited from class org.makumba.commons.tags.GenericMakumbaTag
doStartTag, getParams, initialiseState, isAttribute, setAddTitle, setCols, setDefault, setElementSeparator, setEllipsis, setEllipsisLength, setEmpty, setFormat, setHtml, setLabelSeparator, setLineSeparator, setLongLineLength, setMaxlength, setMaxLength, setOnClick, setOnDblClick, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setRows, setSize, setStyle, setStyleClass, setStyleId, setTitle, setType, setType, setUrlEncode, toString
 
Methods inherited from class org.makumba.analyser.AnalysableTag
addTagText, checkAttributeValues, getElementData, getPageContext, getPageTextInfo, getTagKey, getTagText, needPageCache, notEmpty, onlyInt, registerAttributeValues, registerPossibleAttributeValues, setTagDataAtAnalysis
 
Methods inherited from class org.makumba.analyser.AnalysableElement
checkTagFound, discardJSPParsingData, getAnalyzedElementData, getCurrentBodyTagData, getElementAfter, getElementBefore, getPageCache, getPageCache, getRunningElementData, getTagByAttribute, getTagById, getThreadElementStack, initializeThread, keepAnalysisState, setAnalyzedElementData, setRunningElementData
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
doEndTag, doStartTag, getParent, release, setPageContext, setParent
 

Field Detail

queryProps

String[] queryProps

separator

String separator

countVar

String countVar

maxCountVar

String maxCountVar

offset

String offset

limit

String limit

editable

String editable

logicClass

String logicClass

editPage

String editPage

authorize

protected String authorize

standardCountVar

static String standardCountVar

standardMaxCountVar

static String standardMaxCountVar

standardLastCountVar

static String standardLastCountVar

standardNextCountVar

static String standardNextCountVar

standardMaxResultsVar

static String standardMaxResultsVar

standardMaxResultsKey

static String standardMaxResultsKey

lastFinishedListKey

static String lastFinishedListKey

runningListKeyStack

static String runningListKeyStack

queryExecuted

static String queryExecuted

execution

QueryExecution execution

zero

static final Integer zero

one

static final Integer one

upperCount

Object upperCount

upperMaxCount

Object upperMaxCount

upperMaxResults

Object upperMaxResults
Constructor Detail

QueryTag

public QueryTag()
Method Detail

setFrom

public void setFrom(String s)

setVariableFrom

public void setVariableFrom(String s)

setWhere

public void setWhere(String s)

setOrderBy

public void setOrderBy(String s)

setGroupBy

public void setGroupBy(String s)

setSeparator

public void setSeparator(String s)

setCountVar

public void setCountVar(String s)

setMaxCountVar

public void setMaxCountVar(String s)

setOffset

public void setOffset(String s)
               throws JspException
Throws:
JspException

setLimit

public void setLimit(String s)
              throws JspException
Throws:
JspException

setDefaultLimit

public void setDefaultLimit(String s)
                     throws JspException
Throws:
JspException

setAuthorize

public void setAuthorize(String s)

setEditable

public void setEditable(String s)

getLogicClass

public String getLogicClass()

setLogicClass

public void setLogicClass(String logicClass)

getEditPage

public String getEditPage()

setEditPage

public void setEditPage(String editPage)

getEditable

public String getEditable()

getLimitInt

public int getLimitInt()

getOffsetInt

public int getOffsetInt()

onlyOuterListArgument

protected void onlyOuterListArgument(String s)
                              throws JspException
Throws:
JspException

setTagKey

public void setTagKey(PageCache pageCache)
Computes and set the tagKey. At analysis time, the listQuery is associated with the tagKey, and retrieved at runtime. At runtime, the QueryExecution is discovered by the tag based on the tagKey.

Overrides:
setTagKey in class AnalysableTag
Parameters:
pageCache - The page cache for the current page
See Also:
AnalysableTag.doAnalyzedStartTag(org.makumba.analyser.PageCache), AnalysableTag.doStartAnalyze(org.makumba.analyser.PageCache)

allowsIdenticalKey

public boolean allowsIdenticalKey()
Determines whether the tag can have the same key as others in the page

Overrides:
allowsIdenticalKey in class AnalysableTag
Returns:
true if the tag is allowed to have the same key as others in the page, false otherwise

doStartAnalyze

public void doStartAnalyze(PageCache pageCache)
Starts the analysis of the tag, without knowing what tags follow it in the page. Defines a query, sets the types of variables to "int".

Overrides:
doStartAnalyze in class AnalysableTag
Parameters:
pageCache - The page cache for the current page

doEndAnalyze

public void doEndAnalyze(PageCache pageCache)
Ends the analysis of the tag, after all tags in the page were visited. As all the query projections are known, a RecordViewer is cached as formatter for the mak:values nested in this tag.

Overrides:
doEndAnalyze in class AnalysableTag
Parameters:
pageCache - The page cache for the current page

doAnalyzedStartTag

public int doAnalyzedStartTag(PageCache pageCache)
                       throws LogicException,
                              JspException
Decides if there will be any tag iteration. The QueryExecution is found (and made if needed), and we check if there are any results in the iterationGroup. Calls initiateQueryExecution(PageContext, boolean) and doTagExecution(PageCache, PageContext)

Overrides:
doAnalyzedStartTag in class AnalysableTag
Parameters:
pageCache - The page cache for the current page
Returns:
The tag return state as defined in the Tag interface
Throws:
LogicException
JspException
See Also:
QueryExecution

setNumberOfIterations

protected void setNumberOfIterations(int n)
                              throws JspException
Sets the number of iterations in the iterationGroup. ObjectTag will redefine this and throw an exception if n>1

Parameters:
n - The number of iterations in the iterationGroup
Throws:
JspException
See Also:
ObjectTag

getNumberOfIterations

public int getNumberOfIterations()
Gets the number of iterations of this list


getCurrentIterationNumber

public int getCurrentIterationNumber()
Gets the number of the current iteration


doAfterBody

public int doAfterBody()
                throws JspException
Decides whether to do further iterations. Checks if we got to the end of the iterationGroup.

Specified by:
doAfterBody in interface IterationTag
Overrides:
doAfterBody in class TagSupport
Returns:
The tag return state as defined in the Tag interface
Throws:
JspException

doAnalyzedEndTag

public int doAnalyzedEndTag(PageCache pageCache)
                     throws JspException
Cleans up variables, especially for the rootList.

Overrides:
doAnalyzedEndTag in class AnalysableTag
Parameters:
pageCache - The page cache for the current page
Returns:
The tag return state as defined in the Tag interface in order to continue evaluating the page.
Throws:
JspException
See Also:
AnalysableTag.doEndTag()

getParentList

public static AnalysableTag getParentList(AnalysableTag tag)
Finds the parentList of a list

Parameters:
tag - the tag we want to discover the parent of
Returns:
the parent QueryTag of the Tag

getParentListKey

public static MultipleKey getParentListKey(AnalysableTag tag,
                                           PageCache pageCache)
Finds the key of the parentList of the Tag

Parameters:
tag - the tag we want to discover the parent of
pageCache - the pageCache of the current page
Returns:
The MultipleKey identifying the parentList

getQuery

public static ComposedQuery getQuery(PageCache pc,
                                     MultipleKey key)
Gets the query for a given key

Parameters:
key - the key of the tag for which we want to get a query
Returns:
The OQL query corresponding to this tag

cacheQuery

public static ComposedQuery cacheQuery(PageCache pc,
                                       MultipleKey key,
                                       String[] sections,
                                       MultipleKey parentKey)
Gets a composed query from the cache, and if none is found, creates one and caches it.

Parameters:
key - the key of the tag
sections - the sections needed to compose a query
parentKey - the key of the parent tag, if any

count

public static int count()
Gives the value of the iteration in progress

Returns:
The current count of iterations

maxCount

public static int maxCount()
Gives the maximum number of iteration of the iterationGroup

Returns:
The maximum number of iterations within the current iterationGroup

maxResults

public static int maxResults()
Gives the maximum number of results returned as if the query would not contain any limit / offset.
TODO: we need to pass quite some information in the request attributes, as this method has to be static. Not sure what happens if there are more lists in the same page, if that would overlap or not.

Returns:
The maximum number of results returned as if the query would not contain any limit / offset.

lastCount

public static int lastCount()
Gives the total number of iterations of the previous iterationGroup

Returns:
The total number of iterations performed within the previous iterationGroup

lastCountById

public static int lastCountById(String id)
Gives the total number of iterations of the iterationGroup identified by the given ID string

Parameters:
id - the id of the mak:list or mak:object tag to relate to
Returns:
The total number of iterations performed within the given iterationGroup

nextCount

public static int nextCount()
                     throws LogicException,
                            JspException
Gives the total number of iterations of the next iterationGroup.
Invoking this method in the JSP page will cause this mak:list/object to pre-execute it's query, for the number of iterations to be known before the tag will actually be executed.

Returns:
The total number of iterations that will be performed within the next iterationGroup
Throws:
LogicException
JspException

nextCountById

public static int nextCountById(String id)
                         throws LogicException,
                                JspException
Gives the total number of iterations of the next iterationGroup.
Invoking this method in the JSP page will cause this mak:list/object to pre-execute it's query, for the number of iterations to be known before the tag will actually be executed.

Parameters:
id - the ID of the mak:list/object to relate to
Returns:
The total number of iterations that will be performed within the next iterationGroup
Throws:
LogicException
JspException

getRunningQueryTagStack

public static Stack<MultipleKey> getRunningQueryTagStack(PageContext pageContext)
Gets the stack of currently running (nested) Query Tags from the pageContext


canHaveBody

public boolean canHaveBody()
Description copied from class: AnalysableTag
Determines whether this tag can have a body or not.

Overrides:
canHaveBody in class AnalysableTag
Returns:
true if the tag is allowed to have a body, false otherwise

doAnalyzedCleanup

protected void doAnalyzedCleanup()
Description copied from class: AnalysableTag
Called by doEndTag in its finally block. Use it to clean references that will not be used next time the servlet container uses the tag object.

Overrides:
doAnalyzedCleanup in class GenericMakumbaTag