org.xwiki.query.internal
Class DefaultQuery

java.lang.Object
  extended by org.xwiki.query.internal.DefaultQuery
All Implemented Interfaces:
Query

public class DefaultQuery
extends java.lang.Object
implements Query

Stores all information needed for execute a query.

Since:
1.6M1
Version:
$Id$

Field Summary
 
Fields inherited from interface org.xwiki.query.Query
HQL, XPATH, XWQL
 
Constructor Summary
DefaultQuery(java.lang.String queryName, QueryExecutor executor)
          Create a named Query.
DefaultQuery(java.lang.String statement, java.lang.String language, QueryExecutor executor)
          Create a Query.
 
Method Summary
 Query bindValue(int index, java.lang.Object val)
          Bind positional parameter (?index in JPQL) with value val in query statement.
 Query bindValue(java.lang.String var, java.lang.Object val)
          Bind named parameter var with value val in query statement.
 Query bindValues(java.util.List<java.lang.Object> values)
          Bind list of positional parameters values.
<T> java.util.List<T>
execute()
          
protected  QueryExecutor getExecuter()
           
 java.lang.String getLanguage()
          
 int getLimit()
          
 java.util.Map<java.lang.String,java.lang.Object> getNamedParameters()
          
 int getOffset()
          
 java.util.Map<java.lang.Integer,java.lang.Object> getPositionalParameters()
          
 java.lang.String getStatement()
          
 java.lang.String getWiki()
          
 boolean isNamed()
          if the query is named, then Query.getStatement() returns a name of the query, else - a query statement.
 Query setLimit(int limit)
          
 Query setOffset(int offset)
          
 Query setWiki(java.lang.String wiki)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultQuery

public DefaultQuery(java.lang.String statement,
                    java.lang.String language,
                    QueryExecutor executor)
Create a Query.

Parameters:
statement - query statement
language - query language
executor - QueryExecutor component for execute the query.

DefaultQuery

public DefaultQuery(java.lang.String queryName,
                    QueryExecutor executor)
Create a named Query.

Parameters:
queryName - name of the query.
executor - QueryExecutor component for execute the query.
Method Detail

getStatement

public java.lang.String getStatement()

Specified by:
getStatement in interface Query
Returns:
Query statement or query name depends on Query.isNamed()

getLanguage

public java.lang.String getLanguage()

Specified by:
getLanguage in interface Query
Returns:
Query language. See Query.HQL and others.

isNamed

public boolean isNamed()
if the query is named, then Query.getStatement() returns a name of the query, else - a query statement.

Specified by:
isNamed in interface Query
Returns:
is the query named.

setWiki

public Query setWiki(java.lang.String wiki)

Specified by:
setWiki in interface Query
Parameters:
wiki - virtual wiki to run the query. null is a current wiki.
Returns:
this query.

getWiki

public java.lang.String getWiki()

Specified by:
getWiki in interface Query
Returns:
virtual wiki to run the query. null is a current wiki.
See Also:
Query.setWiki(String)

bindValue

public Query bindValue(java.lang.String var,
                       java.lang.Object val)
Bind named parameter var with value val in query statement.

Specified by:
bindValue in interface Query
Parameters:
var - variable in query statement (:var).
val - value of the variable.
Returns:
this query.

bindValue

public Query bindValue(int index,
                       java.lang.Object val)
Bind positional parameter (?index in JPQL) with value val in query statement. It is recommended to use named parameters if it acceptable. see Query.bindValue(String, Object)

Specified by:
bindValue in interface Query
Parameters:
index - index of positional parameter. Index starting number is depends on store system. According JPQL standard index should start from 1.
val - value of the variable.
Returns:
this query.

bindValues

public Query bindValues(java.util.List<java.lang.Object> values)
Bind list of positional parameters values. values[i] became i+1 positional parameter according JPQL. So it works only for "?index" parameters.

Specified by:
bindValues in interface Query
Parameters:
values - list of positional parameters values.
Returns:
this query.
See Also:
Query.bindValue(int, Object)

getLimit

public int getLimit()

Specified by:
getLimit in interface Query
Returns:
limit limit of result list.
See Also:
Query.setLimit(int)

getOffset

public int getOffset()

Specified by:
getOffset in interface Query
Returns:
offset offset of query result.
See Also:
Query.setOffset(int)

setLimit

public Query setLimit(int limit)

Specified by:
setLimit in interface Query
Parameters:
limit - limit of result list to set (so Query.execute().size() will be <= limit).
Returns:
this query.

setOffset

public Query setOffset(int offset)

Specified by:
setOffset in interface Query
Parameters:
offset - offset of query result to set (skip first "offset" rows).
Returns:
this query.

getNamedParameters

public java.util.Map<java.lang.String,java.lang.Object> getNamedParameters()

Specified by:
getNamedParameters in interface Query
Returns:
map from parameter name to value.
See Also:
Query.bindValue(String, Object)

getPositionalParameters

public java.util.Map<java.lang.Integer,java.lang.Object> getPositionalParameters()

Specified by:
getPositionalParameters in interface Query
Returns:
list of positional parameters values.
See Also:
Query.bindValue(int, Object)

execute

public <T> java.util.List<T> execute()
                          throws QueryException

Specified by:
execute in interface Query
Type Parameters:
T - expected type of elements in the result list.
Returns:
result list of the query. If several fields are selected then T=Object[].
Throws:
QueryException - if something goes wrong.

getExecuter

protected QueryExecutor getExecuter()
Returns:
QueryExecutor interface for execute the query.


Copyright © 2004-2011 XWiki. All Rights Reserved.