Class CollectionBeanDefinition<T>

java.lang.Object
com.datastax.astra.internal.reflection.CollectionBeanDefinition<T>
Type Parameters:
T - the type of the collection document entity being introspected

public class CollectionBeanDefinition<T> extends Object
Provides introspection and metadata for a collection document entity.

This class inspects a JavaBean of type T annotated with DataApiCollection to extract and manage metadata about its properties, particularly the document ID field marked with DocumentId.

  • Constructor Details

    • CollectionBeanDefinition

      public CollectionBeanDefinition(Class<T> clazz)
      Constructor for the collection record definition.
      Parameters:
      clazz - the class type
  • Method Details

    • getId

      public Object getId(T instance)
      Gets the ID value from the given instance.
      Parameters:
      instance - the instance to extract the ID from
      Returns:
      the ID value, or null if no @DocumentId field is defined or the value is null
      Throws:
      IllegalStateException - if the ID field cannot be accessed
    • hasIdField

      public boolean hasIdField()
      Checks if this collection record has a field annotated with @DocumentId.
      Returns:
      true if an ID field exists, false otherwise
    • getIdFieldName

      public String getIdFieldName()
      Gets the name of the ID field.
      Returns:
      the ID field name, or null if no @DocumentId field is defined
    • canSetId

      public boolean canSetId()
      Checks if the ID field can be written through a setter.
      Returns:
      true if an ID field exists and a setter is available
    • setId

      public void setId(T instance, Object value)
      Sets the ID value on the given instance.
      Parameters:
      instance - the instance to update
      value - the new ID value
    • getVectorize

      public String getVectorize(T instance)
      Gets the vectorize value from the given instance.
      Parameters:
      instance - the instance to extract the vectorize value from
      Returns:
      the vectorize value, or null if no @Vectorize field is defined or the value is null
      Throws:
      IllegalStateException - if the vectorize field cannot be accessed
    • hasVectorizeField

      public boolean hasVectorizeField()
      Checks if this collection record has a field annotated with @Vectorize.
      Returns:
      true if a vectorize field exists, false otherwise
    • getVectorizeFieldName

      public String getVectorizeFieldName()
      Gets the name of the vectorize field.
      Returns:
      the vectorize field name, or null if no @Vectorize field is defined
    • getLexical

      public String getLexical(T instance)
      Gets the lexical value from the given instance.
      Parameters:
      instance - the instance to extract the lexical value from
      Returns:
      the lexical value, or null if no @Lexical field is defined or the value is null
      Throws:
      IllegalStateException - if the lexical field cannot be accessed
    • hasLexicalField

      public boolean hasLexicalField()
      Checks if this collection record has a field annotated with @Lexical.
      Returns:
      true if a lexical field exists, false otherwise
    • getLexicalFieldName

      public String getLexicalFieldName()
      Gets the name of the lexical field.
      Returns:
      the lexical field name, or null if no @Lexical field is defined
    • getVector

      public Object getVector(T instance)
      Gets the vector value from the given instance.
      Parameters:
      instance - the instance to extract the vector value from
      Returns:
      the vector value (float[] or DataAPIVector), or null if no @Vector field is defined or the value is null
      Throws:
      IllegalStateException - if the vector field cannot be accessed
    • hasVectorField

      public boolean hasVectorField()
      Checks if this collection record has a field annotated with @Vector.
      Returns:
      true if a vector field exists, false otherwise
    • getVectorFieldName

      public String getVectorFieldName()
      Gets the name of the vector field.
      Returns:
      the vector field name, or null if no @Vector field is defined
    • buildCollectionDefinition

      public CollectionDefinition buildCollectionDefinition()
      Builds a CollectionDefinition from the @DataApiCollection annotation properties.
      Returns:
      a CollectionDefinition configured according to the annotation, or null if no annotation present