Skip to content

Commit 74c6d69

Browse files
committed
Update JavaDocs
1 parent f47cc1d commit 74c6d69

17 files changed

+525
-193
lines changed

src/main/java/com/datastax/astra/client/AstraDBAdmin.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
/**
5555
* Main Client for AstraDB, it implements administration and Data Api Operations.
56-
5756
*/
5857
@Slf4j
5958
public class AstraDBAdmin {
@@ -100,12 +99,14 @@ public class AstraDBAdmin {
10099
}
101100

102101
/**
103-
* Initialization with an authentification token and target environment, Use this constructor for testing purpose.
102+
* Initialization with an authentication token and target environment, Use this constructor for testing purpose.
104103
*
105104
* @param token
106105
* authentication token
107106
* @param options
108107
* options for client
108+
* @param env
109+
* astra environment
109110
*/
110111
AstraDBAdmin(String token, AstraEnvironment env, DataAPIOptions options) {
111112
Assert.hasLength(token, "token");
@@ -198,6 +199,8 @@ public UUID createDatabase(String name) {
198199
* cloud provider
199200
* @param cloudRegion
200201
* cloud region
202+
* @param waitForDb
203+
* if set to true, the method is blocking
201204
* @return
202205
* database identifier
203206
*/
@@ -266,7 +269,7 @@ public UUID createDatabase(String name, CloudProviderType cloud, String cloudReg
266269
}
267270

268271
/**
269-
* Delete a Database if exists from its name
272+
* Delete a Database if exists from its identifier.
270273
*
271274
* @param databaseId
272275
* database identifier
@@ -281,6 +284,14 @@ public boolean dropDatabase(@NonNull UUID databaseId) {
281284
return exists;
282285
}
283286

287+
/**
288+
* Delete a Database if exists from its name.
289+
*
290+
* @param databaseName
291+
* database name
292+
* @return
293+
* if the database has been deleted
294+
*/
284295
public boolean dropDatabase(@NonNull String databaseName) {
285296
Assert.hasLength(databaseName, "database");
286297
com.datastax.astra.internal.utils.Assert.hasLength(databaseName, "Database ");
@@ -293,12 +304,12 @@ public boolean dropDatabase(@NonNull String databaseName) {
293304
}
294305

295306
/**
296-
* Find a database from its id.
307+
* Find database information from its id.
297308
*
298309
* @param id
299-
* a database name
310+
* database identifier
300311
* @return
301-
* list of db matching the criteria
312+
* the bean representing an Astra database
302313
*/
303314
public Database getDatabaseInformations(@NonNull UUID id) {
304315
Assert.notNull(id, "Database identifier should not be null");
@@ -315,6 +326,8 @@ public Database getDatabaseInformations(@NonNull UUID id) {
315326
*
316327
* @param databaseId
317328
* database identifier
329+
* @param namespace
330+
* target namespace name
318331
* @return
319332
* database client
320333
*/

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

Lines changed: 73 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@
8585
* (endpoint, authentication). A Collection has a name, which is its unique identifier for a namespace and
8686
* options to specialize the usage as vector collections or advanced indexing parameters.
8787
* </p>
88-
*
8988
* <p>
9089
* A Collection is typed object designed to work both with default @{@link com.datastax.astra.client.model.Document} (wrapper for a Map) and application
9190
* plain old java objects (pojo). The serialization is performed with Jackson and application beans can be annotated.
9291
* </p>
93-
*
9492
* <p>Example usage:</p>
9593
* <pre>
9694
* {@code
@@ -119,6 +117,7 @@ public class Collection<DOC> extends AbstractCommandRunner {
119117
protected final Class<DOC> documentClass;
120118

121119
/** keep reference to namespace client. */
120+
@Getter
122121
private final Database database;
123122

124123
/** Api Endpoint for the Database. */
@@ -143,35 +142,20 @@ protected Collection(Database db, String collectionName, Class<DOC> clazz) {
143142
}
144143

145144
// ----------------------------
146-
// --- Global Informations ----
145+
// --- Global Information ----
147146
// ----------------------------
148147

149-
public String getNamespaceName() {
150-
return getDatabase().getNamespaceName();
151-
}
152-
153148
/**
154-
* Retrieves the parent {@link Database} instance.
155-
* This parent namespace is used for performing CRUD (Create, Read, Update, Delete) operations on collections.
156-
*
157-
* <p>Example usage:</p>
158-
* <pre>
159-
* {@code
160-
* // Given a collection
161-
* DataApiCollection<Document> collection;
162-
* // TODO
163-
* }
164-
* </pre>
165-
*
166-
* @return parent namespace client.
149+
* Access the parent namespace associated to the collection
150+
* @return
151+
* the name of the parent namespace for current collection.
167152
*/
168-
public Database getDatabase() {
169-
return database;
153+
public String getNamespaceName() {
154+
return getDatabase().getNamespaceName();
170155
}
171156

172157
/**
173158
* Retrieves the full definition of the collection with its name and options.
174-
* <p></p>
175159
* <p>Example usage:</p>
176160
* <pre>
177161
* {@code
@@ -187,9 +171,7 @@ public Database getDatabase() {
187171
* }
188172
* </pre>
189173
*
190-
* @return the full collection definition.
191-
*
192-
* @see CollectionDefinition##getOptions()
174+
* @return the full collection definition
193175
*/
194176
public CollectionDefinition getDefinition() {
195177
return database
@@ -266,12 +248,10 @@ public String getName() {
266248
/**
267249
* Insert a single document in the collection in an atomic operation.
268250
*
269-
* <p>
270251
* <blockquote><b>Note:</b>If an `_id` is explicitly provided, which corresponds to a document
271252
* that exists already in the collection, an error is raised and the insertion fails.
272253
* Inserts the provided document. If the document is missing an identifier, the server will generate one.
273254
* </blockquote>
274-
* </p>
275255
*
276256
* @param document
277257
* the document expressing the document to insert. The `_id` field of the document can be left out, in which case it will be created automatically.
@@ -510,74 +490,112 @@ public FindIterable<DOC> find(Filter filter, FindOptions options) {
510490
* @param filter The {@link Filter} specifying the conditions that the document must meet to be considered
511491
* a match. This parameter determines how the search is conducted and what criteria the
512492
* document must satisfy to be retrieved.
513-
* @return A {@link CompletableFuture<Optional<DOC>>} that, when completed, will contain the result of
493+
* @return CompletableFuture that, when completed, will contain the result of
514494
* the search operation. If a matching document is found, the {@link Optional} is non-empty;
515495
* otherwise, it is empty to indicate the absence of a matching document. This future allows for
516496
* non-blocking operations and facilitates the integration of asynchronous programming patterns.
517497
*/
518498
public CompletableFuture<Optional<DOC>> findOneASync(Filter filter) {
519499
return CompletableFuture.supplyAsync(() -> findOne(filter));
520500
}
521-
522501
/**
523-
* Create a filter by id.
502+
* Retrieves a document by its identifier from the collection.
503+
* <p>
504+
* This method searches for a document with the specified {@code id}. If a matching document is found,
505+
* it is returned wrapped in an {@link Optional}, otherwise, an empty {@link Optional} is returned.
506+
* This approach provides a null-safe way to handle the presence or absence of a document.
507+
* </p>
524508
*
525-
* @param id
526-
* value for identifier
527-
* @return
528-
* document if it exists
509+
* @param id The identifier of the document to find.
510+
* @return An {@link Optional} containing the found document, or an empty {@link Optional} if no document
511+
* matches the provided {@code id}.
529512
*/
530513
public Optional<DOC> findById(Object id) {
531514
return findOne(Filters.eq(id));
532515
}
533516

534517
/**
535-
* Finds all documents in the collection.
518+
* Retrieves all documents in the collection.
519+
* <p>
520+
* This method returns an iterable interface that allows iterating over all documents in the collection,
521+
* without applying any filters. It leverages the default {@link FindOptions} for query execution.
522+
* </p>
536523
*
537-
* @return
538-
* the find iterable interface
524+
* @return A {@link FindIterable} for iterating over all documents in the collection.
539525
*/
540526
public FindIterable<DOC> find() {
541527
return find(null, new FindOptions());
542528
}
543529

544530
/**
545-
* Finds all documents in the collection.
531+
* Retrieves documents in the collection that match the specified filter.
532+
* <p>
533+
* This method returns an iterable interface for documents that meet the criteria defined by the {@code filter}.
534+
* It uses default {@link FindOptions} for query execution, allowing for customization of the query if needed.
535+
* </p>
546536
*
547-
* @param filter
548-
* the query filter
549-
* @return
550-
* the find iterable interface
537+
* @param filter The query filter to apply when retrieving documents.
538+
* @return A {@link FindIterable} for iterating over the documents that match the filter.
551539
*/
552540
public FindIterable<DOC> find(Filter filter) {
553541
return find(filter, new FindOptions());
554542
}
555543

556544
/**
557-
* Finds all documents in the collection.
545+
* Finds documents in the collection that match the specified filter and sorts them based on their similarity
546+
* to a provided vector, limiting the number of results returned.
547+
* <p>
548+
* This method is particularly useful for vector-based search operations where documents are ranked according
549+
* to their distance from a reference vector. The {@code limit} parameter controls the maximum number of documents
550+
* to return, allowing for efficient retrieval of the most relevant documents.
551+
* </p>
558552
*
559-
* @param filter
560-
* the query filter
561-
* @return
562-
* the find iterable interface
553+
* @param filter The query filter to apply when retrieving documents.
554+
* @param vector A float array representing the vector used to sort the documents.
555+
* @param limit The maximum number of documents to return.
556+
* @return A {@link FindIterable} for iterating over the sorted and limited documents.
563557
*/
564558
public FindIterable<DOC> find(Filter filter, float[] vector, int limit) {
565559
return find(filter, new FindOptions().sortingByVector(vector).limit(limit));
566560
}
567561

568562
/**
569-
* Finds all documents in the collection.
563+
* Finds all documents in the collection, applying the specified find options.
564+
* <p>
565+
* This method allows for detailed control over the query execution through {@link FindOptions}, which can
566+
* specify sorting, projection, limits, and other query parameters. If no filter is applied, all documents
567+
* in the collection are considered.
568+
* </p>
570569
*
571-
* @param options
572-
* options of find one
573-
* @return
574-
* the find iterable interface
570+
* @param options The {@link FindOptions} to apply when executing the find operation.
571+
* @return A {@link FindIterable} for iterating over the documents according to the specified options.
575572
*/
576573
public FindIterable<DOC> find(FindOptions options) {
577574
return find(null, options);
578575
}
579576

580-
/** {@inheritDoc} */
577+
/**
578+
* Executes a paginated 'find' query on the collection using the specified filter and find options.
579+
* <p>
580+
* This method constructs and executes a command to fetch a specific page of documents from the collection that match
581+
* the provided filter criteria. It allows for detailed control over the query through {@code FindOptions}, such as sorting,
582+
* projection, pagination, and more. The result is wrapped in a {@link Page} object, which includes the documents found,
583+
* the page size, and the state for fetching subsequent pages.
584+
* </p>
585+
* <p>
586+
* Pagination is facilitated by the {@code skip}, {@code limit}, and {@code pageState} parameters within {@code FindOptions},
587+
* enabling efficient data retrieval in scenarios where the total dataset is too large to be fetched in a single request.
588+
* Optionally, similarity scoring can be included if {@code includeSimilarity} is set, which is useful for vector-based search queries.
589+
* </p>
590+
* <p>
591+
* The method processes the command's response, mapping each document to the specified document class and collecting them into a list.
592+
* This list, along with the maximum page size and the next page state, is used to construct the {@link Page} object returned by the method.
593+
* </p>
594+
*
595+
* @param filter The filter criteria used to select documents from the collection.
596+
* @param options The {@link FindOptions} providing additional query parameters, such as sorting and pagination.
597+
* @return A {@link Page} object containing the documents that match the query, along with pagination information.
598+
*/
581599
public Page<DOC> findPage(Filter filter, FindOptions options) {
582600
Command findCommand = Command
583601
.create("find")
@@ -808,8 +826,7 @@ public DeleteResult deleteAll() {
808826
*
809827
* <p>
810828
* This method delegates the existence check to the {@code existCollection} method of the associated
811-
* namespace, determined by {@link #getDatabase()}, and evaluates the existence based on the
812-
* collection's name, as retrieved by {@link #getName()}.
829+
* namespace, evaluates the existence based on the collection's name, as retrieved by getName().
813830
* </p>
814831
*
815832
* @return {@code true} if the collection exists within the namespace, {@code false} otherwise.

0 commit comments

Comments
 (0)