Package com.mckoi.database
Class Caster
java.lang.Object
com.mckoi.database.Caster
Methods to choose and perform casts from database type to Java types.
- Author:
- Jim McBeath
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The cost to cast to the closes Java object type.static final int
The cost to cast to the closest Java primitive type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object[]
castArgsToConstructor
(TObject[] args, Constructor constructor) Cast the given arguments to the specified constructors parameter types.static void
deserializeJavaObjects
(TObject[] args) Find any JAVA_OBJECTs in the args and deserialize them into real Java objects.static Constructor
findBestConstructor
(Constructor[] constructs, TObject[] args) Search for the best constructor that we can use with the given argument types.static String
getArgTypesString
(TObject[] args) Get a string giving the database types of all of the arguments.static int
getSqlType
(TObject arg) Get the SQL type for a database argument.static int[]
getSqlTypes
(TObject[] args) Get the SQL types for the given database arguments.
-
Field Details
-
PRIMITIVE_COST
public static final int PRIMITIVE_COSTThe cost to cast to the closest Java primitive type.- See Also:
-
OBJECT_COST
public static final int OBJECT_COSTThe cost to cast to the closes Java object type.- See Also:
-
-
Constructor Details
-
Caster
public Caster()
-
-
Method Details
-
deserializeJavaObjects
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
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
Get the SQL types for the given database arguments.- Parameters:
args
- The database args.- Returns:
- The SQL types of the args.
-
getSqlType
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
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
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.
-