Class TableProcessor
java.lang.Object
dimstyl.orm.internal.processors.TableProcessor
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
determineTableName
(Table table, String entityClassName) Determines the table name based on theTable
annotation or defaults to a formatted class name.(package private) static TableMetadata
extractMetadata
(Class<? extends Entity> entityClass, DatabaseEngine databaseEngine) Extracts table metadata from an entity class.private static Table
extractTableAnnotation
(Class<? extends Entity> entityClass) Extracts theTable
annotation from an entity class.private static boolean
hasCompositePrimaryKey
(Class<? extends Entity> entityClass) Determines if an entity class has a composite primary key (multipleColumn
fields marked as primary keys).mapFieldsToColumns
(Class<? extends Entity> entityClass) Maps entity class fields to their corresponding table column names.static String
resolvePrimaryKeyColumnName
(Class<? extends Entity> entityClass) Resolves the primary key column name for a given entity class.(package private) static String
resolveTableName
(Class<? extends Entity> entityClass) Resolves the table name for a given entity class.
-
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 withTable
.databaseEngine
- TheDatabaseEngine
used for column type resolution.- Returns:
TableMetadata
containing table details.- Throws:
MissingTableAnnotationException
- If the entity class lacks theTable
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 aColumn
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 aColumn
annotation.
-
resolveTableName
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
-
extractTableAnnotation
private static Table extractTableAnnotation(Class<? extends Entity> entityClass) throws MissingTableAnnotationException Extracts theTable
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 aTable
annotation.
-
hasCompositePrimaryKey
Determines if an entity class has a composite primary key (multipleColumn
fields marked as primary keys).- Parameters:
entityClass
- The entity class to check.- Returns:
true
if the class has multiple primary key fields,false
otherwise.
-