Interface VectorTypeConverter<T>

Type Parameters:
T - The persisted driver type for a given dialect (e.g. org.postgresql.util.PGobject/PGvector, String, byte[])

public interface VectorTypeConverter<T>
Dialect-specific converter for vector values to and from the persisted database type (JDBC/R2DBC). Responsibilities: - Provide the exact persisted driver type via getPersistedType() (e.g. PGvector, String, byte[]). - Declare the supported vector subtypes via supportedVectorTypes() (keep this list minimal). - Identify the target database via databaseType(). Selection semantics: - At runtime, Micronaut Data selects a converter based on the current DatabaseType. - Implementations should avoid overlapping support for the same database type; ambiguous configurations may result in a selection error. - For read paths, converters may be chosen using both the database type and the actual persisted type (see getPersistedType()).
Since:
5.0.0
Author:
Nemanja Mikic
  • Method Summary

    Modifier and Type
    Method
    Description
    convert(Vector vector)
    Convert an entity-side Vector into the dialect-specific persisted type.
    convert(T object, Class<Vector> targetType)
    Convert a dialect-specific persisted value into the entity-side Vector.
    The database type (dialect family) this converter targets.
    The exact persisted driver type this converter reads/writes.
    default boolean
    Whether this converter is designed for sparse vectors.
    Set<Class<? extends Vector>>
    The exact vector subtypes supported by this converter for the declared database type.
  • Method Details

    • convert

      T convert(Vector vector)
      Convert an entity-side Vector into the dialect-specific persisted type. Contract: - The supplied vector should be an instance of one of supportedVectorTypes() or a compatible superclass. - The returned object MUST be an instance of getPersistedType().
      Parameters:
      vector - the vector value from the entity side (non-null)
      Returns:
      the persisted value to bind to JDBC/R2DBC (non-null)
    • convert

      Vector convert(T object, Class<Vector> targetType)
      Convert a dialect-specific persisted value into the entity-side Vector. Contract: - The supplied object SHOULD be an instance of getPersistedType() (or assignable). - The targetType will be one of the supported vector types or Vector.class. - Converters SHOULD perform the necessary numeric conversions (e.g. float/double narrowing) consistently.
      Parameters:
      object - the persisted value (type returned by getPersistedType(), non-null)
      targetType - the target entity type (typically Vector.class or a concrete subtype)
      Returns:
      the entity-side vector value (non-null)
    • supportedVectorTypes

      Set<Class<? extends Vector>> supportedVectorTypes()
      The exact vector subtypes supported by this converter for the declared database type. Keep this set minimal to avoid ambiguity (e.g. prefer a single, precise subtype, or Vector.class if generic).
      Returns:
      the set of supported vector types (non-empty)
    • databaseType

      DatabaseType databaseType()
      The database type (dialect family) this converter targets.
      Returns:
      the database type
    • getPersistedType

      Class<T> getPersistedType()
      The exact persisted driver type this converter reads/writes. Examples: org.postgresql.util.PGobject or com.pgvector.PGvector for PostgreSQL, String for Oracle textual representation, byte[] for MySQL HeatWave binary.
      Returns:
      the persisted driver type class
    • isSparseSupported

      default boolean isSparseSupported()
      Whether this converter is designed for sparse vectors. Used as a tiebreaker when multiple converters exist for the same database type. Implementations that handle SparseVector persisted paths should return true.
      Returns:
      true if sparse vectors are supported/preferred by this converter