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

    • sqlArrayOf

      public static <E> @NonNull SqlArrayParameter<E> sqlArrayOf(@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).

      For non-SQL array binding where you need to preserve the Java element type for custom binders, use arrayOf(Class, Object) instead.

      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
    • sqlArrayOf

      public static <E> @NonNull SqlArrayParameter<E> sqlArrayOf(@NonNull String baseTypeName, E @Nullable [] 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).

      For non-SQL array binding where you need to preserve the Java element type for custom binders, use arrayOf(Class, Object) instead.

      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
    • inList

      public static <E> @NonNull InListParameter inList(@NonNull Collection<@Nullable E> elements)
      Acquires a parameter for SQL IN list expansion using a Collection. Elements must be non-empty.
      Type Parameters:
      E - the element type
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static <E> @NonNull InListParameter inList(@NonNull E @Nullable [] elements)
      Acquires a parameter for SQL IN list expansion using a Java array. Elements must be non-empty.
      Type Parameters:
      E - the element type
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(byte @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using a byte[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(short @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using a short[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(int @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using an int[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(long @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using a long[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(float @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using a float[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(double @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using a double[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(boolean @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using a boolean[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • inList

      public static @NonNull InListParameter inList(char @NonNull [] elements)
      Acquires a parameter for SQL IN list expansion using a char[] array. Elements must be non-empty.
      Parameters:
      elements - the elements to expand into SQL IN list placeholders
      Returns:
      an IN-list parameter for the given elements
    • arrayOf

      public static <E> @NonNull TypedParameter arrayOf(@NonNull Class<E> elementType, E @Nullable [] array)
      Acquires a parameter of array type, preserving element type information so it is accessible at runtime.

      This is useful when you want to bind an array via a CustomParameterBinder and need the component type to be preserved for TargetType matching.

      For SQL ARRAY binding, use sqlArrayOf(String, Object[]) instead. If you need a formal SQL ARRAY parameter for JDBC array binding, do not use this method.

      Note: this kind of parameter requires a corresponding CustomParameterBinder to be registered, even when the wrapped value is null; implement CustomParameterBinder.bindNull(StatementContext, PreparedStatement, Integer, TargetType, Integer) if you want typed nulls to bind successfully.

      Type Parameters:
      E - the element type of the array
      Parameters:
      elementType - the element type of the array
      array - the array value to wrap; may be null
      Returns:
      a TypedParameter representing a E[] suitable for use with custom binders
    • arrayOf

      public static @NonNull TypedParameter arrayOf(@NonNull Class<?> elementType, @Nullable Object array)
      Acquires a parameter of array type, preserving element type information so it is accessible at runtime.

      This overload supports primitive arrays by passing the primitive component class (for example, int.class) and the corresponding primitive array.

      For SQL ARRAY binding, use sqlArrayOf(String, Object[]) instead. If you need a formal SQL ARRAY parameter for JDBC array binding, do not use this method.

      Note: this kind of parameter requires a corresponding CustomParameterBinder to be registered, even when the wrapped value is null; implement CustomParameterBinder.bindNull(StatementContext, PreparedStatement, Integer, TargetType, Integer) if you want typed nulls to bind successfully.

      Parameters:
      elementType - the element type of the array (may be primitive)
      array - the array value to wrap; may be null
      Returns:
      a TypedParameter representing an array suitable for use with custom binders
    • vectorOfDoubles

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

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

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

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

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

      public static @NonNull 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

      public static @NonNull 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

      public static <E> @NonNull 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, even when the wrapped value is null; implement CustomParameterBinder.bindNull(StatementContext, PreparedStatement, Integer, TargetType, Integer) if you want typed nulls to bind successfully.

      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

      public static <E> @NonNull 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, even when the wrapped value is null; implement CustomParameterBinder.bindNull(StatementContext, PreparedStatement, Integer, TargetType, Integer) if you want typed nulls to bind successfully.

      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

      public static <K,V> @NonNull 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, even when the wrapped value is null; implement CustomParameterBinder.bindNull(StatementContext, PreparedStatement, Integer, TargetType, Integer) if you want typed nulls to bind successfully.

      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>