Skip to content

Package: AbstractKapuaQuery

AbstractKapuaQuery

nameinstructionbranchcomplexitylinemethod
AbstractKapuaQuery()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
AbstractKapuaQuery(KapuaId)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
AbstractKapuaQuery(KapuaQuery)
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
addFetchAttributes(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
andPredicate()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
andPredicate(QueryPredicate[])
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
attributePredicate(String, Object)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
attributePredicate(String, Object, AttributePredicate.Operator)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
fieldSortCriteria(String, SortOrder)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getAskTotalCount()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDefaultSortCriteria()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getFetchAttributes()
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getLimit()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getOffset()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPredicate()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getScopeId()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSortCriteria()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
orPredicate()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
orPredicate(QueryPredicate[])
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setAskTotalCount(Boolean)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setFetchAttributes(List)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setLimit(Integer)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setOffset(Integer)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setPredicate(QueryPredicate)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setScopeId(KapuaId)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setSortCriteria(KapuaSortCriteria)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

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.commons.model.query;
14:
15: import org.eclipse.kapua.commons.model.id.KapuaEid;
16: import org.eclipse.kapua.commons.model.query.predicate.AndPredicateImpl;
17: import org.eclipse.kapua.commons.model.query.predicate.AttributePredicateImpl;
18: import org.eclipse.kapua.commons.model.query.predicate.OrPredicateImpl;
19: import org.eclipse.kapua.model.KapuaEntityAttributes;
20: import org.eclipse.kapua.model.id.KapuaId;
21: import org.eclipse.kapua.model.query.FieldSortCriteria;
22: import org.eclipse.kapua.model.query.KapuaQuery;
23: import org.eclipse.kapua.model.query.KapuaSortCriteria;
24: import org.eclipse.kapua.model.query.SortOrder;
25: import org.eclipse.kapua.model.query.predicate.AndPredicate;
26: import org.eclipse.kapua.model.query.predicate.AttributePredicate;
27: import org.eclipse.kapua.model.query.predicate.OrPredicate;
28: import org.eclipse.kapua.model.query.predicate.QueryPredicate;
29:
30: import javax.validation.constraints.NotNull;
31: import java.util.ArrayList;
32: import java.util.List;
33:
34: /**
35: * {@link KapuaQuery} {@code abstract} implementation.
36: *
37: * @since 1.0.0
38: */
39: public abstract class AbstractKapuaQuery implements KapuaQuery {
40:
41: private KapuaId scopeId;
42:
43: private QueryPredicate predicate;
44: private KapuaSortCriteria sortCriteria;
45: private List<String> fetchAttributes;
46:
47: private Integer offset;
48: private Integer limit;
49: private Boolean askTotalCount;
50:
51: /**
52: * Constructor.
53: *
54: * @since 1.0.0
55: */
56: public AbstractKapuaQuery() {
57: }
58:
59: /**
60: * Constructor.
61: *
62: * @param scopeId The scope {@link KapuaId} of the {@link KapuaQuery}
63: * @since 1.0.0
64: */
65: public AbstractKapuaQuery(KapuaId scopeId) {
66: this();
67:
68: setScopeId(scopeId);
69: }
70:
71: /**
72: * Constructor.
73: * <p>
74: * It deeply clones the given {@link KapuaQuery}
75: *
76: * @param query the query to clone.
77: */
78: public AbstractKapuaQuery(@NotNull KapuaQuery query) {
79: setFetchAttributes(query.getFetchAttributes());
80: setPredicate(query.getPredicate());
81: setLimit(query.getLimit());
82: setOffset(query.getOffset());
83: setSortCriteria(query.getSortCriteria());
84: setAskTotalCount(query.getAskTotalCount());
85: }
86:
87: @Override
88: public KapuaId getScopeId() {
89: return scopeId;
90: }
91:
92: @Override
93: public void setScopeId(KapuaId scopeId) {
94: this.scopeId = KapuaEid.parseKapuaId(scopeId);
95: }
96:
97: @Override
98: public void addFetchAttributes(String fetchAttribute) {
99: getFetchAttributes().add(fetchAttribute);
100: }
101:
102: @Override
103: public List<String> getFetchAttributes() {
104:• if (fetchAttributes == null) {
105: fetchAttributes = new ArrayList<>();
106: }
107:
108: return fetchAttributes;
109: }
110:
111: @Override
112: public void setFetchAttributes(List<String> fetchAttributes) {
113: this.fetchAttributes = fetchAttributes;
114: }
115:
116: @Override
117: public QueryPredicate getPredicate() {
118: return this.predicate;
119: }
120:
121: @Override
122: public void setPredicate(QueryPredicate queryPredicate) {
123: this.predicate = queryPredicate;
124: }
125:
126: @Override
127: public KapuaSortCriteria getSortCriteria() {
128: return sortCriteria;
129: }
130:
131: @Override
132: public void setSortCriteria(KapuaSortCriteria sortCriteria) {
133: this.sortCriteria = sortCriteria;
134: }
135:
136: @Override
137: public KapuaSortCriteria getDefaultSortCriteria() {
138: return fieldSortCriteria(KapuaEntityAttributes.ENTITY_ID, SortOrder.ASCENDING);
139: }
140:
141: @Override
142: public Integer getOffset() {
143: return offset;
144: }
145:
146: @Override
147: public void setOffset(Integer offset) {
148: this.offset = offset;
149: }
150:
151: @Override
152: public Integer getLimit() {
153: return limit;
154: }
155:
156: @Override
157: public void setLimit(Integer limit) {
158: this.limit = limit;
159: }
160:
161: @Override
162: public Boolean getAskTotalCount() {
163: return askTotalCount;
164: }
165:
166: @Override
167: public void setAskTotalCount(Boolean askTotalCount) {
168: this.askTotalCount = askTotalCount;
169: }
170:
171: //
172: // Predicate factory
173: @Override
174: public <T> AttributePredicate<T> attributePredicate(String attributeName, T attributeValue) {
175: return new AttributePredicateImpl<>(attributeName, attributeValue);
176: }
177:
178: @Override
179: public <T> AttributePredicate<T> attributePredicate(String attributeName, T attributeValue, AttributePredicate.Operator operator) {
180: return new AttributePredicateImpl<>(attributeName, attributeValue, operator);
181: }
182:
183: @Override
184: public AndPredicate andPredicate() {
185: return new AndPredicateImpl();
186: }
187:
188: @Override
189: public AndPredicate andPredicate(QueryPredicate... queryPredicates) {
190: return new AndPredicateImpl(queryPredicates);
191: }
192:
193: @Override
194: public OrPredicate orPredicate() {
195: return new OrPredicateImpl();
196: }
197:
198: @Override
199: public OrPredicate orPredicate(QueryPredicate... queryPredicates) {
200: return new OrPredicateImpl(queryPredicates);
201: }
202:
203: @Override
204: public FieldSortCriteria fieldSortCriteria(String attributeName, SortOrder sortOrder) {
205: return new FieldSortCriteriaImpl(attributeName, sortOrder);
206: }
207: }