Class NodeIdReferenceHelpers

java.lang.Object
no.sikt.graphitron.generators.context.NodeIdReferenceHelpers

public class NodeIdReferenceHelpers extends Object
Utility methods for determining whether a @nodeId field is a cross-table reference and resolving the foreign key and column mappings needed for the generated code.
  • Constructor Details

    • NodeIdReferenceHelpers

      public NodeIdReferenceHelpers()
  • Method Details

    • isNodeIdReferenceField

      public static boolean isNodeIdReferenceField(GenerationField field, ProcessedSchema schema, JOOQMapping currentTable)
      Determines whether a @nodeId field is a reference. Returns true when the field has explicit @reference directives, or when its node type's target table differs from currentTable.
      Parameters:
      field - the @nodeId field
      schema - the processed schema.
      currentTable - the current table in which the field is currently being resolved, or null if unknown.
      Returns:
      true if the field references a node on a different table.
    • isNodeIdReferenceField

      public static boolean isNodeIdReferenceField(ObjectField objectField, ProcessedSchema schema)
      Determines whether a @nodeId field is a reference by resolving the current table from the field's container type or its previous table object.
      Parameters:
      objectField - the @nodeId object field
      schema - the processed schema.
      Returns:
      true if the field references a node on a different table than its previous table.
      See Also:
    • resolveColumnNamesForNodeIdField

      public static List<String> resolveColumnNamesForNodeIdField(GenerationField field, ProcessedSchema schema, JOOQMapping currentTable)
      Returns the Java column names to use for a @nodeId field given the current table context. For references, maps the node's key columns through the foreign key to the current table's columns. Returns the node configuration's key columns directly if the field is not a reference.
      Parameters:
      field - the field carrying the @nodeId directive.
      schema - the processed schema.
      currentTable - the current table in which the field is currently being resolved, or null if unknown.
      Returns:
      ordered list of Java column names for the key fields.
    • findForeignKeyForNodeIdField

      public static Optional<org.jooq.ForeignKey<?,?>> findForeignKeyForNodeIdField(GenerationField field, ProcessedSchema schema, JOOQMapping currentTable)
      Resolves the foreign key connecting currentTable to the node type's target table for a @nodeId reference field. Returns empty if the field is not a reference.
      Parameters:
      field - the @nodeId field
      schema - the processed schema.
      currentTable - the current table in which the field is currently being resolved, or null if unknown.
      Returns:
      the foreign key, or empty if the field is not a reference.