Skip to content

Commit 0f0289a

Browse files
committed
doc
1 parent 490b332 commit 0f0289a

30 files changed

+1400
-344
lines changed

astra-db-java/src/main/java/com/datastax/astra/client/Collection.java

Lines changed: 539 additions & 120 deletions
Large diffs are not rendered by default.

astra-db-java/src/main/java/com/datastax/astra/client/DataAPIClient.java

Lines changed: 328 additions & 50 deletions
Large diffs are not rendered by default.

astra-db-java/src/main/java/com/datastax/astra/client/model/DatabaseInfo.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package com.datastax.astra.client.model;
22

3+
/*-
4+
* #%L
5+
* Data API Java Client
6+
* --
7+
* Copyright (C) 2024 DataStax
8+
* --
9+
* Licensed under the Apache License, Version 2.0
10+
* You may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
323
import com.datastax.astra.internal.utils.Assert;
424
import com.dtsx.astra.sdk.db.domain.CloudProviderType;
525
import com.dtsx.astra.sdk.db.domain.Database;

astra-db-java/src/main/java/com/datastax/astra/client/model/FindOneOptions.java

Lines changed: 174 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import lombok.Getter;
2525

2626
import java.util.LinkedHashMap;
27+
import java.util.List;
2728
import java.util.Map;
2829

2930
/**
@@ -32,82 +33,205 @@
3233
@Getter
3334
public class FindOneOptions {
3435

35-
/**
36-
* Default constructor.
37-
*/
38-
public FindOneOptions() {
39-
}
40-
4136
/**
4237
* Order by.
4338
*/
44-
private Document sort;
39+
private final Document sort;
4540

4641
/**
4742
* Select.
4843
*/
49-
private Map<String, Integer> projection;
44+
private final Map<String, Integer> projection;
5045

5146
/**
5247
* Options.
5348
*/
54-
private Boolean includeSimilarity;
49+
private final Boolean includeSimilarity;
5550

5651
/**
57-
* Fluent api.
52+
* Create a builder for those options.
5853
*
5954
* @return
60-
* add a filter
55+
* instance of the builder.
6156
*/
62-
public FindOneOptions includeSimilarity() {
63-
includeSimilarity = true;
64-
return this;
57+
public static FindOneOptionsBuilder builder() {
58+
return new FindOneOptionsBuilder();
6559
}
6660

6761
/**
68-
* Fluent api.
69-
*
70-
* @param pProjection
71-
* add a project field
72-
* @return
73-
* current command.
62+
* Default constructor.
7463
*/
75-
public FindOneOptions projection(Map<String, Integer> pProjection) {
76-
Assert.notNull(pProjection, "projection");
77-
if (this.projection == null) {
78-
this.projection = new LinkedHashMap<>();
79-
}
80-
this.projection.putAll(pProjection);
81-
return this;
64+
public FindOneOptions(FindOneOptionsBuilder builder) {
65+
this.sort = builder.sort;
66+
this.projection = builder.projection;
67+
this.includeSimilarity = builder.includeSimilarity;
8268
}
8369

8470
/**
85-
* Fluent api.
86-
*
87-
* @param pSort
88-
* add a filter
89-
* @return
90-
* current command.
71+
* Find is an operation with multiple options to filter, sort, project, skip, limit, and more.
72+
* This builder will help to chain options.
9173
*/
92-
public FindOneOptions sort(Document pSort) {
93-
Assert.notNull(pSort, "projection");
94-
if (this.sort == null) {
95-
sort = new Document();
74+
public static class FindOneOptionsBuilder {
75+
76+
/**
77+
* Order by.
78+
*/
79+
private Document sort;
80+
81+
/**
82+
* Projection for return document (select)
83+
*/
84+
private Map<String, Integer> projection;
85+
86+
/**
87+
* Flag to include similarity in the result when operating a semantic search.
88+
*/
89+
private Boolean includeSimilarity;
90+
91+
/**
92+
* Default Builder.
93+
*/
94+
public FindOneOptionsBuilder() {}
95+
96+
/**
97+
* Fluent api.
98+
*
99+
* @return
100+
* add a filter
101+
*/
102+
public FindOneOptionsBuilder withIncludeSimilarity() {
103+
this.includeSimilarity = true;
104+
return this;
105+
}
106+
107+
/**
108+
* Provide a way to enter projections elements
109+
*
110+
* @param projections
111+
* projections as a list.
112+
* @return
113+
* self reference
114+
*/
115+
public FindOneOptionsBuilder withProjection(List<Projection> projections) {
116+
Assert.notNull(projections, "projection");
117+
if (this.projection == null) {
118+
this.projection = new LinkedHashMap<>();
119+
}
120+
for (Projection p : projections) {
121+
this.projection.put(p.getField(), p.isPresent() ? 1 : 0);
122+
}
123+
return this;
124+
}
125+
126+
/**
127+
* Fluent api.
128+
*
129+
* @param pProjection
130+
* add a project field
131+
* @return
132+
* current command.
133+
*/
134+
public FindOneOptionsBuilder withProjection(Map<String, Integer> pProjection) {
135+
Assert.notNull(pProjection, "projection");
136+
if (this.projection == null) {
137+
this.projection = new LinkedHashMap<>();
138+
}
139+
this.projection.putAll(pProjection);
140+
return this;
141+
}
142+
143+
/**
144+
* Add a criteria with $vectorize in the sort clause
145+
*
146+
* @param vectorize
147+
* an expression to look for vectorization
148+
* @return
149+
* current command
150+
*/
151+
public FindOneOptionsBuilder withVectorize(String vectorize) {
152+
Assert.hasLength(vectorize, "vectorize");
153+
return sortBy(new Document().append(Document.VECTORIZE, vectorize));
154+
}
155+
156+
/**
157+
* Add a criteria with $vector in the sort clause
158+
*
159+
* @param vector
160+
* vector float
161+
* @return
162+
* current command
163+
*/
164+
public FindOneOptionsBuilder withVector(float[] vector) {
165+
Assert.notNull(vector, "vector");
166+
return sortBy(new Document().append(Document.VECTOR, vector));
167+
}
168+
169+
/**
170+
* Fluent api.
171+
*
172+
* @param field
173+
* field name
174+
* @param order
175+
* orders
176+
* @return
177+
* Self reference
178+
*/
179+
public FindOneOptionsBuilder sortBy(String field, SortOrder order) {
180+
Assert.notNull(order, "order");
181+
Assert.hasLength(field, "field");
182+
if (this.sort == null) {
183+
sort = new Document();
184+
}
185+
this.sort.put(field, order.getOrder());
186+
return this;
187+
}
188+
189+
/**
190+
* Fluent api.
191+
*
192+
* @param sorts
193+
* list of sorts
194+
* @return
195+
* Self reference
196+
*/
197+
public FindOneOptionsBuilder sortBy(List<Sort> sorts) {
198+
Assert.notNull(sorts, "sort");
199+
if (this.sort == null) {
200+
sort = new Document();
201+
}
202+
for (Sort s : sorts) {
203+
this.sort.put(s.getField(), s.getSort().getOrder());
204+
}
205+
return this;
206+
}
207+
208+
/**
209+
* Fluent api.
210+
*
211+
* @param pSort
212+
* add a filter
213+
* @return
214+
* current command.
215+
*/
216+
public FindOneOptionsBuilder sortBy(Document pSort) {
217+
Assert.notNull(pSort, "sort");
218+
if (this.sort == null) {
219+
sort = new Document();
220+
}
221+
this.sort.putAll(pSort);
222+
return this;
223+
}
224+
225+
/**
226+
* Builder for the find Options.
227+
*
228+
* @return
229+
* the find options object
230+
*/
231+
public FindOneOptions build() {
232+
return new FindOneOptions(this);
96233
}
97-
this.sort.putAll(pSort);
98-
return this;
99-
}
100234

101-
/**
102-
* Add vector in the sort block.
103-
*
104-
* @param vector
105-
* vector float
106-
* @return
107-
* current command
108-
*/
109-
public FindOneOptions sortByVector(float[] vector) {
110-
return sort(new Document().append(Document.VECTOR, vector));
111235
}
112236

113237
}

0 commit comments

Comments
 (0)