23
23
import com .datastax .astra .internal .utils .Assert ;
24
24
import lombok .Getter ;
25
25
import lombok .Setter ;
26
+ import lombok .extern .slf4j .Slf4j ;
26
27
27
28
import java .net .http .HttpClient ;
28
29
29
30
/**
30
31
* Options to set up the client for DataApiClient.
31
32
*/
33
+ @ Slf4j
32
34
@ Getter
33
35
public class DataAPIOptions {
34
36
35
37
/** Number of documents for a count. */
36
- static final int MAX_DOCUMENTS_COUNT = 1000 ;
38
+ public static final int DEFAULT_MAX_DOCUMENTS_COUNT = 1000 ;
37
39
38
40
/** Maximum number of documents in a page. */
39
- static final int MAX_PAGE_SIZE = 20 ;
41
+ public static final int DEFAULT_MAX_PAGE_SIZE = 20 ;
40
42
41
43
/** Maximum number of documents when you insert. */
42
- static final int MAX_DOCUMENTS_IN_INSERT = 20 ;
44
+ public static final int DEFAULT_MAX_CHUNKSIZE = 20 ;
43
45
44
46
/** Default user agent. */
45
47
public static final String DEFAULT_CALLER_NAME = "astra-db-java" ;
@@ -73,6 +75,15 @@ public class DataAPIOptions {
73
75
/** Set the API version like 'v1' */
74
76
final String apiVersion ;
75
77
78
+ /** When operating a count operation, the maximum number of documents that can be returned. */
79
+ final int maxDocumentCount ;
80
+
81
+ /** The maximum number of documents that can be returned in a single page. */
82
+ final int maxPageSize ;
83
+
84
+ /** The maximum number of documents that can be inserted in a single operation. */
85
+ final int maxDocumentsInInsert ;
86
+
76
87
/**
77
88
* Initializer for the builder.
78
89
*
@@ -90,9 +101,12 @@ public static DataAPIClientOptionsBuilder builder() {
90
101
* current builder
91
102
*/
92
103
private DataAPIOptions (DataAPIClientOptionsBuilder builder ) {
93
- this .apiVersion = builder .apiVersion ;
94
- this .destination = builder .destination ;
95
- this .httpClientOptions = new HttpClientOptions ();
104
+ this .apiVersion = builder .apiVersion ;
105
+ this .destination = builder .destination ;
106
+ this .maxDocumentCount = builder .maxDocumentCount ;
107
+ this .maxPageSize = builder .maxPageSize ;
108
+ this .maxDocumentsInInsert = builder .maxDocumentsInInsert ;
109
+ this .httpClientOptions = new HttpClientOptions ();
96
110
httpClientOptions .setHttpVersion (builder .httpVersion );
97
111
httpClientOptions .setHttpRedirect (builder .httpRedirect );
98
112
httpClientOptions .setRetryCount (builder .retryCount );
@@ -263,6 +277,15 @@ public static class DataAPIClientOptionsBuilder {
263
277
/** Default is to use Astra in Production. */
264
278
private DataAPIDestination destination = DataAPIDestination .ASTRA ;
265
279
280
+ /** When operating a count operation, the maximum number of documents that can be returned. */
281
+ private int maxDocumentCount = DEFAULT_MAX_DOCUMENTS_COUNT ;
282
+
283
+ /** The maximum number of documents that can be returned in a single page. */
284
+ private int maxPageSize = DEFAULT_MAX_PAGE_SIZE ;
285
+
286
+ /** The maximum number of documents that can be inserted in a single operation. */
287
+ private int maxDocumentsInInsert = DEFAULT_MAX_CHUNKSIZE ;
288
+
266
289
/**
267
290
* Default constructor.
268
291
*/
@@ -425,6 +448,98 @@ public DataAPIClientOptionsBuilder withHttpRetryDelayMillis(int retryDelay) {
425
448
return this ;
426
449
}
427
450
451
+ /**
452
+ * Sets the maximum number of documents that can be returned by the count function.
453
+ * <p>
454
+ * If not explicitly set, the default value is defined by {@code MAX_DOCUMENTS_COUNT},
455
+ * which is 1000 documents.
456
+ * </p>
457
+ *
458
+ * @param maxDocumentCount the maximum number of documents that can be returned by the count function.
459
+ * Must be a positive number.
460
+ * @return a reference to this builder, allowing for method chaining.
461
+ *
462
+ * Example usage:
463
+ * <pre>
464
+ * {@code
465
+ * DataAPIClientOptions
466
+ * .builder()
467
+ * .withMaxDocumentCount(2000); // Sets the maximum number of documents to 2000.
468
+ * }</pre>
469
+ */
470
+ public DataAPIClientOptionsBuilder withMaxDocumentCount (int maxDocumentCount ) {
471
+ if (maxDocumentCount <= 0 ) {
472
+ throw new IllegalArgumentException ("Max document count must be a positive number" );
473
+ }
474
+ if (maxDocumentCount > DEFAULT_MAX_DOCUMENTS_COUNT ) {
475
+ log .warn ("Setting the maximum document count to a value greater than the default value of {} may impact performance." , DEFAULT_MAX_DOCUMENTS_COUNT );
476
+ }
477
+ this .maxDocumentCount = maxDocumentCount ;
478
+ return this ;
479
+ }
480
+
481
+ /**
482
+ * Sets the maximum number of documents that can be returned in a single page.
483
+ * <p>
484
+ * If not explicitly set, the default value is defined by {@code MAX_PAGE_SIZE},
485
+ * which is 20 documents.
486
+ * </p>
487
+ *
488
+ * @param maxPageSize the maximum number of documents that can be returned in a single page.
489
+ * Must be a positive number.
490
+ * @return a reference to this builder, allowing for method chaining.
491
+ *
492
+ * Example usage:
493
+ * <pre>
494
+ * {@code
495
+ * DataAPIClientOptions
496
+ * .builder()
497
+ * .withMaxPageSize(50); // Sets the maximum page size to 50 documents.
498
+ * }</pre>
499
+ */
500
+ public DataAPIClientOptionsBuilder withMaxPageSize (int maxPageSize ) {
501
+ if (maxPageSize <= 0 ) {
502
+ throw new IllegalArgumentException ("Max page size must be a positive number" );
503
+ }
504
+ if (maxPageSize > DEFAULT_MAX_PAGE_SIZE ) {
505
+ log .warn ("Setting the maximum page size to a value greater than the " +
506
+ "default value of {} may impact performance or result in error at server level" , DEFAULT_MAX_PAGE_SIZE );
507
+ }
508
+ this .maxPageSize = maxPageSize ;
509
+ return this ;
510
+ }
511
+
512
+ /**
513
+ * Sets the maximum number of documents that can be inserted in a single operation.
514
+ * <p>
515
+ * If not explicitly set, the default value is defined by {@code MAX_DOCUMENTS_IN_INSERT},
516
+ * which is 20 documents.
517
+ * </p>
518
+ *
519
+ * @param maxDocumentsInInsert the maximum number of documents that can be inserted in a single operation.
520
+ * Must be a positive number.
521
+ * @return a reference to this builder, allowing for method chaining.
522
+ *
523
+ * Example usage:
524
+ * <pre>
525
+ * {@code
526
+ * DataAPIClientOptions
527
+ * .builder()
528
+ * .withMaxDocumentsInInsert(50); // Sets the maximum number of documents to insert to 50.
529
+ * }</pre>
530
+ */
531
+ public DataAPIClientOptionsBuilder withMaxDocumentsInInsert (int maxDocumentsInInsert ) {
532
+ if (maxDocumentsInInsert <= 0 ) {
533
+ throw new IllegalArgumentException ("Max documents in insert must be a positive number" );
534
+ }
535
+ if (maxDocumentsInInsert > DEFAULT_MAX_CHUNKSIZE ) {
536
+ log .warn ("Setting the maximum number of documents in insert to a value greater than the " +
537
+ "default value of {} may impact performance or result in error at server level" , DEFAULT_MAX_CHUNKSIZE );
538
+ }
539
+ this .maxDocumentsInInsert = maxDocumentsInInsert ;
540
+ return this ;
541
+ }
542
+
428
543
/**
429
544
* Build the options.
430
545
*
@@ -434,38 +549,6 @@ public DataAPIClientOptionsBuilder withHttpRetryDelayMillis(int retryDelay) {
434
549
public DataAPIOptions build () {
435
550
return new DataAPIOptions (this );
436
551
}
437
-
438
- }
439
-
440
-
441
- /**
442
- * Retrieve the maximum number of documents that the count function can return.
443
- *
444
- * @return
445
- * maximum number of document returned
446
- */
447
- public static int getMaxDocumentCount () {
448
- return MAX_DOCUMENTS_COUNT ;
449
- }
450
-
451
- /**
452
- * Retrieve the maximum number of documents for a page and also the maximum you can set for a limit.
453
- *
454
- * @return
455
- * maximum page size.
456
- */
457
- public static int getMaxPageSize () {
458
- return MAX_PAGE_SIZE ;
459
- }
460
-
461
- /**
462
- * Retrieve the maximum number of documents allows for a insertMany() below this point the list is split and chunked are processed in parallel.
463
- *
464
- * @return
465
- * maximum page size.
466
- */
467
- public static int getMaxDocumentsInInsert () {
468
- return MAX_DOCUMENTS_IN_INSERT ;
469
552
}
470
553
471
554
}
0 commit comments