Class FWSimResourceTransformer

All Implemented Interfaces:
FWSimFieldContainer
Direct Known Subclasses:
DefaultRuleTransformer, DefaultSQLStatementTransformer

public abstract class FWSimResourceTransformer extends FWSimInputAdapter
Base class of the resource transformers (transform element). A transformer derives a new table from the cache of another resource (attribute resource), e.g. by an SQL statement, a rule or an aggregation, and provides it as its own FWSimResourceCache. The transformer is configured by input variables (input children with a value or a source rule). The data is only recalculated if the source data or the input values changed (see isUpdated(FWSimVarMap)).
Author:
Andreas Enders
See Also:
  • Field Details

    • iIntColumnMap

      protected LinkedHashMap<Integer, ColumnData> iIntColumnMap
      columns of the result table in database order
    • iSourceName

      protected String iSourceName
      name of the source resource whose cache is transformed
    • iPoolName

      protected final String iPoolName
      name of the database connection pool (attribute interface, default: the default pool of the solution)
    • iFieldMap

      protected HashMap<String, FWSimVariable<?>> iFieldMap
      input variables of the transformer by full name (<transformer>.<id>)
    • iLastInputValuesMap

      protected HashMap<FWSimVariable<?>, Object> iLastInputValuesMap
      values of the input variables at the last check, to detect changes
    • iLastUniqueID

      protected String iLastUniqueID
      unique id of the source data at the last update, to detect changed source data
    • iLastProjectID

      protected String iLastProjectID
      id of the project at the last update
  • Constructor Details

    • FWSimResourceTransformer

      protected FWSimResourceTransformer(FWSimSession aSession, org.jdom2.Element aResourceElement, Integer aOrderNumber)
      Creates the transformer from its element: creates the input variables and sets their values (element text) or rules (attribute source).
      Parameters:
      aSession - the session
      aResourceElement - the transform element
      aOrderNumber - order number of the transformer
    • FWSimResourceTransformer

      protected FWSimResourceTransformer(FWSimSession aSession, Integer aOrderNumber)
      Creates a transformer without element (e.g. new transformer in the graph panel, documentation): an empty transform element with the name given to createResourceTransformer(FWSimSession, String, Integer, String) (default NewTransformer) is used.
      Parameters:
      aSession - the session, may be null
      aOrderNumber - order number of the transformer
    • FWSimResourceTransformer

      protected FWSimResourceTransformer()
      Constructor for instantiation via reflection (see createSimTransformer(String)), e.g. for the documentation.
  • Method Details

    • createResourceTransformer

      public static FWSimResourceTransformer createResourceTransformer(FWSimSession aSession, String aClassName, Integer aOrderNumber)
      Factory method used by the graph panel: creates a transformer of the given class via its constructor (FWSimSession, Integer), named after the simple class name. Errors are logged.
      Parameters:
      aSession - the session
      aClassName - full class name of the transformer
      aOrderNumber - order number of the transformer
      Returns:
      the transformer, or null if it cannot be created
    • createResourceTransformer

      public static FWSimResourceTransformer createResourceTransformer(FWSimSession aSession, String aClassName, Integer aOrderNumber, String aName)
      Factory method used by the graph panel: creates a transformer of the given class via its constructor (FWSimSession, Integer) with the given name. Errors are logged.
      Parameters:
      aSession - the session
      aClassName - full class name of the transformer
      aOrderNumber - order number of the transformer
      aName - name (id) of the transformer, or null for the simple class name
      Returns:
      the transformer, or null if it cannot be created
    • createResourceTransformer

      public static FWSimResourceTransformer createResourceTransformer(String aClassName)
      Factory method for documentation purposes: like createResourceTransformer(FWSimSession, String, Integer) without session and with order number 0.
      Parameters:
      aClassName - full class name of the transformer
      Returns:
      the transformer, or null if it cannot be created
    • createResourceTransformer

      public static FWSimResourceTransformer createResourceTransformer(FWSimSession aSession, org.jdom2.Element aTransformElement, Integer aOrderNumber) throws DuplicateSimFieldException
      Factory method: creates the transformer of the class given in the attribute class via its constructor (FWSimSession, Element, Integer). Instantiation errors are logged.
      Parameters:
      aSession - the session
      aTransformElement - the transform element
      aOrderNumber - order number of the transformer
      Returns:
      the transformer, or null if it cannot be created
      Throws:
      DuplicateSimFieldException - if a resource with the same id already exists
    • getSourceResourceCache

      protected FWSimResourceCache getSourceResourceCache(FWSimVarMap aVarMap)
      Parameters:
      aVarMap - variable map of the simulation (provides the session)
      Returns:
      the cache of the source resource, or null if it has no data
    • isUpdated

      public boolean isUpdated(FWSimVarMap aVarMap)
      Checks whether the transformer has to recalculate its data. This is the case if the input values changed, the source data changed (other unique id), or the source is a transformer that was updated. Without source cache, a new project or changed inputs cause an update. The remembered unique id and project id are updated.

      Note: the last condition also updates when the project id is equal to the last one. This method is called once per project by the resource manager (new project id, so the condition has no effect there) and a second time by a transformer that uses this transformer as source; in that second call the condition reports an update, so the dependent transformer is always recalculated (safe, but not optimal).

      Parameters:
      aVarMap - variable map of the first simulation of the project
      Returns:
      true if the data has to be recalculated
    • fillVarMap

      @Deprecated public void fillVarMap(FWSimVarMap aVarMap)
      Deprecated.
      not used; the resource manager fills the variable maps from the caches
      Copies the current data line of the cache of this transformer into the variable map.
      Parameters:
      aVarMap - variable map of the simulation
    • toXML

      public org.jdom2.Element toXML()
      Creates the transform element with id, interface, frequency, source resource, class, header and one input element per input variable (with its current value).
      Returns:
      an XML element with all settings of this container
      See Also:
    • getCreateFormXML

      public final org.jdom2.Element getCreateFormXML()
      Returns the form of this transformer, see createFormFields(FWSimResourceTransformer).
      Specified by:
      getCreateFormXML in interface FWSimFieldContainer
      Overrides:
      getCreateFormXML in class FWSimIOAdapter
      Returns:
      the XML form definition used by the GUI to create this container
      See Also:
    • getEditFormXML

      public org.jdom2.Element getEditFormXML(boolean aEnabled)
      Returns the form of this transformer, see createFormFields(FWSimResourceTransformer). aEnabled is not used.
      Specified by:
      getEditFormXML in interface FWSimFieldContainer
      Overrides:
      getEditFormXML in class FWSimIOAdapter
      Parameters:
      aEnabled - if false, the form fields are read-only
      Returns:
      the XML form definition used by the GUI to edit the settings of this container
      See Also:
    • createFormFields

      public org.jdom2.Element createFormFields(FWSimResourceTransformer aTransformer)
      Creates the edit form of a transformer: name and class (editable only for a new transformer), a choice of the input variables and one field group per input variable, shown when it is chosen.
      Parameters:
      aTransformer - the transformer, or null for a new one (then only name and class are shown)
      Returns:
      the form element
    • addVariable

      public void addVariable(FWSimVariable<?> aVariable)
      Adds an input variable under its full name.
      Specified by:
      addVariable in interface FWSimFieldContainer
      Overrides:
      addVariable in class FWSimIOAdapter
      Parameters:
      aVariable - the variable to add
      See Also:
    • getVariable

      public FWSimVariable<?> getVariable(String aKey)
      Returns an input variable.
      Specified by:
      getVariable in interface FWSimFieldContainer
      Overrides:
      getVariable in class FWSimIOAdapter
      Parameters:
      aKey - id of the input without the transformer name
      Returns:
      the input variable, or null if unknown
      See Also:
    • updateFields

      public abstract void updateFields(FWObservable aObservable)
      Takes the values of the edit form into the transformer.
      Parameters:
      aObservable - the form data
    • createSimTransformer

      public static FWSimResourceTransformer createSimTransformer(String aClassname)
      Creates a transformer via its constructor without parameters, e.g. for the documentation of all transformers. Errors are logged.
      Parameters:
      aClassname - full class name of the transformer
      Returns:
      the transformer, or null for abstract classes or if it cannot be created
    • toDocXML

      public org.jdom2.Element toDocXML()
      Creates the XML for the documentation: a transform element with the class and the input variables defined by this transformer, sorted.
      Returns:
      the documentation element