Class ModificationContext

java.lang.Object
de.ubs.xdm.utils.modification.ScriptContext
de.ubs.xdm.utils.modification.ModificationContext

public class ModificationContext extends ScriptContext
Author:
Sven Schneider
  • Field Details

  • Constructor Details

    • ModificationContext

      public ModificationContext(de.ubs.xdm.utils.modification.ModificationInternalContext privateContext)
  • Method Details

    • getReportStream

      public static de.ubs.xdm.utils.modification.ModificationReportStream getReportStream()
      Returns:
      ModificationReportStream
    • indexOf

      public final int indexOf(String name)
      Returns the index of the column in the current table as it can be used as index against data
      Parameters:
      name - the name of the column
      Returns:
      the zero based index or -1 if column is not present
    • getRule

      public de.ubs.xdm.batch.client.model.ModificationRule getRule()
      Returns the rule, which was used to apply the modification method against this table.
      Returns:
      A MethodRule (useful methods String getColumnPattern(), String getTablePattern(), String getSchemaPattern())
    • buildPoolTable

      @Deprecated public void buildPoolTable(String methodName, String category, String url, String user, String password, String tableSchema, String tableName, String refreshInterval, String... columnNames) throws SQLException
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      This method uses the specified table in the respective database system to populate an internal pool table. The pool table name is build based on the specified category and method name.
      Parameters:
      methodName - The name of the modification method. This name is used to build the name of the pool table.
      category - The category of the modification method. This category is used to build the name of the pool table.
      url - The JDBC url in which the table is located that is used to populate the pool table.
      user - The JDBC user used to access the database system.
      password - The password for the user.
      tableSchema - The schema name of the table that is used as data source for the pool table.
      tableName - The table name that is used as data source for the pool table.
      refreshInterval - The refresh interval that controls if the data of the pool table should be refreshed or not.
      columnNames - List of columns that are used to populate the pool table.
      Throws:
      SQLException - the exception happened while building the table
    • buildShufflingPoolTable

      @Deprecated public void buildShufflingPoolTable(String methodName, String category, String url, String user, String password, String tableSchema, String tableName, String refreshInterval, String... columnNames) throws SQLException
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      This method uses the specified table in the respective database system to populate an internal pool table. The pool table name is build based on the specified category and method name.
      Parameters:
      methodName - The name of the modification method. This name is used to build the name of the pool table.
      category - The category of the modification method. This category is used to build the name of the pool table.
      url - The JDBC url in which the table is located that is used to populate the pool table.
      user - The JDBC user used to access the database system.
      password - The password for the user.
      tableSchema - The schema name of the table that is used as data source for the pool table.
      tableName - The table name that is used as data source for the pool table.
      refreshInterval - The refresh interval that controls if the data of the pool table should be refreshed or not.
      columnNames - List of columns that are used to populate the pool table.
      Throws:
      SQLException - the exception happened while building the table
    • getInvocations

      public long getInvocations()
      Get the number of invocations for a row of this context
      Returns:
      the number of invocations of this context
    • getOverallRuntime

      public long getOverallRuntime()
      The run time in milliseconds for this modification method in the given context
      Returns:
      the runtime of all invocations in complete
    • setData

      public void setData(int i, Object data)
      Sets the value in the current row.
      Parameters:
      i - The index of the column in the given table
      data - The data to be set. This must match the data type of the column that should receive the data and must correspond to one of the types defined in java.sql.SqlTypes.
    • put

      public void put(String name, Object value)
      Stores a value in scope of the current column. This allows you to store values over different rows while processing the column. The data will not be available in other tables that are processed by the same modification rule or method.
      Parameters:
      name - A symbolic name to store a value
      value - The value to be stored
    • get

      public Object get(String name)
      Retrieves a value from the store that works in the scope of one rule specified for a table. This method will return values written with the put() method.
      Parameters:
      name - The symbolic name of the stored value
      Returns:
      the value mapped for key, null if key is not found
    • createPoolTableIfNotExists

      @Deprecated public void createPoolTableIfNotExists(String poolTableName, Object[] data)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Creates pool table with given name of format category/name if not already existing. It acquires the column types by comparing given data with the source table. The given data may only contain those columns which are part of the pool table!
      Parameters:
      poolTableName - pool table name of format category/name.
      data - array of data containing the appropriate column types.
    • createPoolTableIfNotExists

      public void createPoolTableIfNotExists(String poolTableName, String mappedColumnNames)
      Creates pool table with given name of format category/name if not already existing. It fetches the column types out of the source table by comparing its columns with the given mappedColumns.
      Parameters:
      poolTableName - pool table name of format category/name.
      mappedColumnNames - string containing the column names for pool table.
    • specialMapping

      @Deprecated public Object specialMapping(Object data, String mappingName, String types, boolean takeRandom)
      Deprecated.
      method is substituted by poolMappingGet(Object data, String poolTableName, String mappedColumns, boolean takeRandom)
      Utility function to access a mapping table. The mapping name of the mapping modification method is specified in the form category/name.
      Parameters:
      data - A data value.
      mappingName - The name of a mapping modification method in the form category/name.
      types - - The data types used, specified as a string containing the type number as defined in java.sql.SqlTypes.
      takeRandom - If true, then for a value not contained in the map a random value will be stored in the map, otherwise null.
      Returns:
      The mapped object for key, null or a random value if not found
    • poolMappingGet

      public Object poolMappingGet(Object data, String poolTableName, String mappedColumns, boolean takeRandom)
      Utility function to access a pool table. The name of the pool table is specified in the form category/name. If a pool table with the specified name does not yet exist, it will be created.
      Parameters:
      data - A single data value.
      poolTableName - The name of the specified pool table in the form category/name.
      mappedColumns - The names of the mapped columns, specified as a comma separated string.
      takeRandom - If true, then for a value not contained in the map, a random value will be stored in the map, otherwise null.
      Returns:
      The mapped object for key, null or a random value if not found.
    • poolMappingGet

      @Deprecated public Object poolMappingGet(Object data, String poolTableName)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to access a pool table. The name of the pool table is specified in the form category/name. If a pool table with the specified name does not yet exist, an exception will be thrown and the table will not be created.
      Parameters:
      data - A single data value.
      poolTableName - The name of the specified pool table in the form category/name.
      Returns:
      The mapped object for key, null or a random value if not found.
    • specialMapping

      @Deprecated public Object[] specialMapping(Object[] data, String poolTableName, String types, boolean takeRandom)
      Deprecated.
      method is substituted by poolMapping(Object[] data, String poolTableName, String mappedColumns, boolean takeRandom)
      Utility function to access a pool table. The name of a pool table in the form category/name.
      Parameters:
      data - An array of data values
      poolTableName - The name of a pool table specified as category/name
      types - The data types used, specified as a string containing a comma separated list of numbers as defined in java.sql.SqlTypes.
      takeRandom - If true, for a value not contained in the map a random value will be stored in the map, otherwise store null.
      Returns:
      the value mapped for key, null or a random value if not found
    • poolMappingGet

      @Deprecated public Object[] poolMappingGet(Object[] data, String poolTableName, String mappedColumns, boolean takeRandom)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to access a pool table. The name of the pool table is specified in the form category/name. If a pool table with the specified name does not yet exist, it will be created.
      Parameters:
      data - An array of data values.
      poolTableName - The name of a pool table in the form category/name.
      mappedColumns - The names of the mapped columns, specified as a comma separated string.
      takeRandom - If true, then for a value not contained in the map, a random value will be stored in the map, otherwise null.
      Returns:
      Values mapped for keys, null or random values if not found.
    • poolMappingGet

      @Deprecated public Object[] poolMappingGet(Object[] data, String poolTableName)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to access a pool table. The name of the pool table is specified in the form category/name. If a pool table with the specified name does not yet exist, an exception will be thrown and the table will not be created.
      Parameters:
      data - An array of data values.
      poolTableName - The name of a pool table in the form category/name.
      Returns:
      Values mapped for keys, null or random values if not found.
    • specialMappingPut

      @Deprecated public void specialMappingPut(Object srcData, Object tgtData, String poolTableName, String types)
      Deprecated.
      method is substituted by poolMappingPut(Object srcData, Object tgtData, String poolTableName, String mappedColumns)
      Utility function to modify a pool table. This method puts a value into a pool table.
      Parameters:
      srcData - The source data to use.
      tgtData - The target value to put in the map.
      poolTableName - The name of a pool table specified as category/name.
      types - The data type used, specified as a string containing a number as defined in java.sql.SqlTypes.
    • poolMappingPut

      @Deprecated public void poolMappingPut(Object srcData, Object tgtData, String poolTableName, String mappedColumns)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to modify a pool table. This method puts a value into a pool table for mapping modification. If a pool table with the specified name does not yet exist, it will be created.
      Parameters:
      srcData - The source value to use.
      tgtData - The target value to put in the map.
      poolTableName - The name of a pool table specified in the form category/name.
      mappedColumns - The names of the mapped columns, specified as a comma separated string.
    • poolMappingPut

      @Deprecated public void poolMappingPut(Object srcData, Object tgtData, String poolTableName)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to modify a pool table. This method puts a value into a pool table for mapping modification. If a pool table with the specified name does not yet exist, an exception will be thrown and the table will not be created.
      Parameters:
      srcData - The source value to use.
      tgtData - The target value to put in the map.
      poolTableName - The name of a pool table specified in the form category/name.
    • specialMappingPut

      @Deprecated public void specialMappingPut(Object[] srcData, Object[] tgtData, String poolTableName, String types)
      Deprecated.
      method is substituted by poolMappingPut(Object[] srcData, Object[] tgtData, String poolTableName, String mappedColumns)
      Utility function to modify a pool table. This method allows to put a value into a pool table.
      Parameters:
      srcData - The source data values to use.
      tgtData - The target corresponding values to put in the map.
      poolTableName - The name of a pool table specified as category/name.
      types - The data types used, specified as a string containing a comma separated list of numbers as defined in java.sql.SqlTypes.
    • poolMappingPut

      @Deprecated public void poolMappingPut(Object[] srcData, Object[] tgtData, String poolTableName, String mappedColumns)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to modify a pool table. This method allows to put a value into an existing pool table. If a pool table with the specified name does not yet exist, it will be created.
      Parameters:
      srcData - The source values to use.
      tgtData - The target values to put in the map.
      poolTableName - The name of a pool table specified in the form category/name.
      mappedColumns - The names of the mapped columns, specified as a comma separated string.
    • poolMappingPut

      @Deprecated public void poolMappingPut(Object[] srcData, Object[] tgtData, String poolTableName)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to modify a pool table. This method allows to put a value into an existing pool table. If a pool table with the specified name does not yet exist, an exception will be thrown and the table will not be created.
      Parameters:
      srcData - The source values to use.
      tgtData - The target values to put in the map.
      poolTableName - The name of a pool table specified in the form category/name.
    • specialGetMappingTable

      @Deprecated public Map specialGetMappingTable(String poolTableName, String types)
      Deprecated.
      method is substituted by getPoolTable(String poolTableName)
      Utility function to retrieve a pool table as a java.util.Map

      Usage of this method will lock the pool table

      Parameters:
      poolTableName - The name of a pool table as category/name
      types - The data types used. Entered as a string containing a comma separated list of numbers as defined in java.sql.SqlTypes.
      Returns:
      A java.util.Map Object representing the mapping table
    • getPoolTable

      @Deprecated public Map getPoolTable(String poolTableName)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to retrieve a pool table as a java.util.Map. Usage of this method will lock the pool table. An exception will be thrown if the pool table does not yet exist.
      Parameters:
      poolTableName - The name of a pool table as category/name.
      Returns:
      A java.util.Map Object representing the pool table.
    • specialGetMappingTableSize

      @Deprecated public int specialGetMappingTableSize(String poolTableName, String types)
      Deprecated.
      method is substituted by getPoolTableSize(String poolTableName)
      Utility function to retrieve the size of a pool table
      Parameters:
      poolTableName - The name of a pool table as category/name
      types - The data types used. Entered as a string containing a comma separated list of numbers as defined in java.sql.SqlTypes.
      Returns:
      An integer representing the mapping table size
    • getPoolTableSize

      @Deprecated public int getPoolTableSize(String poolTableName)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Utility function to retrieve the size of a pool table. An exception will be thrown if the pool table does not yet exist.
      Parameters:
      poolTableName - The name of a pool table specified as category/name.
      Returns:
      An integer representing the pool table size.
    • getPoolTableColumnTypes

      @Deprecated public String getPoolTableColumnTypes(String poolTableName)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      Provides column types of a pool table as SqlTypes in form of a comma separated string, i.e. 12,4,8,12. If a pool table with given name does not exist, an exception will be thrown.
      Parameters:
      poolTableName - name of the pool table the column types should be returned for
      Returns:
      comma separated string containing the SqlTypes of the pool table's columns
    • mappingTable

      @Deprecated public Object[] mappingTable(Object[] row, String mappedColumns)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      This method provides access to mapping tables. Mapping tables will be generated once by their defined data source. This method can be used to access the mapping tables by giving objects as a key. The method will modify the values in the row as defined by the mapping table. A new array will be returned containing the mapped values. The mapping name defaults to the modification method specified in this modification rule. The value of columnsToPreserve gets a default value of an empty string.
      Parameters:
      row - The source values for the mapping.
      mappedColumns - Comma separated list containing the names of the columns to be used .
      Returns:
      Object[]
    • mappingTable

      @Deprecated public Object[] mappingTable(Object[] row, String mappedColumns, String columnsToPreserve)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      This method provides access to mapping tables. Mapping tables will be generated once by their defined data source. This method can be used to access the mapping tables by giving objects as a key. The method will modify the values in the row as defined by the mapping table. A new array will be returned containing the mapped values. The mapping name defaults to the modification method specified in this modification rule.
      Parameters:
      row - The source values for the mapping
      mappedColumns - Comma separated list containing the names of the columns to be used .
      columnsToPreserve - The names of columns that should be preserved in a random mapping
      Returns:
      Object[]
    • mappingTable

      @Deprecated public Object[] mappingTable(String name, Object[] row, String mappedColumns)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      This method provides access to mapping tables. Mapping tables will be generated once by their defined data source. This method can be used to access the mapping tables by giving objects as a key. The method will modify the values in the row as defined by the mapping table. A new array will be returned containing the mapped values. The value of columnsToPreserve has a default value of an empty string.
      Parameters:
      name - The name of a mapping modification method as category/name
      row - The source values for the mapping
      mappedColumns - Comma separated list containing the names of the columns to be used .
      Returns:
      Object[]
    • mappingTable

      @Deprecated public Object[] mappingTable(String name, Object[] row, String mappedColumns, String columnsToPreserve)
      Deprecated.
      The pool tables are not compatible with a multi container XDM installation. Use ModificationUtils instead.
      This method provides access to mapping tables. Mapping tables will be generated once by their defined data source. This method can be used to access the mapping tables by giving objects as a key. The method will modify the values in the row as defined by the mapping table. A new array will be returned containing the mapped values.
      Parameters:
      name - The name of a mapping modification method as category/name
      row - The source values for the mapping
      mappedColumns - Comma separated list containing the names of the columns to be used .
      columnsToPreserve - The names of columns that should be preserved in a random mapping
      Returns:
      the mapped array of values
    • putPersistent

      @Deprecated public void putPersistent(String mapName, Object key, Object value)
      Deprecated.
      method is substituted by sessionPersistentPut(String mapName, Object key, Object value)
      Stores a persistent value for an entire run of the modification.
      Parameters:
      mapName - The name of the map in which to store the value.
      key - The key in the map.
      value - The value to be stored.
    • sessionPersistentPut

      public void sessionPersistentPut(String mapName, Object key, Object value)
      Stores a persistent value for an entire run of the modification.
      Parameters:
      mapName - The name of the map in which to store the value.
      key - The key in the map.
      value - The value to be stored.
    • getPersistent

      @Deprecated public Object getPersistent(String mapName, Object key)
      Deprecated.
      method is substituted by sessionPersistentGet(String mapName, Object key)
      Retrieves a persistent value from the global map.
      Parameters:
      mapName - The name of the map in which the value is stored.
      key - The key in the map.
      Returns:
      Object
    • sessionPersistentGet

      public Object sessionPersistentGet(String mapName, Object key)
      Retrieves a persistent value from the global map.
      Parameters:
      mapName - The name of the map in which the value is stored.
      key - The key in the map.
      Returns:
      Object
    • getCurrentTargetConnectionPool

      public ConnectionPool getCurrentTargetConnectionPool()
      Returns:
      an internal ConnectionPool object, that can be used to get a JDBC connection to the database. Use the get() method to retrieve the java.sql.Connection. Use the put() method to release the connection afterwards.
    • getCurrentSourceConnectionPool

      public ConnectionPool getCurrentSourceConnectionPool()
      Returns:
      an internal ConnectionPool object, that can be used to get a JDBC connection to the database. Use the get() method to retrieve the java.sql.Connection. Use the put() method to release the connection afterwards.
    • fetchSingleValueFromConnection

      public Object fetchSingleValueFromConnection(String scope, String sql, Object... parameter)
      Executes a statement against the source or target connection and returns a single value. Note that with every call of this method, a new CONNECTION object will be taken from the connection pool instead of re-using one single connection for every call of this method.
      Parameters:
      scope - use "TARGET" or "SOURCE" to execute against the specific connection of the task. The respective connection is chosen based on the table the rule is applied on. It will always use the source or target connection the table relates to. Alternatively this can be the name of a connection parameter of type CONNECTION. Then the statement will be executed against the configured connection of the parameter.
      sql - An SQL statement that returns a result set
      parameter - You may use parameter markers (?) in your statement. Fill those values with parameters
      Returns:
      The value of the first column in the first row, null if there is an empty result set
    • fetchSingleValueFromConnection

      public Object fetchSingleValueFromConnection(Connection connection, String sql, Object... parameter)
      Executes a statement against the source or target connection and returns a single value. Note that with calling this method only one single CONNECTION object is taken from the ConnectionPool. This object will then be re-used for every further method call.
      Parameters:
      connection - An object of type java.sql.Connection. Can be either a connection provided as parameter of type CONNECTION or built by a ConnectionPool.
      sql - An SQL statement that returns a result set
      parameter - You may use parameter markers (?) in your statement. Fill those values with parameters
      Returns:
      The value of the first column in the first row, null if there is an empty result set
    • getParameterConnectionPool

      public ConnectionPool getParameterConnectionPool(String scope) throws IOException
      Parameters:
      scope - This is the name of a connection parameter of type Connection. Then the statement will be executed against the configured connection of the parameter
      Returns:
      an internal ConnectionPool object, that can be used to get a JDBC connection to the database. Use the get() method to retrieve the java.sql.Connection. Use the put() method to release the connection afterwards.
      Throws:
      IOException - if connection configuration could not be deserialized. This indicates an internal XDM error.
    • getCurrentTableSchema

      public String getCurrentTableSchema()
      Returns:
      the schema of the currently processed table Mapping rules are applied on the name if the scope of the modification rule is set to Target
    • getCurrentTableName

      public String getCurrentTableName()
      Returns:
      the name of the currently processed table. Mapping rules are applied on the name if the scope of the modification rule is set to Target
    • getCurrentSourceTableSchema

      public String getCurrentSourceTableSchema()
      Returns:
      the source schema of the currently processed table.
    • getCurrentSourceTableName

      public String getCurrentSourceTableName()
      Returns:
      the source name of the currently processed table
    • getCurrentTableMappedSchema

      public String getCurrentTableMappedSchema()
      Returns:
      the mapped schema name of the currently processed table
    • getCurrentTableMappedName

      public String getCurrentTableMappedName()
      Returns:
      the mapped name of the currently processed table
    • parseTimestamp

      public de.ubs.xdm.utils.core.HighPrecisionTimestamp parseTimestamp(String patternToSecond, String patternAfterSecond, String data)
      Parses a string and returns a HighPrecisionTimestamp, the internal Format for all date/time related data types. Use this type to ensure all date/time information is transported.
      Parameters:
      patternToSecond - A parser pattern as described in java.util.SimpleDateFormat up to and including the seconds.
      patternAfterSecond - The pattern of all digits after the seconds e.g '.SSS' for three decimal digits.
      data - The string to be parsed
      Returns:
      The date represented as high precision timestamp
    • getCurrentColumn

      public Column getCurrentColumn()
      This return an internal representation of the column. Only works for modification methods of type COLUMN. Column supports getName(), getType() (java.sqlTypes constants), getTypeName(), getLength(), getScale() etc.
      Returns:
      The column object on which the method is currently processed
    • getCurrentTable

      public Table getCurrentTable()
      This return an internal representation of the table. Table supports getName(), getSchema(), getColumnList() etc. This is the source table if the scope of the modification rule is that to source, and the target table if the scope is set to target.
      Returns:
      The table object on which the method is currently processed
    • getCurrentSourceTable

      public Table getCurrentSourceTable()
      This return an internal representation of the source table. Table supports getName(), getSchema(), getColumnList() etc.
      Returns:
      The source table object of the table on which the method is currently processed
    • getLogContext

      protected String getLogContext()
      Overrides:
      getLogContext in class ScriptContext
    • defineReport

      public void defineReport(String name, String... columns)
      Defines a report to be written when modification is complete. All column values are strings.
      Parameters:
      name - A unique name for the report
      columns - A comma separated list of column names.
    • defineReport

      public void defineReport(String name, boolean ignoreDuplicate, String... columns)
      Defines a report to be written when modification is complete. All column values are strings.
      Parameters:
      name - A unique name for the report
      ignoreDuplicate - omit error message if report was already defined
      columns - A comma separated list of column names.
    • addReportRow

      public void addReportRow(String name, String... values)
      Adds a row to the named report. All values must be strings.
      Parameters:
      name - The unique report name
      values - Row values
    • getDataColumns

      public List<? extends Column> getDataColumns()
      Returns:
      the list of columns that are transported over the data
    • doesSourceTableContainsColumn

      public Boolean doesSourceTableContainsColumn(String columnName)
    • getColumnTypeClassification

      public String getColumnTypeClassification(String columnName)
    • loadLibrary

      protected void loadLibrary(InputStream jsLibReader, String fileName) throws IOException
      The use of the Context.evaluateReader() method has the effect of loading all the code supplied by jsLibReader into the current method scope.
      Specified by:
      loadLibrary in class ScriptContext
      Parameters:
      jsLibReader - The Reader for the jslib specified by fileName
      fileName - Name of the file containing the jslib (required by the evaluateReader() method
      Throws:
      IOException - that can originate from jsLibReader
    • stashRow

      public void stashRow(Object[] data)
      Stashes a row to be fetched later with get unstashRows() method. The stashed array is a deep copy of the parameter. That means, that modifications on the data array after the stash are not changed in the stashed array.
      Parameters:
      data - The row to be saved.
    • unstashRows

      public List<Object[]> unstashRows()
      Returns all rows that have been stashed with the stashRow(Object[]) data method. This method should usually be used to return collected rows from the apply() method. This method clears the current stash.
      Returns:
      The list of saved rows