Skip to content

Commit 32cbe4b

Browse files
authored
JAVA-6168 JAVA-6244 JAVA-6196: QE prefix/suffix/substring GA + rename Text API to String (#2010) bump libmongocrypt 1.20
1 parent 6612f5d commit 32cbe4b

15 files changed

Lines changed: 917 additions & 364 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ driver-benchmarks/.factorypath
6868
# bin build directories
6969
**/bin
7070

71+
docs/superpowers/

driver-core/src/main/com/mongodb/client/model/vault/EncryptOptions.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class EncryptOptions {
3434
private String queryType;
3535
private RangeOptions rangeOptions;
3636
private TextOptions textOptions;
37+
private StringOptions stringOptions;
3738

3839
/**
3940
* Construct an instance with the given algorithm.
@@ -54,12 +55,12 @@ public EncryptOptions(final String algorithm) {
5455
* <li>Indexed</li>
5556
* <li>Unindexed</li>
5657
* <li>Range</li>
57-
* <li>TextPreview</li>
58+
* <li>String</li>
5859
* </ul>
5960
*
60-
* <p>The "TextPreview" algorithm is in preview and should be used for experimental workloads only.
61-
* These features are unstable and their security is not guaranteed until released as Generally Available (GA).
62-
* The GA version of these features may not be backwards compatible with the preview version.</p>
61+
* <p>The "String" algorithm supports Queryable Encryption prefix, suffix, and substring string queries.
62+
* Use the "String" algorithm with query types "prefix"/"suffix"/"substring" (server 9.0+) or the deprecated
63+
* aliases "prefixPreview"/"suffixPreview"/"substringPreview" (server 8.2 to pre-9.0).</p>
6364
*
6465
* @return the encryption algorithm
6566
*/
@@ -149,8 +150,12 @@ public Long getContentionFactor() {
149150
/**
150151
* The QueryType.
151152
*
152-
* <p>Currently, we support only "equality", "range", "prefixPreview", "suffixPreview" or "substringPreview" queryType.</p>
153-
* <p>It is an error to set queryType when the algorithm is not "Indexed", "Range" or "TextPreview".</p>
153+
* <p>Currently, we support only "equality", "range", "prefix", "suffix", "substring", "prefixPreview",
154+
* "suffixPreview" or "substringPreview" queryType.</p>
155+
* <p>The "prefix", "suffix", "substring", "prefixPreview", "suffixPreview" and "substringPreview" query types are
156+
* only valid with the "String" algorithm. "prefixPreview"/"suffixPreview"/"substringPreview" are deprecated
157+
* aliases supported for servers 8.2 to pre-9.0; use "prefix"/"suffix"/"substring" on server 9.0+.</p>
158+
* <p>It is an error to set queryType when the algorithm is not "Indexed", "Range" or "String".</p>
154159
* @param queryType the query type
155160
* @return this
156161
* @since 4.7
@@ -164,7 +169,7 @@ public EncryptOptions queryType(@Nullable final String queryType) {
164169
/**
165170
* Gets the QueryType.
166171
*
167-
* <p>Currently, we support only "equality" or "range" queryType.</p>
172+
* <p>See {@link #queryType(String)} for the supported query types.</p>
168173
* @see #queryType(String)
169174
* @return the queryType or null
170175
* @since 4.7
@@ -205,13 +210,15 @@ public RangeOptions getRangeOptions() {
205210
/**
206211
* The TextOptions
207212
*
208-
* <p>It is an error to set TextOptions when the algorithm is not "TextPreview".
213+
* <p>It is an error to set TextOptions when the algorithm is not "String".
209214
* @param textOptions the text options
210215
* @return this
211216
* @since 5.6
212217
* @mongodb.server.release 8.2
213218
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
219+
* @deprecated Use {@link #stringOptions(StringOptions)} instead.
214220
*/
221+
@Deprecated
215222
@Alpha(Reason.SERVER)
216223
public EncryptOptions textOptions(@Nullable final TextOptions textOptions) {
217224
this.textOptions = textOptions;
@@ -225,13 +232,43 @@ public EncryptOptions textOptions(@Nullable final TextOptions textOptions) {
225232
* @since 5.6
226233
* @mongodb.server.release 8.2
227234
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
235+
* @deprecated Use {@link #getStringOptions()} instead.
228236
*/
237+
@Deprecated
229238
@Alpha(Reason.SERVER)
230239
@Nullable
231240
public TextOptions getTextOptions() {
232241
return textOptions;
233242
}
234243

244+
/**
245+
* The StringOptions
246+
*
247+
* <p>It is an error to set StringOptions when the algorithm is not "String".
248+
* @param stringOptions the string options
249+
* @return this
250+
* @since 5.9
251+
* @mongodb.server.release 8.2
252+
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
253+
*/
254+
public EncryptOptions stringOptions(@Nullable final StringOptions stringOptions) {
255+
this.stringOptions = stringOptions;
256+
return this;
257+
}
258+
259+
/**
260+
* Gets the StringOptions
261+
* @see #stringOptions(StringOptions)
262+
* @return the string options or null if not set
263+
* @since 5.9
264+
* @mongodb.server.release 8.2
265+
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
266+
*/
267+
@Nullable
268+
public StringOptions getStringOptions() {
269+
return stringOptions;
270+
}
271+
235272
@Override
236273
public String toString() {
237274
return "EncryptOptions{"
@@ -241,6 +278,8 @@ public String toString() {
241278
+ ", contentionFactor=" + contentionFactor
242279
+ ", queryType='" + queryType + '\''
243280
+ ", rangeOptions=" + rangeOptions
281+
+ ", textOptions=" + textOptions
282+
+ ", stringOptions=" + stringOptions
244283
+ '}';
245284
}
246285
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mongodb.client.model.vault;
18+
19+
import com.mongodb.lang.Nullable;
20+
import org.bson.BsonDocument;
21+
22+
/**
23+
* String options for a Queryable Encryption field that supports string queries (prefix, suffix, and substring).
24+
*
25+
* @since 5.9
26+
* @mongodb.server.release 8.2
27+
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
28+
*/
29+
public class StringOptions {
30+
private boolean caseSensitive;
31+
private boolean diacriticSensitive;
32+
@Nullable
33+
private BsonDocument prefixOptions;
34+
@Nullable
35+
private BsonDocument suffixOptions;
36+
@Nullable
37+
private BsonDocument substringOptions;
38+
39+
/**
40+
* Construct a new instance
41+
*/
42+
public StringOptions() {
43+
}
44+
45+
/**
46+
* @return true if string indexes for this field are case sensitive.
47+
*/
48+
public boolean getCaseSensitive() {
49+
return caseSensitive;
50+
}
51+
52+
/**
53+
* Set case sensitivity
54+
*
55+
* @param caseSensitive true if string indexes are case sensitive
56+
* @return this
57+
*/
58+
public StringOptions caseSensitive(final boolean caseSensitive) {
59+
this.caseSensitive = caseSensitive;
60+
return this;
61+
}
62+
63+
/**
64+
* @return true if string indexes are diacritic sensitive
65+
*/
66+
public boolean getDiacriticSensitive() {
67+
return diacriticSensitive;
68+
}
69+
70+
/**
71+
* Set diacritic sensitivity
72+
*
73+
* @param diacriticSensitive true if string indexes are diacritic sensitive
74+
* @return this
75+
*/
76+
public StringOptions diacriticSensitive(final boolean diacriticSensitive) {
77+
this.diacriticSensitive = diacriticSensitive;
78+
return this;
79+
}
80+
81+
/**
82+
* Set the prefix options.
83+
*
84+
* <p>Expected to be a {@link BsonDocument} in the format of:</p>
85+
*
86+
* <pre>
87+
* {@code
88+
* {
89+
* // strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error.
90+
* strMinQueryLength: BsonInt32,
91+
* // strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error.
92+
* strMaxQueryLength: BsonInt32
93+
* }
94+
* }
95+
* </pre>
96+
*
97+
* @param prefixOptions the prefix options or null
98+
* @return this
99+
*/
100+
public StringOptions prefixOptions(@Nullable final BsonDocument prefixOptions) {
101+
this.prefixOptions = prefixOptions;
102+
return this;
103+
}
104+
105+
/**
106+
* @see #prefixOptions(BsonDocument)
107+
* @return the prefix options document or null
108+
*/
109+
@Nullable
110+
public BsonDocument getPrefixOptions() {
111+
return prefixOptions;
112+
}
113+
114+
/**
115+
* Set the suffix options.
116+
*
117+
* <p>Expected to be a {@link BsonDocument} in the format of:</p>
118+
*
119+
* <pre>
120+
* {@code
121+
* {
122+
* // strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error.
123+
* strMinQueryLength: BsonInt32,
124+
* // strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error.
125+
* strMaxQueryLength: BsonInt32
126+
* }
127+
* }
128+
* </pre>
129+
*
130+
* @param suffixOptions the suffix options or null
131+
* @return this
132+
*/
133+
public StringOptions suffixOptions(@Nullable final BsonDocument suffixOptions) {
134+
this.suffixOptions = suffixOptions;
135+
return this;
136+
}
137+
138+
/**
139+
* @see #suffixOptions(BsonDocument)
140+
* @return the suffix options document or null
141+
*/
142+
@Nullable
143+
public BsonDocument getSuffixOptions() {
144+
return suffixOptions;
145+
}
146+
147+
/**
148+
* Set the substring options.
149+
*
150+
* <p>Expected to be a {@link BsonDocument} in the format of:</p>
151+
*
152+
* <pre>
153+
* {@code
154+
* {
155+
* // strMaxLength is the maximum allowed length to insert. Inserting longer strings will error.
156+
* strMaxLength: BsonInt32,
157+
* // strMinQueryLength is the minimum allowed query length. Querying with a shorter string will error.
158+
* strMinQueryLength: BsonInt32,
159+
* // strMaxQueryLength is the maximum allowed query length. Querying with a longer string will error.
160+
* strMaxQueryLength: BsonInt32
161+
* }
162+
* }
163+
* </pre>
164+
*
165+
* @param substringOptions the substring options or null
166+
* @return this
167+
*/
168+
public StringOptions substringOptions(@Nullable final BsonDocument substringOptions) {
169+
this.substringOptions = substringOptions;
170+
return this;
171+
}
172+
173+
/**
174+
* @see #substringOptions(BsonDocument)
175+
* @return the substring options document or null
176+
*/
177+
@Nullable
178+
public BsonDocument getSubstringOptions() {
179+
return substringOptions;
180+
}
181+
182+
@Override
183+
public String toString() {
184+
return "StringOptions{"
185+
+ "caseSensitive=" + caseSensitive
186+
+ ", diacriticSensitive=" + diacriticSensitive
187+
+ ", prefixOptions=" + prefixOptions
188+
+ ", suffixOptions=" + suffixOptions
189+
+ ", substringOptions=" + substringOptions
190+
+ '}';
191+
}
192+
}

driver-core/src/main/com/mongodb/client/model/vault/TextOptions.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
* @since 5.6
3030
* @mongodb.server.release 8.2
3131
* @mongodb.driver.manual /core/queryable-encryption/ queryable encryption
32+
* @deprecated Use {@link StringOptions} instead.
3233
*/
34+
@Deprecated
3335
@Alpha(Reason.SERVER)
3436
public class TextOptions {
35-
private Boolean caseSensitive;
36-
private Boolean diacriticSensitive;
37+
private boolean caseSensitive;
38+
private boolean diacriticSensitive;
3739
@Nullable
3840
private BsonDocument prefixOptions;
3941
@Nullable
@@ -184,4 +186,14 @@ public BsonDocument getSubstringOptions() {
184186
return substringOptions;
185187
}
186188

189+
@Override
190+
public String toString() {
191+
return "TextOptions{"
192+
+ "caseSensitive=" + caseSensitive
193+
+ ", diacriticSensitive=" + diacriticSensitive
194+
+ ", prefixOptions=" + prefixOptions
195+
+ ", suffixOptions=" + suffixOptions
196+
+ ", substringOptions=" + substringOptions
197+
+ '}';
198+
}
187199
}

0 commit comments

Comments
 (0)