Class TableProcessor

java.lang.Object
dimstyl.orm.internal.processors.TableProcessor

public final class TableProcessor extends Object
Utility class responsible for processing table metadata for ORM.

This class extracts and processes table metadata from entity classes annotated with Table, including table names, column mappings, and primary key resolution.

  • Constructor Details

    • TableProcessor

      private TableProcessor()
      Private constructor to prevent instantiation.
  • Method Details

    • extractMetadata

      static TableMetadata extractMetadata(Class<? extends Entity> entityClass, DatabaseEngine databaseEngine) throws MissingTableAnnotationException, UnsupportedFieldTypeException
      Extracts table metadata from an entity class.

      This method retrieves table-related metadata such as table name, unique constraints, and column metadata, using reflection to process annotated fields.

      Parameters:
      entityClass - The entity class annotated with Table.
      databaseEngine - The DatabaseEngine used for column type resolution.
      Returns:
      TableMetadata containing table details.
      Throws:
      MissingTableAnnotationException - If the entity class lacks the Table annotation.
      UnsupportedFieldTypeException - If a field has an unsupported type.
    • resolvePrimaryKeyColumnName

      public static String resolvePrimaryKeyColumnName(Class<? extends Entity> entityClass) throws CompositePrimaryKeyException, MissingColumnAnnotationException, MissingPrimaryKeyException
      Resolves the primary key column name for a given entity class.

      Ensures that a valid primary key is present and handles composite primary key cases.

      Parameters:
      entityClass - The entity class containing the primary key.
      Returns:
      The name of the primary key column.
      Throws:
      CompositePrimaryKeyException - If multiple primary key annotations are detected.
      MissingColumnAnnotationException - If the primary key field lacks a Column annotation.
      MissingPrimaryKeyException - If no primary key is found.
    • mapFieldsToColumns

      public static Map<String,String> mapFieldsToColumns(Class<? extends Entity> entityClass) throws MissingColumnAnnotationException
      Maps entity class fields to their corresponding table column names.

      Uses reflection to scan fields annotated with Column and map their names to column names as defined in the annotation.

      Parameters:
      entityClass - The entity class to be processed.
      Returns:
      A map where keys are field names and values are corresponding column names.
      Throws:
      MissingColumnAnnotationException - If a field lacks a Column annotation.
    • resolveTableName

      static String resolveTableName(Class<? extends Entity> entityClass)
      Resolves the table name for a given entity class.

      If the Table annotation specifies a name, it is used; otherwise, a default name is derived from the entity class name.

      Parameters:
      entityClass - The entity class.
      Returns:
      The resolved table name.
    • determineTableName

      private static String determineTableName(Table table, String entityClassName)
      Determines the table name based on the Table annotation or defaults to a formatted class name.
      Parameters:
      table - The extracted Table annotation.
      entityClassName - The entity class name.
      Returns:
      The resolved table name.
    • extractTableAnnotation

      private static Table extractTableAnnotation(Class<? extends Entity> entityClass) throws MissingTableAnnotationException
      Extracts the Table annotation from an entity class.
      Parameters:
      entityClass - The entity class to be processed.
      Returns:
      The extracted Table annotation.
      Throws:
      MissingTableAnnotationException - If the entity class lacks a Table annotation.
    • hasCompositePrimaryKey

      private static boolean hasCompositePrimaryKey(Class<? extends Entity> entityClass)
      Determines if an entity class has a composite primary key (multiple Column fields marked as primary keys).
      Parameters:
      entityClass - The entity class to check.
      Returns:
      true if the class has multiple primary key fields, false otherwise.