Package no.sikt.graphitron.generators.db
Class FetchDBMethodGenerator
java.lang.Object
no.sikt.graphitron.generators.abstractions.AbstractSchemaMethodGenerator<ObjectField,ObjectDefinition>
no.sikt.graphitron.generators.abstractions.DBMethodGenerator<ObjectField>
no.sikt.graphitron.generators.db.FetchDBMethodGenerator
- All Implemented Interfaces:
MethodGenerator
- Direct Known Subclasses:
FetchCountDBMethodGenerator,FetchEntityImplementationDBMethodGenerator,FetchMappedObjectDBMethodGenerator,FetchMultiTableDBMethodGenerator,FetchNodeImplementationDBMethodGenerator,FetchSingleTableInterfaceDBMethodGenerator,NestedFetchDBMethodGenerator,UpdateWithReturningDBMethodGenerator
Abstract generator for various database fetching methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected static final Stringprotected final StringFields inherited from class no.sikt.graphitron.generators.abstractions.AbstractSchemaMethodGenerator
dependencyMap, localObject, processedSchema -
Constructor Summary
ConstructorsConstructorDescriptionFetchDBMethodGenerator(ObjectDefinition localObject, ProcessedSchema processedSchema) FetchDBMethodGenerator(ObjectDefinition localObject, ProcessedSchema processedSchema, boolean conditionsShouldFallbackToFalse) -
Method Summary
Modifier and TypeMethodDescriptionprotected static no.sikt.graphitron.javapoet.CodeBlockcreateAliasDeclarations(Set<AliasWrapper> aliasSet) protected static no.sikt.graphitron.javapoet.CodeBlockcreateAliasDeclarations(Set<AliasWrapper> aliasSet, boolean skipFirstAlias) protected no.sikt.graphitron.javapoet.CodeBlockcreateOrderFieldsBlock(ObjectField referenceField, String actualRefTable, String tableName) protected no.sikt.graphitron.javapoet.CodeBlockcreateOrderFieldsDeclarationBlock(ObjectField referenceField, String actualRefTable, String tableName) protected no.sikt.graphitron.javapoet.CodeBlockprotected no.sikt.graphitron.javapoet.CodeBlockcreateSelectConditions(List<no.sikt.graphitron.javapoet.CodeBlock> conditionList, boolean hasWhere) protected no.sikt.graphitron.javapoet.CodeBlockcreateSelectJoins(Set<SQLJoinStatement> joinList) protected no.sikt.graphitron.javapoet.CodeBlockcreateSelectJoins(Set<SQLJoinStatement> joinList, boolean skipFirstJoin) protected static no.sikt.graphitron.javapoet.CodeBlockformatJooqConditions(ArrayList<no.sikt.graphitron.javapoet.CodeBlock> conditionList, String chainMethod) protected no.sikt.graphitron.javapoet.CodeBlockformatWhereContents(FetchContext context, boolean isDataFetcherRoot) protected no.sikt.graphitron.javapoet.CodeBlockgenerateCorrelatedSubquery(FetchContext context) protected no.sikt.graphitron.javapoet.CodeBlockgenerateForField(GenerationField field, FetchContext context) Generate a single argument in the row method call.protected no.sikt.graphitron.javapoet.CodeBlockgenerateForField(GenerationField field, FetchContext context, boolean overrideEnum) Generate a single argument in the row method call.protected no.sikt.graphitron.javapoet.CodeBlockgenerateForUnionField(GenerationField field, FetchContext context) Generate select row for each object within the union fieldprotected StringgenerateHelperMethodName(ObjectField target) protected StringgenerateNestedMethodName(String parentHelperMethodName, String fieldName) Generates a method name.protected no.sikt.graphitron.javapoet.CodeBlockgenerateSelectRow(FetchContext context) This method recursively generates one single row method call.protected no.sikt.graphitron.javapoet.CodeBlockgetHelperMethodCallForNestedField(ObjectField field, FetchContext context) Generates a helper method call for nested record type fields.protected no.sikt.graphitron.javapoet.CodeBlockgetInitialKey(FetchContext context) protected List<no.sikt.graphitron.javapoet.CodeBlock> getInputConditions(FetchContext context, ObjectField sourceField) Returns condition code blocks for a field which is assumed to only have input conditions, and no set values.protected @NotNull no.sikt.graphitron.javapoet.TypeNamegetReturnType(ObjectField referenceField, no.sikt.graphitron.javapoet.TypeName refClassName) protected no.sikt.graphitron.javapoet.CodeBlockgetSelectCode(GenerationField field, FetchContext context) protected no.sikt.graphitron.javapoet.MethodSpec.BuildergetSpecBuilder(ObjectField referenceField, no.sikt.graphitron.javapoet.TypeName refTypeName, InputParser parser) protected Stringprotected booleanisRoot()protected no.sikt.graphitron.javapoet.CodeBlockwrapInField(no.sikt.graphitron.javapoet.CodeBlock contents) protected no.sikt.graphitron.javapoet.CodeBlockwrapInMultiset(no.sikt.graphitron.javapoet.CodeBlock contents) Methods inherited from class no.sikt.graphitron.generators.abstractions.DBMethodGenerator
getDefaultSpecBuilder, getDefaultSpecBuilderMethods inherited from class no.sikt.graphitron.generators.abstractions.AbstractSchemaMethodGenerator
createServiceDependency, declareAllServiceClasses, declareAllServiceClasses, declareAllServiceClassesInAliasSet, generate, getDataFetcherWiring, getDependencyMap, getLocalObject, getLocalTable, getTypeResolverWiringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface no.sikt.graphitron.generators.abstractions.MethodGenerator
generateAll
-
Field Details
-
ELEMENT_NAME
-
resolverKeyParamName
-
conditionsShouldFallbackToFalse
protected final boolean conditionsShouldFallbackToFalse
-
-
Constructor Details
-
FetchDBMethodGenerator
public FetchDBMethodGenerator(ObjectDefinition localObject, ProcessedSchema processedSchema, boolean conditionsShouldFallbackToFalse) -
FetchDBMethodGenerator
-
-
Method Details
-
isRoot
protected boolean isRoot() -
getInitialKey
-
createSelectJoins
- 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.
-
getHelperMethodCallForNestedField
protected no.sikt.graphitron.javapoet.CodeBlock getHelperMethodCallForNestedField(ObjectField field, FetchContext context) Generates a helper method call for nested record type fields. This base implementation generates the root-level helper method call.- Parameters:
field- The field to generate the helper method call forcontext- The fetch context (unused in base implementation)- Returns:
- CodeBlock containing the helper method call, or 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
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.
-
getSelectCode
protected no.sikt.graphitron.javapoet.CodeBlock getSelectCode(GenerationField field, FetchContext context) -
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, boolean isDataFetcherRoot) - Returns:
- Formatted CodeBlock for the where-statement and surrounding code. Applies conditions and joins.
-
formatJooqConditions
-
getInputConditions
protected List<no.sikt.graphitron.javapoet.CodeBlock> getInputConditions(FetchContext context, ObjectField sourceField) Returns condition code blocks for a field which is assumed to only have input conditions, and no set values. -
inferFieldNamingConvention
-
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) -
getReturnType
@NotNull protected @NotNull no.sikt.graphitron.javapoet.TypeName getReturnType(ObjectField referenceField, no.sikt.graphitron.javapoet.TypeName refClassName) -
generateHelperMethodName
-
generateNestedMethodName
Generates a method name. Format: [parentHelperMethodName]_[fieldName] Example: queryForQuery_customer_storeInfo_staff
-