Class AbstractBusinessDomainMapper<B extends BusinessDomainObject,P extends Persistable>

java.lang.Object
de.seggebaeing.sqlanalyzer.logic.domainmapper.AbstractBusinessDomainMapper<B,P>
Type Parameters:
B - business domain object type
P - persistable DTO type
All Implemented Interfaces:
BusinessDomainMapper<B,P>
Direct Known Subclasses:
GeneratedQueryMapper, LLMMapper, PromptMapper, PromptTypeMapper, SampleQueryMapper

public abstract class AbstractBusinessDomainMapper<B extends BusinessDomainObject,P extends Persistable> extends Object implements BusinessDomainMapper<B,P>
Abstract base for bidirectional mapping between business domain objects (BDOs) and de.seggebaeing.sqlanalyzer.persistence DTOs.

Maintains identity-preserving caches in both directions to avoid duplicate mappings (BDO→DTO and DTO→BDO). Provides initialize(Supplier) to inject an ID supplier required by concrete mappers, and convenience methods putIntoMaps(B, P) / putIntoMaps(P, B) to register paired objects.

Since:
1.0
Author:
Felix Seggebäing
  • Field Details

    • cacheMapBDOtoDTO

      protected final Map<B extends BusinessDomainObject,P extends Persistable> cacheMapBDOtoDTO
      Identity cache mapping BDO → DTO to reuse mapped instances (not thread-safe).
    • cacheMapDTOtoBDO

      protected final Map<P extends Persistable,B extends BusinessDomainObject> cacheMapDTOtoBDO
      Identity cache mapping DTO → BDO to reuse mapped instances (not thread-safe).
    • idSupplier

      protected Supplier<Integer> idSupplier
      Supplier for generating new IDs; set via initialize(Supplier). Defaults to a lambda that throws an illegal state exception if used before initialization.
  • Constructor Details

    • AbstractBusinessDomainMapper

      public AbstractBusinessDomainMapper()
  • Method Details

    • putIntoMaps

      protected void putIntoMaps(B bdo, P dto)
      Registers a mapped pair in both caches (BDO→DTO and DTO→BDO). Requires non-null arguments.
      Parameters:
      bdo - the business object
      dto - the corresponding DTO
      Throws:
      NullPointerException - if any of the args are null
    • putIntoMaps

      protected void putIntoMaps(P dto, B bdo)
      Registers a mapped pair in both caches (DTO→BDO and BDO→DTO). Delegates to putIntoMaps(B, P).
      Parameters:
      dto - the DTO
      bdo - the corresponding business object
    • initialize

      public void initialize(Supplier<Integer> idSupplier)
      Initializes this mapper with a supplier for allocating new IDs.
      Specified by:
      initialize in interface BusinessDomainMapper<B extends BusinessDomainObject,P extends Persistable>
      Parameters:
      idSupplier - non-null supplier of unique IDs
      Throws:
      NullPointerException - if idSupplier is null