Class FieldColumnSpecBuilder

java.lang.Object
org.litebridgedb.orm.api.register.FieldColumnSpecBuilder

public final class FieldColumnSpecBuilder extends Object
A builder for specifying mappings between fields or properties in a DTO (Data Transfer Object) and database expressions. This class is part of the fluent API for creating field-to-column mapping specifications in the ORM framework.

The mappings allow developers to configure how fields or properties should map to database structures, including basic field-column mappings, property-based mappings, and advanced relations such as one-to-many and many-to-many associations.

This builder facilitates a multi-step configuration process where each method represents a specific stage in defining the field-column specification. The result of the configuration is encapsulated in a FieldColumnSpec, which can later be used for persistence or ORM-related operations.

The following steps summarise how this builder operates:

  • A field or property in a DTO is mapped to begin configuration using mapField or mapProperty.
  • Subsequent methods allow specifying database column names, or defining relationships like one-to-many or many-to-many.
  • The resulting configuration is finalised and returned as a complete, immutable spec.

This class supports the creation of specifications using a declarative and type-safe approach. Any ambiguities and potential misconfigurations are resolved at runtime while ensuring a fluent, readable API design.

  • Constructor Details

    • FieldColumnSpecBuilder

      public FieldColumnSpecBuilder()
  • Method Details

    • mapField

      public FieldColumnSpecBuilderFieldStep mapField(String fieldName)
      Maps a specific field in a DTO to begin the configuration process for defining its database column mapping. This is the initial step of the field-to-column mapping process using the builder.
      Parameters:
      fieldName - The name of the field in the DTO to be mapped. This name should correspond to the field in the DTO class and must not be null.
      Returns:
      An instance of FieldColumnSpecBuilderFieldStep to continue the configuration of the field mapping.
    • mapProperty

      public FieldColumnSpecBuilderFieldStep mapProperty(String fieldName)
      Maps a specific property in a DTO to begin the configuration process for defining its database property-based mapping. This method assumes property-level access using getter and setter conventions in the DTO class.
      Parameters:
      fieldName - The name of the property in the DTO to be mapped. This name should correspond to the property in the DTO class and must not be null.
      Returns:
      An instance of FieldColumnSpecBuilderFieldStep to continue the configuration of the property mapping.
    • spec

      Constructs a FieldColumnSpec by applying a function to a FieldColumnSpecBuilder. The function defines the steps and configuration for mapping a field or property in a DTO to its corresponding database column or table specification.
      Parameters:
      rc - A function that accepts a FieldColumnSpecBuilder and returns a FieldColumnSpecBuilderTerminal. This function defines the sequence of steps required to configure the field-to-column mapping.
      Returns:
      A FieldColumnSpec representing the finalised mapping between the DTO field or property and the database column or table specification.