Class TableProcessor
java.lang.Object
dimstyl.orm.internal.processors.TableProcessor
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringdetermineTableName(Table table, String entityClassName) Determines the table name based on theTableannotation or defaults to a formatted class name.(package private) static TableMetadataextractMetadata(Class<? extends Entity> entityClass, DatabaseEngine databaseEngine) Extracts table metadata from an entity class.private static TableextractTableAnnotation(Class<? extends Entity> entityClass) Extracts theTableannotation from an entity class.private static booleanhasCompositePrimaryKey(Class<? extends Entity> entityClass) Determines if an entity class has a composite primary key (multipleColumnfields marked as primary keys).mapFieldsToColumns(Class<? extends Entity> entityClass) Maps entity class fields to their corresponding table column names.static StringresolvePrimaryKeyColumnName(Class<? extends Entity> entityClass) Resolves the primary key column name for a given entity class.(package private) static StringresolveTableName(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- TheDatabaseEngineused for column type resolution.- Returns:
TableMetadatacontaining table details.- Throws:
MissingTableAnnotationException- If the entity class lacks theTableannotation.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 aColumnannotation.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
Columnand 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 aColumnannotation.
-
resolveTableName
Resolves the table name for a given entity class.If the
Tableannotation 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 theTableannotation from an entity class.- Parameters:
entityClass- The entity class to be processed.- Returns:
- The extracted
Tableannotation. - Throws:
MissingTableAnnotationException- If the entity class lacks aTableannotation.
-
hasCompositePrimaryKey
Determines if an entity class has a composite primary key (multipleColumnfields marked as primary keys).- Parameters:
entityClass- The entity class to check.- Returns:
trueif the class has multiple primary key fields,falseotherwise.
-