diff --git a/astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/documents/Document.java b/astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/documents/Document.java index 937f3e4..183a5b6 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/documents/Document.java +++ b/astra-db-java/src/main/java/com/datastax/astra/client/collections/definition/documents/Document.java @@ -554,52 +554,104 @@ public String toJson() { return toString(); } - /** {@inheritDoc} */ + /** + * Evaluation if a key is present in the document + * @param key + * key to evaluate + * @return + * true if the key is present + */ public boolean containsKey(final Object key) { return documentMap.containsKey(key); } - /** {@inheritDoc} */ + + /** + * Retrieves the value associated with the specified key from the document. + * + * @param key the key whose associated value is to be returned + * @return the value associated with the specified key, or {@code null} if the key is not found + */ public Object get(final Object key) { return documentMap.get(key); } - /** {@inheritDoc} */ + /** + * Associates the specified value with the specified key in the document. + * If the key already has a value, the old value is replaced. + * + * @param key the key with which the specified value is to be associated + * @param value the value to be associated with the specified key + * @return the previous value associated with the key, or {@code null} if there was no mapping for the key + */ public Object put(final String key, final Object value) { return documentMap.put(key, value); } - /** {@inheritDoc} */ + /** + * Removes the mapping for a key from the document if it is present. + * + * @param key the key whose mapping is to be removed + * @return the value that was associated with the key, or {@code null} if the key was not mapped + */ public Object remove(final Object key) { return documentMap.remove(key); } - /** {@inheritDoc} */ + /** + * Copies all mappings from the specified map to this document. + * Existing mappings will be replaced with mappings from the provided map. + * + * @param map the map containing mappings to be copied to this document + */ public void putAll(final Map map) { documentMap.putAll(map); } - /** {@inheritDoc} */ + /** + * Copies all mappings from the specified {@code Document} to this document. + * Existing mappings will be replaced with mappings from the provided document. + * + * @param doc the document whose mappings are to be copied to this document + */ public void putAll(Document doc) { documentMap.putAll(doc.getDocumentMap()); } - /** {@inheritDoc} */ + /** + * Removes all mappings from this document. + * The document will be empty after this operation. + */ public void clear() { documentMap.clear(); } - /** {@inheritDoc} */ + /** + * Returns a collection view of the values contained in this document. + * + * @return a collection view of the values contained in this document + */ public Collection values() { return documentMap.values(); } - /** {@inheritDoc} */ + /** + * Returns a set view of the mappings contained in this document. + * Each entry in the set is a key-value pair. + * + * @return a set view of the mappings contained in this document + */ public Set> entrySet() { return documentMap.entrySet(); } - /** {@inheritDoc} */ + /** + * Compares this document to another object for equality. + * Two documents are considered equal if their underlying maps are equal. + * + * @param o the object to compare with this document + * @return {@code true} if the specified object is equal to this document, {@code false} otherwise + */ @Override public boolean equals(final Object o) { if (this == o) { @@ -612,7 +664,12 @@ public boolean equals(final Object o) { return documentMap.equals(document.documentMap); } - /** {@inheritDoc} */ + /** + * Returns the hash code value for this document. + * The hash code is computed based on the underlying map. + * + * @return the hash code value for this document + */ @Override public int hashCode() { return documentMap.hashCode(); @@ -620,5 +677,4 @@ public int hashCode() { - } diff --git a/astra-db-java/src/main/java/com/datastax/astra/client/core/paging/CollectionCursor.java b/astra-db-java/src/main/java/com/datastax/astra/client/core/paging/CollectionCursor.java index 3e6283f..336266d 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/client/core/paging/CollectionCursor.java +++ b/astra-db-java/src/main/java/com/datastax/astra/client/core/paging/CollectionCursor.java @@ -127,6 +127,7 @@ public CollectionCursor clone() { * * @param newFilter * a new filter + * @return a new {@code CollectionCursor} instance with the filter applied */ public CollectionCursor filter(Filter newFilter) { checkIdleState(); @@ -140,6 +141,7 @@ public CollectionCursor filter(Filter newFilter) { * * @param newProjection * a new projection + * @return a new {@code CollectionCursor} instance with the projection applied */ public CollectionCursor project(Projection... newProjection) { checkIdleState(); @@ -236,7 +238,12 @@ private void rewind() { this.consumedCount = 0; } - // Buffer consumption + /** + * Consume the buffer and return the results. + * + * @return + * list of results + */ public List consumeBuffer(int n) { if (state == CursorState.CLOSED || state == CursorState.IDLE) { return Collections.emptyList(); @@ -297,7 +304,9 @@ public T next() { } } - // Fetch next batch of documents + /** + * Fetch the next batch of documents into the buffer. + */ private void fetchNextBatch() { if (currentPage == null) { currentPage = myCollection.findPage(filter, findOptions); @@ -311,15 +320,32 @@ private void fetchNextBatch() { } } - // Additional methods + /** + * Check if there is a next element. + * + * @return + * true if there is a next element + */ public boolean hasNext() { return iterator().hasNext(); } + /** + * Retrieve the next element. + * + * @return + * next element + */ public T next() { return iterator().next(); } + /** + * Retrieve all the elements in a list. + * + * @return + * list of elements + */ public List toList() { List result = new ArrayList<>(); try { diff --git a/astra-db-java/src/main/java/com/datastax/astra/client/exceptions/ClientErrorCodes.java b/astra-db-java/src/main/java/com/datastax/astra/client/exceptions/ClientErrorCodes.java index ad37110..c1fc737 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/client/exceptions/ClientErrorCodes.java +++ b/astra-db-java/src/main/java/com/datastax/astra/client/exceptions/ClientErrorCodes.java @@ -22,27 +22,110 @@ import lombok.Getter; +/** + * Represents client error codes used to standardize error reporting in the application. + * Each error code is associated with a unique identifier (`code`) and a descriptive message (`message`). + *

+ * This enum is designed to facilitate consistent error handling and logging across various components. + * Some codes are pre-configured with detailed messages that accept placeholders for dynamic values, + * while others are placeholders for future implementation. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * String errorCode = ClientErrorCodes.CONFIG_MISSING.getCode();
+ * String errorMessage = String.format(ClientErrorCodes.CONFIG_MISSING.getMessage(), "paramName", "operationName");
+ * }
+ * 
+ */ @Getter public enum ClientErrorCodes { + + /** + * Indicates that the operation is restricted to Astra environments. + * Dynamic placeholders: + *
    + *
  • {@code '%s'}: The operation name.
  • + *
  • {@code '%s'}: The current environment.
  • + *
+ */ ENV_RESTRICTED_ASTRA("ASTRA_RESTRICTED", "Operation '%s' available only for Astra environments (current is '%s')"), + + /** + * Indicates that a required configuration parameter is missing. + * Dynamic placeholders: + *
    + *
  • {@code '%s'}: The name of the missing configuration parameter.
  • + *
  • {@code '%s'}: The operation requiring the parameter.
  • + *
+ */ CONFIG_MISSING("CLIENT_CONFIG_MISSING", "Configuration parameter is missing : '%s' for operation '%s'"), + + /** + * Indicates that a required annotation is missing from a bean. + * Dynamic placeholders: + *
    + *
  • {@code '%s'}: The name of the missing annotation.
  • + *
  • {@code '%s'}: The name of the bean.
  • + *
  • {@code '%s'}: The operation requiring the annotation.
  • + *
+ */ MISSING_ANNOTATION("CLIENT_MISSING_ANNOTATION", "Annotation '%s' is missing on bean '%s' for operation '%s'"), - // TODO + /** + * Generic client error with no specific message. + */ ERROR("CLIENT_ERROR", ""), + + /** + * Indicates an HTTP error encountered by the client. + */ HTTP("CLIENT_HTTP", ""), + + /** + * Indicates a timeout error encountered by the client. + */ TIMEOUT("CLIENT_TIMEOUT", ""), + + /** + * Indicates an operation was interrupted. + */ INTERRUPTED("CLIENT_INTERRUPTED", ""), + + /** + * Placeholder for random client errors. + */ RANDOM("CLIENT_RANDOM", ""), + + /** + * Indicates an error related to cursor operations. + */ CURSOR("CLIENT_CURSOR", ""), + + /** + * Indicates an error in client-side serialization. + */ SERIALIZATION("CLIENT_SERIALIZATION", "CLIENT_SERIALIZATION"); + /** + * The unique code representing the error. + */ private final String code; + /** + * The descriptive message associated with the error. + */ private final String message; + /** + * Constructs a new {@code ClientErrorCodes} instance with the specified code and message. + * + * @param code the unique code representing the error + * @param message the descriptive message associated with the error + */ ClientErrorCodes(String code, String message) { - this.code = code; + this.code = code; this.message = message; } } diff --git a/astra-db-java/src/main/java/com/datastax/astra/client/tables/commands/options/AlterTableOptions.java b/astra-db-java/src/main/java/com/datastax/astra/client/tables/commands/options/AlterTableOptions.java index 815b7ae..32c40b0 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/client/tables/commands/options/AlterTableOptions.java +++ b/astra-db-java/src/main/java/com/datastax/astra/client/tables/commands/options/AlterTableOptions.java @@ -27,30 +27,54 @@ import static com.datastax.astra.client.tables.Table.DEFAULT_TABLE_SERIALIZER; +/** + * Represents options for altering a table in a database schema. + * Extends {@link BaseOptions} to provide additional functionality for table alteration commands. + *

+ * This class supports a fluent, chainable API using the {@link Accessors} annotation. + * Common options include specifying whether to include an "IF EXISTS" condition during the operation. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * AlterTableOptions options = new AlterTableOptions()
+ *     .ifExists(true);
+ * }
+ * 
+ */ @Setter @Accessors(fluent = true, chain = true) public class AlterTableOptions extends BaseOptions { - /** Improve syntax. */ + /** + * A predefined instance of {@code AlterTableOptions} with the "IF EXISTS" condition enabled. + * This improves syntax for commonly used configurations. + */ public static final AlterTableOptions IF_EXISTS = new AlterTableOptions().ifExists(true); /** - * Condition to upsert the table. + * Indicates whether the "IF EXISTS" condition should be applied to the table alteration. + * When {@code true}, the operation will only proceed if the table exists. */ - boolean ifExists = true; + private boolean ifExists = true; + /** + * Constructs a new {@code AlterTableOptions} instance with default settings. + * Initializes the options with {@link CommandType#TABLE_ADMIN} and the default table serializer. + */ public AlterTableOptions() { super(null, CommandType.TABLE_ADMIN, DEFAULT_TABLE_SERIALIZER, null); } /** - * Accessor for serialization. + * Retrieves the value of the "IF EXISTS" condition. + * This condition determines whether the operation should check for the existence of the table. * - * @return - * accessor for serialization + * @return {@code true} if the "IF EXISTS" condition is enabled, {@code false} otherwise */ public boolean isIfExists() { return ifExists; } - } + diff --git a/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionList.java b/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionList.java index 251c7e7..2dc5c8a 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionList.java +++ b/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionList.java @@ -23,15 +23,43 @@ import lombok.Getter; import lombok.Setter; -@Getter @Setter +/** + * Represents a column definition for a list type in a database schema. + * Extends {@link ColumnDefinition} to include details about the type of elements stored in the list. + *

+ * This class is used to configure columns of type {@link ColumnTypes#LIST}, allowing the specification + * of the data type for the values stored in the list. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * ColumnDefinitionList listColumn = new ColumnDefinitionList(ColumnTypes.TEXT);
+ * ColumnTypes valueType = listColumn.getValueType();
+ * }
+ * 
+ */ +@Getter +@Setter public class ColumnDefinitionList extends ColumnDefinition { + /** + * The data type of the values stored in the list. + */ private ColumnTypes valueType; + /** + * Constructs a new {@code ColumnDefinitionList} instance with the column type set to {@link ColumnTypes#LIST}. + */ public ColumnDefinitionList() { super(ColumnTypes.LIST); } + /** + * Constructs a new {@code ColumnDefinitionList} instance with the specified value type. + * + * @param valueType the data type of the values in the list + */ public ColumnDefinitionList(ColumnTypes valueType) { this(); this.valueType = valueType; diff --git a/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionSet.java b/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionSet.java index 4188395..2445ffa 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionSet.java +++ b/astra-db-java/src/main/java/com/datastax/astra/client/tables/definition/columns/ColumnDefinitionSet.java @@ -23,15 +23,42 @@ import lombok.Getter; import lombok.Setter; +/** + * Represents a column definition for a set type in a database schema. + * Extends {@link ColumnDefinition} to include details about the type of elements stored in the set. + *

+ * This class is used to configure columns of type {@link ColumnTypes#SET}, allowing the specification + * of the data type for the values stored in the set. + *

+ * + *

Example usage:

+ *
+ * {@code
+ * ColumnDefinitionSet setColumn = new ColumnDefinitionSet(ColumnTypes.TEXT);
+ * ColumnTypes valueType = setColumn.getValueType();
+ * }
+ * 
+ */ @Getter @Setter public class ColumnDefinitionSet extends ColumnDefinition { + /** + * The data type of the values stored in the set. + */ private ColumnTypes valueType; + /** + * Constructs a new {@code ColumnDefinitionSet} instance with the column type set to {@link ColumnTypes#SET}. + */ public ColumnDefinitionSet() { super(ColumnTypes.SET); } + /** + * Constructs a new {@code ColumnDefinitionSet} instance with the specified value type. + * + * @param valueType the data type of the values in the set + */ public ColumnDefinitionSet(ColumnTypes valueType) { this(); this.valueType = valueType; diff --git a/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArrayDeserializer.java b/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArrayDeserializer.java index d010109..e8924d7 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArrayDeserializer.java +++ b/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArrayDeserializer.java @@ -28,12 +28,49 @@ import java.io.IOException; import java.util.Base64; +/** + * A custom deserializer for byte arrays that expects the input JSON to be a Base64-encoded string + * wrapped in a JSON object with a specific field name. + *

+ * This deserializer processes a JSON object with the following format: + *

+ * + *
+ * {
+ *   "$binary": "base64EncodedString"
+ * }
+ * 
+ * + *

Example usage:

+ *
+ * {@code
+ * ObjectMapper mapper = new ObjectMapper();
+ * SimpleModule module = new SimpleModule();
+ * module.addDeserializer(byte[].class, new ByteArrayDeserializer());
+ * mapper.registerModule(module);
+ *
+ * String json = "{\"$binary\": \"AQID\"}";
+ * byte[] data = mapper.readValue(json, byte[].class);
+ * }
+ * 
+ */ public class ByteArrayDeserializer extends StdDeserializer { + /** + * Default constructor that specifies the {@code byte[]} type for deserialization. + */ public ByteArrayDeserializer() { super(byte[].class); } + /** + * Deserializes a JSON object containing a Base64-encoded string into a byte array. + * + * @param p the {@link JsonParser} used to parse the JSON input + * @param ctxt the {@link DeserializationContext} that can be used to handle contextual information + * @return the deserialized byte array + * @throws IOException if the JSON structure is invalid or if a decoding error occurs + */ @Override public byte[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { if (p.getCurrentToken() == JsonToken.START_OBJECT) { @@ -51,5 +88,4 @@ public byte[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx throw new IOException("Expected START_OBJECT token"); } } - } diff --git a/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArraySerializer.java b/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArraySerializer.java index 7657628..4f5991b 100644 --- a/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArraySerializer.java +++ b/astra-db-java/src/main/java/com/datastax/astra/internal/serdes/tables/ByteArraySerializer.java @@ -26,12 +26,57 @@ import java.io.IOException; import java.util.Base64; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import java.io.IOException; +import java.util.Base64; + +/** + * A custom serializer for byte arrays that encodes the array as a Base64 string + * and wraps it in a JSON object with a specific field name. + *

+ * This serializer converts a byte array into a JSON object with the following format: + *

+ * + *
+ * {
+ *   "$binary": "base64EncodedString"
+ * }
+ * 
+ * + *

Example usage:

+ *
+ * {@code
+ * ObjectMapper mapper = new ObjectMapper();
+ * SimpleModule module = new SimpleModule();
+ * module.addSerializer(new ByteArraySerializer());
+ * mapper.registerModule(module);
+ *
+ * byte[] data = {1, 2, 3};
+ * String json = mapper.writeValueAsString(data);
+ * }
+ * 
+ */ public class ByteArraySerializer extends StdSerializer { + /** + * Default constructor that specifies the {@code byte[]} type for serialization. + */ public ByteArraySerializer() { super(byte[].class); } + /** + * Serializes a byte array as a Base64-encoded string wrapped in a JSON object. + * + * @param value the byte array to serialize + * @param gen the {@link JsonGenerator} used to write the serialized JSON output + * @param provider the {@link SerializerProvider} that can be used to get serializers for + * serializing objects contained within this value + * @throws IOException if an I/O error occurs during serialization + */ @Override public void serialize(byte[] value, JsonGenerator gen, SerializerProvider provider) throws IOException { String base64Encoded = Base64.getEncoder().encodeToString(value);