Class FetchDBMethodGenerator

All Implemented Interfaces:
MethodGenerator
Direct Known Subclasses:
EntityDBFetcherMethodGenerator, FetchCountDBMethodGenerator, FetchMultiTableDBMethodGenerator, FetchNodeImplementationDBMethodGenerator, FetchSingleTableInterfaceDBMethodGenerator, NestedFetchDBMethodGenerator

public abstract class FetchDBMethodGenerator extends DBMethodGenerator<ObjectField>
Abstract generator for various database fetching methods.
  • Field Details

    • ELEMENT_NAME

      protected static final String ELEMENT_NAME
    • resolverKeyParamName

      protected final String resolverKeyParamName
    • isRoot

      protected final boolean isRoot
  • Constructor Details

  • Method Details

    • getInitialKey

      protected no.sikt.graphitron.javapoet.CodeBlock getInitialKey(FetchContext context)
    • createSelectJoins

      protected no.sikt.graphitron.javapoet.CodeBlock createSelectJoins(Set<SQLJoinStatement> joinList)
      Parameters:
      joinList - List of join statements that should be applied to a select query.
      Returns:
      Code block containing all the join statements and their conditions.
    • createSelectJoins

      protected no.sikt.graphitron.javapoet.CodeBlock createSelectJoins(Set<SQLJoinStatement> joinList, boolean skipFirstJoin)
      Parameters:
      joinList - List of join statements that should be applied to a select query.
      skipFirstJoin - Whether to skip the first join statement. Used in multitable resolver queries where the first join is implicit via .from(keyPath), unless it's a condition reference.
      Returns:
      Code block containing all the join statements and their conditions.
    • createSelectConditions

      protected no.sikt.graphitron.javapoet.CodeBlock createSelectConditions(List<no.sikt.graphitron.javapoet.CodeBlock> conditionList, boolean hasWhere)
      Parameters:
      conditionList - List of conditional statements that should be appended after the where-statement.
      Returns:
      Code block which declares all the extra conditions that will be used in a select query.
    • createAliasDeclarations

      protected static no.sikt.graphitron.javapoet.CodeBlock createAliasDeclarations(Set<AliasWrapper> aliasSet)
      Parameters:
      aliasSet - Set of aliases to be defined.
      Returns:
      Code block which declares all the aliases that will be used in a select query.
    • createAliasDeclarations

      protected static no.sikt.graphitron.javapoet.CodeBlock createAliasDeclarations(Set<AliasWrapper> aliasSet, boolean skipFirstAlias)
      Parameters:
      aliasSet - Set of aliases to be defined.
      skipFirstAlias - Whether to skip the first alias declaration. Used in multitable resolver queries where the source table alias is already declared in the main method and passed to the helper methods.
      Returns:
      Code block which declares all the aliases that will be used in a select query.
    • generateCorrelatedSubquery

      protected no.sikt.graphitron.javapoet.CodeBlock generateCorrelatedSubquery(GenerationField field, FetchContext context)
    • getHelperMethodCallForNestedField

      protected no.sikt.graphitron.javapoet.CodeBlock getHelperMethodCallForNestedField(ObjectField field, FetchContext context)
      Override this method to provide a helper method call for nested record type fields. Return null to use inline generation.
    • wrapInMultiset

      protected no.sikt.graphitron.javapoet.CodeBlock wrapInMultiset(no.sikt.graphitron.javapoet.CodeBlock contents)
    • wrapInField

      protected no.sikt.graphitron.javapoet.CodeBlock wrapInField(no.sikt.graphitron.javapoet.CodeBlock contents)
    • generateSelectRow

      protected no.sikt.graphitron.javapoet.CodeBlock generateSelectRow(FetchContext context)
      This method recursively generates one single row method call. It deduces how each layer of row call should be structured by keeping track of joins and following field references.
      Returns:
      Code block which contains the entire recursive structure of the row statement.
    • getSelectCodeAndFieldSource

      protected org.apache.commons.lang3.tuple.Pair<no.sikt.graphitron.javapoet.CodeBlock,String> getSelectCodeAndFieldSource(GenerationField field, FetchContext context)
    • createMapping

      protected no.sikt.graphitron.javapoet.CodeBlock createMapping(FetchContext context, List<? extends GenerationField> fieldsWithoutSplitting, HashMap<String,String> referenceFieldSources, List<no.sikt.graphitron.javapoet.CodeBlock> rowElements, LinkedHashSet<KeyWrapper> keySet)
    • generateForField

      protected no.sikt.graphitron.javapoet.CodeBlock generateForField(GenerationField field, FetchContext context)
      Generate a single argument in the row method call.
    • generateForField

      protected no.sikt.graphitron.javapoet.CodeBlock generateForField(GenerationField field, FetchContext context, boolean overrideEnum)
      Generate a single argument in the row method call.
    • generateForUnionField

      protected no.sikt.graphitron.javapoet.CodeBlock generateForUnionField(GenerationField field, FetchContext context)
      Generate select row for each object within the union field
    • formatWhereContents

      protected no.sikt.graphitron.javapoet.CodeBlock formatWhereContents(FetchContext context, String resolverKeyParamName, boolean isRoot, boolean isResolverRoot)
      Returns:
      Formatted CodeBlock for the where-statement and surrounding code. Applies conditions and joins.
    • getInputConditions

      @NotNull protected @NotNull InputConditions getInputConditions(ObjectField referenceField)
    • inferFieldNamingConvention

      protected String inferFieldNamingConvention(GenerationField field)
    • createSeekAndLimitBlock

      protected no.sikt.graphitron.javapoet.CodeBlock createSeekAndLimitBlock()
    • createOrderFieldsDeclarationBlock

      protected no.sikt.graphitron.javapoet.CodeBlock createOrderFieldsDeclarationBlock(ObjectField referenceField, String actualRefTable, String tableName)
    • createOrderFieldsBlock

      protected no.sikt.graphitron.javapoet.CodeBlock createOrderFieldsBlock(ObjectField referenceField, String actualRefTable, String tableName)
    • getSpecBuilder

      @NotNull protected no.sikt.graphitron.javapoet.MethodSpec.Builder getSpecBuilder(ObjectField referenceField, no.sikt.graphitron.javapoet.TypeName refTypeName, InputParser parser)