Class IdDefinition
This class encapsulates metadata about an ID field in an object, including:
- The name of the ID generator to use
- The field that should receive the generated ID
- The type of the ID field (String, Long, Integer, etc.)
The ID definition is used by the CosId accessor framework to automatically inject generated IDs into objects when they are processed. This enables automatic ID assignment without requiring explicit code in the application.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IdDefinitionA sentinel value representing a "not found" ID definition. -
Constructor Summary
ConstructorsConstructorDescriptionIdDefinition(Field idField) Create a new ID definition with the default shared generator.IdDefinition(String generatorName, Field idField) Create a new ID definition with the specified generator name.IdDefinition(String generatorName, Field idField, Class<?> idType) Create a new ID definition with all parameters specified. -
Method Summary
Modifier and TypeMethodDescriptionGet the name of the ID generator to use for this field.Get the field that should receive the generated ID.Class<?>Get the type of the ID field.
-
Field Details
-
NOT_FOUND
A sentinel value representing a "not found" ID definition.This is used when no valid ID field can be found in an object, allowing the framework to handle missing ID fields gracefully without null checks.
-
-
Constructor Details
-
IdDefinition
Create a new ID definition with the default shared generator.This constructor creates an ID definition that uses the shared ID generator (
IdGeneratorProvider.SHARE) to generate IDs for the specified field.- Parameters:
idField- The field that should receive the generated ID
-
IdDefinition
Create a new ID definition with the specified generator name.This constructor creates an ID definition that uses the named ID generator to generate IDs for the specified field. The field's type is inferred from the field itself.
- Parameters:
generatorName- The name of the ID generator to useidField- The field that should receive the generated ID
-
IdDefinition
Create a new ID definition with all parameters specified.This constructor creates an ID definition with explicit control over all aspects: generator name, target field, and field type.
- Parameters:
generatorName- The name of the ID generator to useidField- The field that should receive the generated IDidType- The type of the ID field
-
-
Method Details
-
getGeneratorName
Get the name of the ID generator to use for this field.- Returns:
- The name of the ID generator
-
getIdField
Get the field that should receive the generated ID.- Returns:
- The field that should receive the generated ID
-
getIdType
Get the type of the ID field.- Returns:
- The type of the ID field
-