Class DefaultCosIdAccessor

java.lang.Object
me.ahoo.cosid.accessor.AbstractIdMetadata
me.ahoo.cosid.accessor.DefaultCosIdAccessor
All Implemented Interfaces:
CosIdAccessor, CosIdGetter, CosIdSetter, EnsureId, IdMetadata

public class DefaultCosIdAccessor extends AbstractIdMetadata implements CosIdAccessor
Default CosIdAccessor implementation.

Provides ID get/set operations on entities and ensures IDs are generated when missing. Supports Long, Integer, and String ID types.

  • Constructor Details

    • DefaultCosIdAccessor

      public DefaultCosIdAccessor(IdDefinition idDefinition, CosIdGetter getter, CosIdSetter setter)
      Creates a new accessor.
      Parameters:
      idDefinition - the ID definition
      getter - the getter for extracting ID from entities
      setter - the setter for setting ID on entities
  • Method Details

    • getId

      public Object getId(Object target)
      Description copied from interface: CosIdGetter
      Gets the ID value from the target object.
      Specified by:
      getId in interface CosIdGetter
      Parameters:
      target - the object to get ID from
      Returns:
      the ID value
    • setId

      public void setId(Object target, Object id)
      Description copied from interface: CosIdSetter
      Sets the ID value on the target object.
      Specified by:
      setId in interface CosIdSetter
      Parameters:
      target - the object to set ID on
      id - the ID value to set
    • getGetter

      public CosIdGetter getGetter()
      Gets the getter.
      Returns:
      the getter
    • getSetter

      public CosIdSetter getSetter()
      Gets the setter.
      Returns:
      the setter
    • ensureId

      public boolean ensureId(Object target)
      Description copied from interface: EnsureId
      Ensure that the target object has an ID set.
      Specified by:
      ensureId in interface EnsureId
      Parameters:
      target - target object
      Returns:
      Set successfully?