Skip to content

Package: StorableQuery

StorableQuery

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.storable.model.query;
14:
15: import org.eclipse.kapua.model.KapuaEntity;
16: import org.eclipse.kapua.model.id.KapuaId;
17: import org.eclipse.kapua.model.id.KapuaIdAdapter;
18: import org.eclipse.kapua.service.storable.model.StorableListResult;
19: import org.eclipse.kapua.service.storable.model.query.predicate.StorablePredicate;
20:
21: import javax.xml.bind.annotation.XmlElement;
22: import javax.xml.bind.annotation.XmlElementWrapper;
23: import javax.xml.bind.annotation.XmlTransient;
24: import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
25: import java.util.List;
26:
27: /**
28: * {@link StorableQuery} definition.
29: *
30: * @since 1.0.0
31: */
32: public interface StorableQuery {
33:
34: /**
35: * Gets the fetch attribute names list.
36: *
37: * @return The fetch attribute names list.
38: */
39: @XmlElementWrapper(name = "fetchAttributeName")
40: @XmlElement(name = "fetchAttributeName")
41: public List<String> getFetchAttributes();
42:
43: /**
44: * Adds an attribute to the fetch attribute names list
45: *
46: * @param fetchAttribute The fetch attribute to add to the list.
47: * @since 1.0.0
48: */
49: void addFetchAttributes(String fetchAttribute);
50:
51: /**
52: * Sets the fetch attribute names list.<br>
53: * This list is a list of optional attributes of a {@link KapuaEntity} that can be fetched when querying.
54: *
55: * @param fetchAttributeNames The fetch attribute names list.
56: * @since 1.0.0
57: */
58: void setFetchAttributes(List<String> fetchAttributeNames);
59:
60: /**
61: * Gets the scope {@link KapuaId}.
62: *
63: * @return The scope {@link KapuaId}.
64: * @since 1.0.0
65: */
66: @XmlElement(name = "scopeId")
67: @XmlJavaTypeAdapter(KapuaIdAdapter.class)
68: KapuaId getScopeId();
69:
70: /**
71: * Sets the scope id
72: *
73: * @param scopeId The scope {@link KapuaId}.
74: * @since 1.0.0
75: */
76: void setScopeId(KapuaId scopeId);
77:
78: /**
79: * Gets the {@link StorablePredicate}s
80: *
81: * @return The {@link StorablePredicate}s
82: * @since 1.0.0
83: */
84: @XmlTransient
85: StorablePredicate getPredicate();
86:
87: /**
88: * Sets the {@link StorablePredicate}s
89: *
90: * @param predicate The {@link StorablePredicate}s
91: * @since 1.0.0
92: */
93: void setPredicate(StorablePredicate predicate);
94:
95: /**
96: * Gets the {@link StorableQuery} offset.
97: *
98: * @return The {@link StorableQuery} offset.
99: * @since 1.0.0
100: */
101: @XmlElement(name = "offset")
102: Integer getOffset();
103:
104: /**
105: * Set the {@link StorableQuery} offset in the result set from which start query.
106: * <p>
107: * If set to {@code null} the {@link StorableQuery} will start from the first result found.
108: * This also mean that {@link #setOffset(Integer)} with {@code 0} or {@code null} will produce the same result.
109: * <p>
110: * This method and {@link #setLimit(Integer)} are meant to be used to paginate through the result set.
111: *
112: * @param offset The {@link StorableQuery} offset.
113: * @since 1.0.0
114: */
115: void setOffset(Integer offset);
116:
117:
118: /**
119: * Gets the {@link StorableQuery} limit.
120: *
121: * @return The {@link StorableQuery} limit.
122: * @since 1.0.0
123: */
124: @XmlElement(name = "limit")
125: Integer getLimit();
126:
127: /**
128: * Sets max number of result that will be fetched by this {@link KapuaEntity}.
129: * <p>
130: * If set to {@code null} the {@link StorableQuery} will be unlimited.
131: * <p>
132: * This method and {@link #setOffset(Integer)} are meant to be used to paginate through the result set.
133: *
134: * @param limit The max number of result that will be fetched by this {@link KapuaEntity}.
135: * @since 1.0.0
136: */
137: void setLimit(Integer limit);
138:
139: /**
140: * Whether or not add the {@link StorableListResult#getTotalCount()} when processing the {@link StorableQuery}.
141: *
142: * @return {@code true} to include the StorableListResult#getTotalCount(), {@code false} otherwise.
143: * @since 1.0.0
144: */
145: @XmlElement(name = "askTotalCount")
146: boolean isAskTotalCount();
147:
148: /**
149: * Sets whether or not add the {@link StorableListResult#getTotalCount()} when processing the {@link StorableQuery}.
150: *
151: * @param askTotalCount {@code true} to include the StorableListResult#getTotalCount(), {@code false} otherwise.
152: * @since 1.0.0
153: */
154: void setAskTotalCount(boolean askTotalCount);
155:
156: /**
157: * Gets the {@link StorableFetchStyle}.
158: *
159: * @return The {@link StorableFetchStyle}.
160: * @since 1.0.0
161: */
162: @XmlTransient
163: StorableFetchStyle getFetchStyle();
164:
165: /**
166: * Sets the {@link StorableFetchStyle}.
167: *
168: * @param fetchStyle The {@link StorableFetchStyle}.
169: * @since 1.0.0
170: */
171: void setFetchStyle(StorableFetchStyle fetchStyle);
172:
173: /**
174: * Gets the {@link List} of {@link SortField}s
175: *
176: * @return The {@link List} of {@link SortField}s
177: * @since 1.0.0
178: */
179: @XmlJavaTypeAdapter(SortFieldXmlAdapter.class)
180: List<SortField> getSortFields();
181:
182: /**
183: * Sets the {@link List} of {@link SortField}s
184: *
185: * @param sortFields The {@link List} of {@link SortField}s
186: * @since 1.0.0
187: */
188: void setSortFields(List<SortField> sortFields);
189:
190: /**
191: * Gets the included {@link StorableField}s according to the {@link StorableFetchStyle}.
192: *
193: * @param fetchStyle The {@link StorableFetchStyle}.
194: * @return The included {@link StorableField}s according to the {@link StorableFetchStyle}.
195: * @since 1.0.0
196: */
197: String[] getIncludes(StorableFetchStyle fetchStyle);
198:
199: /**
200: * Gets the excluded {@link StorableField}s according to the {@link StorableFetchStyle}.
201: *
202: * @param fetchStyle The {@link StorableFetchStyle}.
203: * @return The excluded {@link StorableField}s according to the {@link StorableFetchStyle}.
204: * @since 1.0.0
205: */
206: String[] getExcludes(StorableFetchStyle fetchStyle);
207: }