Class DefaultAutoMappingPolicy

java.lang.Object
de.calamanari.adl.sql.config.DefaultAutoMappingPolicy
All Implemented Interfaces:
AutoMappingPolicy, Serializable

public class DefaultAutoMappingPolicy extends Object implements AutoMappingPolicy
The DefaultAutoMappingPolicy maps arguments to columns with a template-based approach and an extractor operator.

If the extractor returns a non-null value (policy applies to this argName), then a copy of the template with the adjusted argName will be returned.

Example: You want to map any structured argName varName.int to column XYZ of type SQL INTEGER with the qualifier column Q17 set to the argName. Then you can configure a predicate like s -> s.endsWith(".int") ? s.substring(0, s.length()-4 : null and configure the target column with the filter column value set to ${argName.local}, see "${argName.local}".

The convenience variable ${argName.local} covers the very common demand to decode a single identifier from the argName.
However, if you need advanced extraction (e.g., you want to extract multiple variables from an argName like "org7.section9.dep34.int"), then you can subclass DefaultAutoMappingPolicy and overwrite prepareVariables(String, ConversionSettings).

This way you can map a whole category of variables to columns without knowing and listing them beforehand.

Author:
Karl Eilebrecht
See Also:
  • Field Details

    • VAR_ARG_NAME_LOCAL

      public static final String VAR_ARG_NAME_LOCAL
      Dynamic variable that can be specified as a filterValue to tell the system to replace it at runtime with the value of the global variable argName.local (if present). By default this value will be set by this policy right before processing the filter condition setup (parameter creation), so the value will be the result of this instances extractor function.
      See Also:
    • ARG_NAME_LOCAL_PLACEHOLDER

      public static final String ARG_NAME_LOCAL_PLACEHOLDER
      Reference to the variable "argName.local"
      See Also:
    • NONE

      public static final AutoMappingPolicy NONE
      Configuration element if no policy is defined to avoid null
    • assignmentTemplate

      protected final ArgColumnAssignment assignmentTemplate
      At runtime we return the same mapping for all matching argNames, argMetaInfo updated with the current argName
    • extractorFunction

      protected final DefaultAutoMappingPolicy.LocalArgNameExtractor extractorFunction
      The function that extracts the "${argName.local}" from the argName
  • Constructor Details

  • Method Details

    • isApplicable

      public boolean isApplicable(String argName)
      Description copied from interface: AutoMappingPolicy
      Returns whether this mapping policy can map the given argument to a column
      Specified by:
      isApplicable in interface AutoMappingPolicy
      Parameters:
      argName -
      Returns:
      true if the policy is applicable
    • prepareVariables

      protected void prepareVariables(String argName, de.calamanari.adl.ProcessContext ctx)
      This TEMPLATE METHOD allows sub-classes to compute and set further global variables which can then be referenced inside the mapping process.

      Example: Let the argName be structured org.section.department and you want to pass the department as a filter column value.
      Simply extract (parse) the qualifier from the argName in this method and put it as a global variable department into the settings.
      Now you can reference it in a filter column value, e.g., SEC/${department} like any other variable.

      By default this method calls the extractor function and sets the global variable "${argName.local}" to the value extracted from the argName.

      Parameters:
      argName -
      ctx - to obtain and set variables
    • map

      public ArgColumnAssignment map(String argName, de.calamanari.adl.ProcessContext ctx)
      Description copied from interface: AutoMappingPolicy
      Returns the column assignment for the given argName
      Specified by:
      map in interface AutoMappingPolicy
      Parameters:
      argName -
      ctx -
      Returns:
      column assignment