Class Parameters

java.lang.Object
com.pyranid.Parameters

@ThreadSafe public final class Parameters extends Object
Fluent interface for acquiring instances of specialized parameter types.
Since:
3.0.0
Author:
Mark Allen
  • Method Details

    • arrayOf

      @Nonnull public static <E> ArrayParameter<E> arrayOf(@Nonnull String baseTypeName, @Nullable List<E> list)
      Acquires a SQL ARRAY parameter for a List given an appropriate java.sql.Array#getBaseTypeName().

      You may determine available baseTypeName values for your database by examining metadata exposed via Database.readDatabaseMetaData(DatabaseMetaDataReader).

      Type Parameters:
      E - the element type of the Java list (List<E>); each element must be bindable to baseTypeName by the active PreparedStatementBinder.
      Parameters:
      baseTypeName - the SQL ARRAY element type, e.g. "text", "uuid", "float4", "float8" ...
      list - the list whose elements will be used to populate the SQL ARRAY
      Returns:
      a SQL ARRAY parameter for the given list
    • arrayOf

      @Nonnull public static <E> ArrayParameter<E> arrayOf(@Nonnull String baseTypeName, @Nullable E[] array)
      Acquires a SQL ARRAY parameter for a native Java array given an appropriate java.sql.Array#getBaseTypeName().

      You may determine available baseTypeName values for your database by examining metadata exposed via Database.readDatabaseMetaData(DatabaseMetaDataReader).

      Type Parameters:
      E - the element type of the Java array (T[]); each element must be bindable to baseTypeName by the active PreparedStatementBinder.
      Parameters:
      baseTypeName - the SQL ARRAY element type, e.g. "text", "uuid", "float4", "float8" ...
      array - the native Java array whose elements will be used to populate the SQL ARRAY
      Returns:
      a SQL ARRAY parameter for the given Java array
    • vectorOfDoubles

      @Nonnull public static VectorParameter vectorOfDoubles(@Nullable double[] elements)
      Acquires a vector parameter for an array of double.
      Parameters:
      elements - the elements of the vector parameter
      Returns:
      the vector parameter
    • vectorOfDoubles

      @Nonnull public static VectorParameter vectorOfDoubles(@Nullable List<Double> elements)
      Acquires a vector parameter for a List of Double.
      Parameters:
      elements - the elements of the vector parameter
      Returns:
      the vector parameter
    • vectorOfFloats

      @Nonnull public static VectorParameter vectorOfFloats(@Nullable float[] elements)
      Acquires a vector parameter for an array of float.
      Parameters:
      elements - the elements of the vector parameter
      Returns:
      the vector parameter
    • vectorOfFloats

      @Nonnull public static VectorParameter vectorOfFloats(@Nullable List<Float> elements)
      Acquires a vector parameter for a List of Float.
      Parameters:
      elements - the elements of the vector parameter
      Returns:
      the vector parameter
    • vectorOfBigDecimals

      @Nonnull public static VectorParameter vectorOfBigDecimals(@Nullable List<BigDecimal> elements)
      Acquires a vector parameter for a List of BigDecimal.
      Parameters:
      elements - the elements of the vector parameter
      Returns:
      the vector parameter
    • json

      @Nonnull public static JsonParameter json(@Nullable String json)
      Acquires a JSON parameter for "stringified" JSON, using JsonParameter.BindingPreference.BINARY.
      Parameters:
      json - the stringified JSON for this parameter
      Returns:
      the JSON parameter
    • json

      @Nonnull public static JsonParameter json(@Nullable String json, @Nonnull JsonParameter.BindingPreference bindingPreference)
      Acquires a JSON parameter for "stringified" JSON.
      Parameters:
      json - the stringified JSON for this parameter
      bindingPreference - how the JSON parameter should be bound to a PreparedStatement
      Returns:
      the JSON parameter
    • listOf

      @Nonnull public static <E> TypedParameter listOf(@Nonnull Class<E> elementType, @Nullable List<E> list)
      Acquires a parameter of type List, preserving type information so it is accessible at runtime.

      This is useful when you want to bind a parameterized collection such as List<UUID> or List<String> and need the generic type argument (e.g. UUID.class) to be preserved.

      The resulting TypedParameter carries both the runtime value and its generic type so that CustomParameterBinder.appliesTo(TargetType) can match against the element type.

      Note: this kind of parameter requires a corresponding CustomParameterBinder to be registered; otherwise, binding will fail-fast.

      Type Parameters:
      E - the element type of the list
      Parameters:
      elementType - the Class representing the type of elements contained in the list; used to preserve generic type information
      list - the list value to wrap; may be null
      Returns:
      a TypedParameter representing a List<E> suitable for use with custom binders
    • setOf

      @Nonnull public static <E> TypedParameter setOf(@Nonnull Class<E> elementType, @Nullable Set<E> set)
      Acquires a parameter of type Set, preserving type information so it is accessible at runtime.

      This is useful when you want to bind a parameterized collection such as Set<UUID> or Set<String> and need the generic type argument (e.g. UUID.class) to be preserved.

      The resulting TypedParameter carries both the runtime value and its generic type so that CustomParameterBinder.appliesTo(TargetType) can match against the element type.

      Note: this kind of parameter requires a corresponding CustomParameterBinder to be registered; otherwise, binding will fail-fast.

      Type Parameters:
      E - the element type of the set
      Parameters:
      elementType - the Class representing the type of elements contained in the set; used to preserve generic type information
      set - the set value to wrap; may be null
      Returns:
      a TypedParameter representing a Set<E> suitable for use with custom binders
    • mapOf

      @Nonnull public static <K,V> TypedParameter mapOf(@Nonnull Class<K> keyType, @Nonnull Class<V> valueType, @Nullable Map<K,V> map)
      Acquires a parameter of type Map, preserving key and value type information so they are accessible at runtime.

      This is useful when you want to bind a parameterized collection such as Map<UUID, Integer> and need the generic type arguments (e.g. UUID.class and Integer.class) to be preserved.

      The resulting TypedParameter carries both the runtime value and its generic type so that CustomParameterBinder.appliesTo(TargetType) can match against the element type.

      Note: this kind of parameter requires a corresponding CustomParameterBinder to be registered; otherwise, binding will fail-fast.

      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyType - the type of the map keys
      valueType - the type of the map values
      map - the map value; may be null
      Returns:
      a TypedParameter representing Map<K,V>