Skip to content

Commit 947c726

Browse files
committed
Rethink the serialization with Json annotations
1 parent a16b33f commit 947c726

File tree

51 files changed

+1124
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1124
-352
lines changed

astra-db-java/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
<groupId>com.fasterxml.jackson.datatype</groupId>
5555
<artifactId>jackson-datatype-jsr310</artifactId>
5656
</dependency>
57+
<dependency>
58+
<groupId>com.fasterxml.jackson.datatype</groupId>
59+
<artifactId>jackson-datatype-jdk8</artifactId>
60+
</dependency>
5761

5862
<!-- TEST -->
5963
<dependency>

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class DataAPIOptions {
5050
public static final String DEFAULT_VERSION = "v1";
5151

5252
/** Number of documents for a count. */
53-
public static final int DEFAULT_MAX_DOCUMENTS_COUNT = 1000;
53+
public static final int DEFAULT_MAX_COUNT = 1000;
5454

5555
/** Maximum number of documents in a page. */
5656
public static final int DEFAULT_MAX_PAGE_SIZE = 20;
@@ -59,13 +59,13 @@ public class DataAPIOptions {
5959
public static final int DEFAULT_MAX_CHUNK_SIZE = 100;
6060

6161
/** When operating a count operation, the maximum number of documents that can be returned. */
62-
final int maxDocumentCount;
62+
final int maxRecordCount;
6363

6464
/** The maximum number of documents that can be returned in a single page. */
6565
final int maxPageSize;
6666

6767
/** The maximum number of documents that can be inserted in a single operation. */
68-
final int maxDocumentsInInsert;
68+
final int maxRecordsInInsert;
6969

7070
/** Set the API version like 'v1' */
7171
final String apiVersion;
@@ -105,14 +105,14 @@ public static DataAPIClientOptionsBuilder builder() {
105105
* current builder
106106
*/
107107
private DataAPIOptions(DataAPIClientOptionsBuilder builder) {
108-
this.apiVersion = builder.apiVersion;
109-
this.destination = builder.destination;
110-
this.maxDocumentCount = builder.maxDocumentCount;
111-
this.maxPageSize = builder.maxPageSize;
112-
this.maxDocumentsInInsert = builder.maxDocumentsInInsert;
113-
this.embeddingAuthProvider = builder.embeddingAuthProvider;
114-
this.httpClientOptions = builder.httpClientOptions;
115-
this.observers = builder.observers;
108+
this.apiVersion = builder.apiVersion;
109+
this.destination = builder.destination;
110+
this.maxRecordCount = builder.maxDocumentCount;
111+
this.maxPageSize = builder.maxPageSize;
112+
this.maxRecordsInInsert = builder.maxDocumentsInInsert;
113+
this.embeddingAuthProvider = builder.embeddingAuthProvider;
114+
this.httpClientOptions = builder.httpClientOptions;
115+
this.observers = builder.observers;
116116
this.databaseAdditionalHeaders = builder.databaseAdditionalHeaders;
117117
this.adminAdditionalHeaders = builder.adminAdditionalHeaders;
118118
}
@@ -126,7 +126,7 @@ public static class DataAPIClientOptionsBuilder {
126126
private String apiVersion = DEFAULT_VERSION;
127127

128128
/** When operating a count operation, the maximum number of documents that can be returned. */
129-
private int maxDocumentCount = DEFAULT_MAX_DOCUMENTS_COUNT;
129+
private int maxDocumentCount = DEFAULT_MAX_COUNT;
130130

131131
/** The maximum number of documents that can be returned in a single page. */
132132
private int maxPageSize = DEFAULT_MAX_PAGE_SIZE;
@@ -196,8 +196,8 @@ public DataAPIClientOptionsBuilder withMaxDocumentCount(int maxDocumentCount) {
196196
if (maxDocumentCount <= 0) {
197197
throw new IllegalArgumentException("Max document count must be a positive number");
198198
}
199-
if (maxDocumentCount > DEFAULT_MAX_DOCUMENTS_COUNT) {
200-
log.warn("Setting the maximum document count to a value greater than the default value of {} may impact performance.", DEFAULT_MAX_DOCUMENTS_COUNT);
199+
if (maxDocumentCount > DEFAULT_MAX_COUNT) {
200+
log.warn("Setting the maximum document count to a value greater than the default value of {} may impact performance.", DEFAULT_MAX_COUNT);
201201
}
202202
this.maxDocumentCount = maxDocumentCount;
203203
return this;

astra-db-java/src/main/java/com/datastax/astra/client/admin/DataAPIDatabaseAdmin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.datastax.astra.client.collections.commands.EmbeddingProvider;
2828
import com.datastax.astra.client.collections.commands.FindEmbeddingProvidersResult;
2929
import com.datastax.astra.client.keyspaces.KeyspaceOptions;
30-
import com.datastax.astra.internal.api.ApiResponse;
30+
import com.datastax.astra.internal.api.DataAPIResponse;
3131
import com.datastax.astra.internal.command.AbstractCommandRunner;
3232
import com.datastax.astra.internal.command.CommandObserver;
3333
import com.datastax.astra.internal.serdes.DataAPISerializer;
@@ -106,7 +106,7 @@ public Set<String> listKeyspaceNames() {
106106
/** {@inheritDoc} */
107107
@Override
108108
public FindEmbeddingProvidersResult findEmbeddingProviders() {
109-
ApiResponse res = runCommand(Command.create("findEmbeddingProviders"));
109+
DataAPIResponse res = runCommand(Command.create("findEmbeddingProviders"));
110110
return new FindEmbeddingProvidersResult(
111111
res.getStatusKeyAsMap("embeddingProviders",
112112
EmbeddingProvider.class));

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@
5555
import com.datastax.astra.client.core.types.UUIDv6;
5656
import com.datastax.astra.client.core.types.UUIDv7;
5757
import com.datastax.astra.client.databases.Database;
58-
import com.datastax.astra.client.exception.DataAPIFaultyResponseException;
58+
import com.datastax.astra.client.exception.UnexpectedDataAPIResponseException;
5959
import com.datastax.astra.client.exception.DataAPIException;
60-
import com.datastax.astra.client.exception.TooManyDocumentsToCountException;
61-
import com.datastax.astra.internal.api.ApiResponse;
60+
import com.datastax.astra.client.collections.exceptions.TooManyDocumentsToCountException;
61+
import com.datastax.astra.internal.api.DataAPIResponse;
62+
import com.datastax.astra.internal.api.DataAPIStatus;
6263
import com.datastax.astra.internal.command.AbstractCommandRunner;
6364
import com.datastax.astra.internal.command.CommandObserver;
6465
import com.datastax.astra.internal.serdes.DataAPISerializer;
@@ -632,8 +633,8 @@ public InsertManyResult insertMany(List<? extends T> documents, InsertManyOption
632633
if (options.getConcurrency() > 1 && options.isOrdered()) {
633634
throw new IllegalArgumentException("Cannot run ordered insert_many concurrently.");
634635
}
635-
if (options.getChunkSize() > dataAPIOptions.getMaxDocumentsInInsert()) {
636-
throw new IllegalArgumentException("Cannot insert more than " + dataAPIOptions.getMaxDocumentsInInsert() + " at a time.");
636+
if (options.getChunkSize() > dataAPIOptions.getMaxRecordsInInsert()) {
637+
throw new IllegalArgumentException("Cannot insert more than " + dataAPIOptions.getMaxRecordsInInsert() + " at a time.");
637638
}
638639
long start = System.currentTimeMillis();
639640
ExecutorService executor = Executors.newFixedThreadPool(options.getConcurrency());
@@ -1175,7 +1176,7 @@ public Page<T> findPage(Filter filter, FindOptions options) {
11751176
.appendIfNotNull(INPUT_PAGE_STATE, options.getPageState())
11761177
.appendIfNotNull(INPUT_INCLUDE_SORT_VECTOR, options.getIncludeSortVector())
11771178
.appendIfNotNull(INPUT_INCLUDE_SIMILARITY, options.getIncludeSimilarity()));
1178-
ApiResponse apiResponse = runCommand(findCommand, options);
1179+
DataAPIResponse apiResponse = runCommand(findCommand, options);
11791180

11801181
// load sortVector if available
11811182
float[] sortVector = null;
@@ -1313,7 +1314,7 @@ public long estimatedDocumentCount() {
13131314
public long estimatedDocumentCount(EstimatedCountDocumentsOptions options) {
13141315
Command command = new Command("estimatedDocumentCount");
13151316
// Run command
1316-
ApiResponse response = runCommand(command, options);
1317+
DataAPIResponse response = runCommand(command, options);
13171318
// Build Result
13181319
return response.getStatus().getInteger(RESULT_COUNT);
13191320
}
@@ -1348,13 +1349,13 @@ public long estimatedDocumentCount(EstimatedCountDocumentsOptions options) {
13481349
public int countDocuments(Filter filter, int upperBound, CountDocumentsOptions options)
13491350
throws TooManyDocumentsToCountException {
13501351
// Argument Validation
1351-
if (upperBound<1 || upperBound> dataAPIOptions.getMaxDocumentCount()) {
1352-
throw new IllegalArgumentException("UpperBound limit should be in between 1 and " + dataAPIOptions.getMaxDocumentCount());
1352+
if (upperBound<1 || upperBound> dataAPIOptions.getMaxRecordCount()) {
1353+
throw new IllegalArgumentException("UpperBound limit should be in between 1 and " + dataAPIOptions.getMaxRecordCount());
13531354
}
13541355
// Build command
13551356
Command command = new Command("countDocuments").withFilter(filter);
13561357
// Run command
1357-
ApiResponse response = runCommand(command, options);
1358+
DataAPIResponse response = runCommand(command, options);
13581359
// Build Result
13591360
Boolean moreData = response.getStatus().getBoolean(RESULT_MORE_DATA);
13601361
Integer count = response.getStatus().getInteger(RESULT_COUNT);
@@ -1418,7 +1419,7 @@ public DeleteResult deleteOne(Filter filter, DeleteOneOptions deleteOneOptions)
14181419
.withFilter(filter)
14191420
.withSort(deleteOneOptions.getSort());
14201421

1421-
ApiResponse apiResponse = runCommand(deleteOne, deleteOneOptions);
1422+
DataAPIResponse apiResponse = runCommand(deleteOne, deleteOneOptions);
14221423
int deletedCount = apiResponse.getStatus().getInteger(RESULT_DELETED_COUNT);
14231424
return new DeleteResult(deletedCount);
14241425
}
@@ -1441,8 +1442,8 @@ public DeleteResult deleteMany(Filter filter, DeleteManyOptions options) {
14411442
.create("deleteMany")
14421443
.withFilter(filter);
14431444

1444-
ApiResponse apiResponse = runCommand(deleteMany, options);
1445-
Document status = apiResponse.getStatus();
1445+
DataAPIResponse apiResponse = runCommand(deleteMany, options);
1446+
DataAPIStatus status = apiResponse.getStatus();
14461447
if (status != null) {
14471448
if (status.containsKey(RESULT_DELETED_COUNT)) {
14481449
totalCount.addAndGet(status.getInteger(RESULT_DELETED_COUNT));
@@ -1542,7 +1543,7 @@ public Optional<T> findOneAndReplace(Filter filter, T replacement, FindOneAndRep
15421543
.appendIfNotNull(INPUT_RETURN_DOCUMENT, options.getReturnDocument())
15431544
);
15441545

1545-
ApiResponse res = runCommand(findOneAndReplace, options);
1546+
DataAPIResponse res = runCommand(findOneAndReplace, options);
15461547
if (res.getData()!= null && res.getData().getDocument() != null) {
15471548
return Optional.ofNullable(res
15481549
.getData()
@@ -1616,19 +1617,19 @@ public UpdateResult replaceOne(Filter filter, T replacement, ReplaceOneOptions r
16161617
*/
16171618
private FindOneAndReplaceResult<T> executeFindOneAndReplace(Command cmd, CommandOptions<?> options) {
16181619
// Run Command
1619-
ApiResponse apiResponse = runCommand(cmd, options);
1620+
DataAPIResponse apiResponse = runCommand(cmd, options);
16201621
// Parse Command Result
16211622
FindOneAndReplaceResult<T> result = new FindOneAndReplaceResult<>();
16221623
if (apiResponse.getData() == null) {
1623-
throw new DataAPIFaultyResponseException(cmd, apiResponse,"Faulty response from find_one_and_replace API command.");
1624+
throw new UnexpectedDataAPIResponseException(cmd, apiResponse,"Faulty response from find_one_and_replace API command.");
16241625
}
16251626
if (apiResponse.getData().getDocument() != null) {
16261627
result.setDocument(apiResponse
16271628
.getData()
16281629
.getDocument()
16291630
.map(getDocumentClass()));
16301631
}
1631-
Document status = apiResponse.getStatus();
1632+
DataAPIStatus status = apiResponse.getStatus();
16321633
if (status != null) {
16331634
if (status.containsKey(RESULT_MATCHED_COUNT)) {
16341635
result.setMatchedCount(status.getInteger(RESULT_MATCHED_COUNT));
@@ -1684,7 +1685,7 @@ public Optional<T> findOneAndUpdate(Filter filter, Update update, FindOneAndUpda
16841685
.append(INPUT_RETURN_DOCUMENT, options.getReturnDocument())
16851686
);
16861687

1687-
ApiResponse res = runCommand(cmd, options);
1688+
DataAPIResponse res = runCommand(cmd, options);
16881689
if (res.getData()!= null && res.getData().getDocument() != null) {
16891690
return Optional.ofNullable(res
16901691
.getData()
@@ -1742,9 +1743,9 @@ public UpdateResult updateOne(Filter filter, Update update, UpdateOneOptions upd
17421743
* @return
17431744
* the result of the update many operation
17441745
*/
1745-
private static UpdateResult getUpdateResult(ApiResponse apiResponse) {
1746+
private static UpdateResult getUpdateResult(DataAPIResponse apiResponse) {
17461747
UpdateResult result = new UpdateResult();
1747-
Document status = apiResponse.getStatus();
1748+
DataAPIStatus status = apiResponse.getStatus();
17481749
if (status != null) {
17491750
if (status.containsKey(RESULT_MATCHED_COUNT)) {
17501751
result.setMatchedCount(status.getInteger(RESULT_MATCHED_COUNT));
@@ -1800,13 +1801,13 @@ public UpdateResult updateMany(Filter filter, Update update, UpdateManyOptions o
18001801
.withOptions(new Document()
18011802
.appendIfNotNull(INPUT_UPSERT, options.getUpsert())
18021803
.appendIfNotNull(INPUT_PAGE_STATE, nextPageState));
1803-
ApiResponse res = runCommand(cmd, options);
1804+
DataAPIResponse res = runCommand(cmd, options);
18041805
// Data
18051806
if (res.getData() != null) {
18061807
nextPageState = res.getData().getNextPageState();
18071808
}
18081809
// Status
1809-
Document status = res.getStatus();
1810+
DataAPIStatus status = res.getStatus();
18101811
if (status.containsKey(RESULT_MATCHED_COUNT)) {
18111812
result.setMatchedCount(result.getMatchedCount() + status.getInteger(RESULT_MATCHED_COUNT));
18121813
}
@@ -1861,7 +1862,7 @@ public Optional<T> findOneAndDelete(Filter filter, FindOneAndDeleteOptions optio
18611862
.withSort(options.getSort())
18621863
.withProjection(options.getProjection());
18631864

1864-
ApiResponse res = runCommand(findOneAndReplace, options);
1865+
DataAPIResponse res = runCommand(findOneAndReplace, options);
18651866
if (res.getData()!= null && res.getData().getDocument() != null) {
18661867
return Optional.ofNullable(res
18671868
.getData()

astra-db-java/src/main/java/com/datastax/astra/client/collections/commands/InsertManyOptions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.datastax.astra.client.DataAPIOptions;
2424
import com.datastax.astra.client.core.commands.CommandOptions;
25+
import com.datastax.astra.client.core.http.HttpClientOptions;
2526
import lombok.Getter;
2627

2728
/**
@@ -48,13 +49,15 @@ public class InsertManyOptions extends CommandOptions<InsertManyOptions> {
4849
/**
4950
* If the flag is set to true the command is failing on first error
5051
*/
51-
private long timeout = httpClientOptions.getRequestTimeout().getSeconds();
52+
private long timeout;
5253

5354
/**
5455
* Populate insertMany options
5556
*/
5657
public InsertManyOptions() {
5758
// left blank, jackson serialization
59+
this.httpClientOptions = new HttpClientOptions();
60+
this.timeout = httpClientOptions.getRequestTimeout().getSeconds();
5861
}
5962

6063
/**

0 commit comments

Comments
 (0)