Class NestedFetchDBMethodGenerator

All Implemented Interfaces:
MethodGenerator
Direct Known Subclasses:
EntitySelectHelperDBMethodGenerator, NodeSelectHelperDBMethodGenerator, SelectHelperDBMethodGenerator

public abstract class NestedFetchDBMethodGenerator extends FetchDBMethodGenerator
Abstract base class for generators that create nested helper methods for database query generation.

This class provides the infrastructure and logic for generating private static helper methods that extract SelectField row mapping logic for record types. Helper methods improve compilation performance by reducing method complexity and enable reuse of mapping logic across different query contexts.

Subclasses (like FetchMappedObjectDBMethodGenerator) extend this to generate the main query methods while inheriting all helper method generation capabilities and shared state management.

Helper Method Generation Rules:

  • Helper methods are generated for record types with tables, list fields, or fields with @reference
  • Error types (marked with @error) never generate helpers
  • Split queries receive the target table as a parameter
  • Other fields receive base table parameters with alias declarations in the method body
  • Only aliases actually referenced in the generated SELECT are declared
  • Circular references are detected and prevented using visited type tracking
  • Input parameters are omitted from split query helpers (applied at main method level)

Special Patterns:

  • Container Pattern - At depth 0, non-table types with input arguments traverse directly to nested fields without generating a helper (e.g., FilmContainer wrapping Film query)
  • Wrapper Types - Non-table singular types without @reference recurse to children without generating helpers (e.g., LanguageWrapper.originalLanguage)
  • Helper Naming - Nested helpers use parent method name as prefix with depth indicators (e.g., queryForQuery_customer_d1_address). Uniqueness ensured with counters for duplicate paths.

State Management:

This class maintains shared state (NestedFetchDBMethodGenerator.MethodGenerationState, NestedFetchDBMethodGenerator.HelperGenerationContext) that is accessible to subclasses during method generation to ensure consistent naming and proper depth tracking for nested helper methods.
See Also:
  • Constructor Details

  • Method Details

    • generate

      public no.sikt.graphitron.javapoet.MethodSpec generate(ObjectField field)
      Specified by:
      generate in class AbstractSchemaMethodGenerator<ObjectField,ObjectDefinition>
      Returns:
      The complete javapoet MethodSpec based on the provided target.
    • generateNested

      public List<no.sikt.graphitron.javapoet.MethodSpec> generateNested(ObjectField field)
    • getHelperMethodCallForNestedField

      protected no.sikt.graphitron.javapoet.CodeBlock getHelperMethodCallForNestedField(ObjectField field, FetchContext context)
      Description copied from class: FetchDBMethodGenerator
      Generates a helper method call for nested record type fields. This base implementation generates the root-level helper method call.
      Overrides:
      getHelperMethodCallForNestedField in class FetchDBMethodGenerator
      Parameters:
      field - The field to generate the helper method call for
      context - The fetch context (unused in base implementation)
      Returns:
      CodeBlock containing the helper method call, or null to use inline generation