Class IdDefinition

java.lang.Object
me.ahoo.cosid.accessor.IdDefinition

public class IdDefinition extends Object
ID definition that describes how an ID field should be handled.

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 Details

    • NOT_FOUND

      public static final IdDefinition 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

      public IdDefinition(Field idField)
      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

      public IdDefinition(String generatorName, Field idField)
      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 use
      idField - The field that should receive the generated ID
    • IdDefinition

      public IdDefinition(String generatorName, Field idField, Class<?> idType)
      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 use
      idField - The field that should receive the generated ID
      idType - The type of the ID field
  • Method Details

    • getGeneratorName

      public String getGeneratorName()
      Get the name of the ID generator to use for this field.
      Returns:
      The name of the ID generator
    • getIdField

      public Field getIdField()
      Get the field that should receive the generated ID.
      Returns:
      The field that should receive the generated ID
    • getIdType

      public Class<?> getIdType()
      Get the type of the ID field.
      Returns:
      The type of the ID field