Class TypeConverter

java.lang.Object
io.github.blyznytsiaorg.bibernate.utils.TypeConverter

public class TypeConverter extends Object
Contains utility methods for converting Java types to database types and checking compatibility of types for DDL creation. This utility class provides methods to convert Java types to their corresponding database types and to check if a given Java type is suitable for creating columns in a database table.
Since:
1.0
Author:
Blyzhnytsia Team
See Also:
  • Field Details

    • typeToDatabaseTypeString

      private static final Map<Class<?>,String> typeToDatabaseTypeString
  • Constructor Details

    • TypeConverter

      public TypeConverter()
  • Method Details

    • convertToDatabaseType

      public static String convertToDatabaseType(Class<?> columnType)
      Converts a Java type to its corresponding database type.
      Parameters:
      columnType - the Java type to convert
      Returns:
      the corresponding database type
    • isInternalJavaTypeSuitableForCreation

      public static boolean isInternalJavaTypeSuitableForCreation(EntityColumnDetails entityColumn, String tableName)
      Checks if the internal Java type is suitable for creating database columns. Throws an exception if the type is not supported.
      Parameters:
      entityColumn - the details of the entity column
      tableName - the name of the table
      Returns:
      true if the Java type is suitable, otherwise false
      Throws:
      UnsupportedDataTypeException - if the Java type is not supported
    • getPostgresIdTypeForGeneration

      public static String getPostgresIdTypeForGeneration(Class<?> idFieldType, String tableName)
      Gets the Postgres ID type for generation based on the Java ID field type.
      Parameters:
      idFieldType - the type of the ID field
      tableName - the name of the table
      Returns:
      the Postgres ID type for generation ("serial" or "bigserial")
      Throws:
      UnsupportedDataTypeException - if the ID field type is not supported for generation
    • checkIdTypeForGeneration

      public static void checkIdTypeForGeneration(Class<?> idFieldType, String tableName)
      Checks if the ID field type is suitable for ID generation in SQL commands.
      Parameters:
      idFieldType - the type of the ID field
      tableName - the name of the table
      Throws:
      UnsupportedDataTypeException - if the ID field type is not supported for generation