Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
Query | 33 | 0 | - | 0 | 0 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.query; | |
21 | ||
22 | import java.util.List; | |
23 | import java.util.Map; | |
24 | ||
25 | /** | |
26 | * This is a Query interface, representing all queries in various languages for various stores. | |
27 | * | |
28 | * <p>Note that it was modeled after the JCR Query interface.</p> | |
29 | * | |
30 | * @version $Id: 9f1f43359c55e1366b84988cbff7cb953767f62d $ | |
31 | * @since 1.6M1 | |
32 | */ | |
33 | public interface Query | |
34 | { | |
35 | /** | |
36 | * Indicator for Hibernate Query Language. | |
37 | */ | |
38 | String HQL = "hql"; | |
39 | ||
40 | /** | |
41 | * Indicator for XPath language. | |
42 | */ | |
43 | String XPATH = "xpath"; | |
44 | ||
45 | /** | |
46 | * Indicator for XWiki Query Language. | |
47 | */ | |
48 | String XWQL = "xwql"; | |
49 | ||
50 | /** | |
51 | * @return Query statement or query name depends on {@link #isNamed()} | |
52 | */ | |
53 | String getStatement(); | |
54 | ||
55 | /** | |
56 | * @return Query language. See {@link Query#HQL} and others. | |
57 | */ | |
58 | String getLanguage(); | |
59 | ||
60 | /** | |
61 | * if the query is named, then {@link #getStatement()} returns a name of the query, else - a query statement. | |
62 | * | |
63 | * @return is the query named. | |
64 | */ | |
65 | boolean isNamed(); | |
66 | ||
67 | /** | |
68 | * @param wiki virtual wiki to run the query. null is a current wiki. | |
69 | * @return this query | |
70 | */ | |
71 | Query setWiki(String wiki); | |
72 | ||
73 | /** | |
74 | * @return virtual wiki to run the query. null is a current wiki. | |
75 | * @see #setWiki(String) | |
76 | */ | |
77 | String getWiki(); | |
78 | ||
79 | /** | |
80 | * Bind named parameter var with value val in query statement. | |
81 | * | |
82 | * @param var variable in query statement (:var). | |
83 | * @param val value of the variable. | |
84 | * @return this query | |
85 | */ | |
86 | Query bindValue(String var, Object val); | |
87 | ||
88 | /** | |
89 | * Bind a positional parameter present in the statement (?index in XWQL) with a value. It is recommended to use | |
90 | * named parameters if it acceptable, see {@link #bindValue(String, Object)}. | |
91 | * | |
92 | * @param index index of positional parameter. Index starting number depends on the query language. According to the | |
93 | * JPQL standard index should start from 1. | |
94 | * @param val value of the variable. | |
95 | * @return this query | |
96 | */ | |
97 | Query bindValue(int index, Object val); | |
98 | ||
99 | /** | |
100 | * Bind a list of positional parameters values. This method is a convenience method allowing passing a list of | |
101 | * values in one call instead of multiple calls to {@link #bindValue(int, Object)}. | |
102 | * | |
103 | * @param values list of positional parameters values. | |
104 | * @return this query | |
105 | * @see #bindValue(int, Object) | |
106 | */ | |
107 | Query bindValues(List<Object> values); | |
108 | ||
109 | /** | |
110 | * @return map from parameter name to value. | |
111 | * @see #bindValue(String, Object) | |
112 | */ | |
113 | Map<String, Object> getNamedParameters(); | |
114 | ||
115 | /** | |
116 | * @return list of positional parameters values. | |
117 | * @see #bindValue(int, Object) | |
118 | */ | |
119 | Map<Integer, Object> getPositionalParameters(); | |
120 | ||
121 | /** | |
122 | * @param filter the {@link QueryFilter} to add to this query | |
123 | * @return this query | |
124 | */ | |
125 | Query addFilter(QueryFilter filter); | |
126 | ||
127 | /** | |
128 | * @return the list of {@link QueryFilter}s that will be applied to this query | |
129 | */ | |
130 | List<QueryFilter> getFilters(); | |
131 | ||
132 | /** | |
133 | * @param limit see {@link #getLimit()} | |
134 | * @return this query | |
135 | */ | |
136 | Query setLimit(int limit); | |
137 | ||
138 | /** | |
139 | * @param offset offset of query result to set (skip first "offset" rows) | |
140 | * @return this query | |
141 | */ | |
142 | Query setOffset(int offset); | |
143 | ||
144 | /** | |
145 | * @return limit the limit of result list to set ({@code execute().size() <= limit}) | |
146 | * @see #setLimit(int) | |
147 | */ | |
148 | int getLimit(); | |
149 | ||
150 | /** | |
151 | * @return offset offset of query result. | |
152 | * @see #setOffset(int) | |
153 | */ | |
154 | int getOffset(); | |
155 | ||
156 | /** | |
157 | * @param <T> expected type of elements in the result list. | |
158 | * @return result list of the query. If several fields are selected then T=Object[]. | |
159 | * @throws QueryException if something goes wrong. | |
160 | */ | |
161 | <T> List<T> execute() throws QueryException; | |
162 | } |