/
DefaultDocumentMapperSelectBuilder.java
218 lines (176 loc) · 6.03 KB
/
DefaultDocumentMapperSelectBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* Copyright (c) 2017 Otávio Santana and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.jnosql.artemis.document.query;
import org.jnosql.artemis.Converters;
import org.jnosql.artemis.Page;
import org.jnosql.artemis.Pagination;
import org.jnosql.artemis.document.DocumentQueryPagination;
import org.jnosql.artemis.document.DocumentTemplate;
import org.jnosql.artemis.document.DocumentTemplateAsync;
import org.jnosql.artemis.reflection.ClassMapping;
import org.jnosql.diana.api.Sort;
import org.jnosql.diana.api.document.DocumentQuery;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import static java.util.Objects.requireNonNull;
class DefaultDocumentMapperSelectBuilder extends AbstractMapperQuery implements DocumentMapperFrom, DocumentMapperLimit,
DocumentMapperSkip, DocumentMapperOrder, DocumentMapperNameCondition,
DocumentMapperNotCondition, DocumentMapperNameOrder, DocumentMapperWhere {
private final List<Sort> sorts = new ArrayList<>();
DefaultDocumentMapperSelectBuilder(ClassMapping mapping, Converters converters) {
super(mapping, converters);
}
@Override
public DocumentMapperNameCondition and(String name) {
requireNonNull(name, "name is required");
this.name = name;
this.and = true;
return this;
}
@Override
public DocumentMapperNameCondition or(String name) {
requireNonNull(name, "name is required");
this.name = name;
this.and = false;
return this;
}
@Override
public DocumentMapperNameCondition where(String name) {
requireNonNull(name, "name is required");
this.name = name;
return this;
}
@Override
public DocumentMapperSkip skip(long start) {
this.start = start;
return this;
}
@Override
public DocumentMapperLimit limit(long limit) {
this.limit = limit;
return this;
}
@Override
public DocumentMapperOrder orderBy(String name) {
requireNonNull(name, "name is required");
this.name = name;
return this;
}
@Override
public DocumentMapperNotCondition not() {
this.negate = true;
return this;
}
@Override
public <T> DocumentMapperWhere eq(T value) {
eqImpl(value);
return this;
}
@Override
public DocumentMapperWhere like(String value) {
likeImpl(value);
return this;
}
@Override
public <T> DocumentMapperWhere gt(T value) {
gtImpl(value);
return this;
}
@Override
public <T> DocumentMapperWhere gte(T value) {
gteImpl(value);
return this;
}
@Override
public <T> DocumentMapperWhere lt(T value) {
ltImpl(value);
return this;
}
@Override
public <T> DocumentMapperWhere lte(T value) {
lteImpl(value);
return this;
}
@Override
public <T> DocumentMapperWhere between(T valueA, T valueB) {
betweenImpl(valueA, valueB);
return this;
}
@Override
public <T> DocumentMapperWhere in(Iterable<T> values) {
inImpl(values);
return this;
}
@Override
public DocumentMapperNameOrder asc() {
this.sorts.add(Sort.of(mapping.getColumnField(name), Sort.SortType.ASC));
return this;
}
@Override
public DocumentMapperNameOrder desc() {
this.sorts.add(Sort.of(mapping.getColumnField(name), Sort.SortType.DESC));
return this;
}
@Override
public DocumentQuery build() {
return new ArtemisDocumentQuery(sorts, limit, start, condition, documentCollection);
}
@Override
public DocumentQuery build(Pagination pagination) {
requireNonNull(pagination, "pagination is required");
return DocumentQueryPagination.of(build(), pagination);
}
@Override
public <T> List<T> execute(DocumentTemplate template) {
Objects.requireNonNull(template, "template is required");
return template.select(this.build());
}
@Override
public <T> Optional<T> executeSingle(DocumentTemplate template) {
Objects.requireNonNull(template, "template is required");
return template.singleResult(this.build());
}
@Override
public <T> List<T> execute(DocumentTemplate template, Pagination pagination) {
requireNonNull(template, "template is required");
requireNonNull(pagination, "pagination is required");
return template.select(this.build(pagination));
}
@Override
public <T> Optional<T> executeSingle(DocumentTemplate template, Pagination pagination) {
requireNonNull(template, "template is required");
requireNonNull(pagination, "pagination is required");
return template.singleResult(this.build(pagination));
}
@Override
public <T> void execute(DocumentTemplateAsync template, Consumer<List<T>> callback) {
Objects.requireNonNull(template, "template is required");
Objects.requireNonNull(callback, "callback is required");
template.select(this.build(), callback);
}
@Override
public <T> void executeSingle(DocumentTemplateAsync template, Consumer<Optional<T>> callback) {
Objects.requireNonNull(template, "template is required");
Objects.requireNonNull(callback, "callback is required");
template.singleResult(this.build(), callback);
}
@Override
public <T> Page<T> page(DocumentTemplate template, Pagination pagination) {
return null;
}
}