Class Caster

java.lang.Object
com.mckoi.database.Caster

public class Caster extends Object
Methods to choose and perform casts from database type to Java types.
Author:
Jim McBeath
  • Field Details

    • PRIMITIVE_COST

      public static final int PRIMITIVE_COST
      The cost to cast to the closest Java primitive type.
      See Also:
    • OBJECT_COST

      public static final int OBJECT_COST
      The cost to cast to the closes Java object type.
      See Also:
  • Constructor Details

    • Caster

      public Caster()
  • Method Details

    • deserializeJavaObjects

      public static void deserializeJavaObjects(TObject[] args)
      Find any JAVA_OBJECTs in the args and deserialize them into real Java objects.
      Parameters:
      args - The args to deserialize. Any JAVA_OBJECT args are converted in-place to a new TObject with a value which is the deserialized object.
    • findBestConstructor

      public static Constructor findBestConstructor(Constructor[] constructs, TObject[] args)
      Search for the best constructor that we can use with the given argument types.
      Parameters:
      constructs - The set of constructors from which to select.
      argSqlTypes - The SQL types of the database arguments to be passed to the constructor.
      Returns:
      The constructor with the lowest cost, or null if there are no constructors that match the args.
    • getSqlTypes

      public static int[] getSqlTypes(TObject[] args)
      Get the SQL types for the given database arguments.
      Parameters:
      args - The database args.
      Returns:
      The SQL types of the args.
    • getSqlType

      public static int getSqlType(TObject arg)
      Get the SQL type for a database argument. If the actual value does not fit into the declared type, the returned type is widened as required for the value to fit.
      Parameters:
      arg - The database argument.
      Returns:
      The SQL type of the arg.
    • getArgTypesString

      public static String getArgTypesString(TObject[] args)
      Get a string giving the database types of all of the arguments. Useful for error messages.
      Parameters:
      args - The arguments.
      Returns:
      A string with the types of all of the arguments, using comma as a separator.
    • castArgsToConstructor

      public static Object[] castArgsToConstructor(TObject[] args, Constructor constructor)
      Cast the given arguments to the specified constructors parameter types. The caller must already have checked to make sure the argument count and types match the constructor.
      Parameters:
      args - The database arguments from which to cast.
      constructor - The constructor to which to cast.
      Returns:
      The cast arguments.