Class EtlVariable

java.lang.Object
scriptella.core.EtlVariable
All Implemented Interfaces:
ParametersCallback

public class EtlVariable extends Object implements ParametersCallback
Represents a global etl variable available for all ETL file elements.

The variable provides the following functionalities:

As of 1.1 a new syntax is introduced based on JEXL function namespaces:

Examples

Global variables

A global variable, which is set in one part of the ETL file can be later read from other places during ETL execution:


     <query connection-id="db">
       SELECT COUNT(*) as userCount from Users
       <script connection-id="jexl">
           etl.globals['globalVar'] = userCount;
       </script>
     </query>
     <script connection-id="log">
         Global variable 'globalVar': ${etl.globals['globalVar']}
    </script>
 

Obtain a native connection to the JDBC datasource


    <script connection-id="java">
        scriptella.core.EtlVariable etl = (scriptella.core.EtlVariable)get("etl");
        java.sql.Connection c = (java.sql.Connection)((scriptella.spi.NativeConnectionProvider)etl.getConnection("db")).getNativeConnection();
        java.sql.ResultSet r = c.createStatement().executeQuery("SELECT COUNT(*) FROM Test");
        r.next();
        Object cnt = r.getObject(1);
        java.util.logging.Logger.getLogger("mylogger").info("Count: "+cnt);
    </script>
 
Since:
1.0
Author:
Fyodor Kupolov
  • Field Details

  • Constructor Details

  • Method Details

    • getDate

      public EtlVariable.DateUtils getDate()
    • getText

      public EtlVariable.TextUtils getText()
    • getClazz

      public EtlVariable.ClassUtils getClazz()
    • loadClass

      public Class loadClass(String name) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • getParameter

      public Object getParameter(String name)
      Accessor method for parameters available in the current execution context. Useful for cases when variables has special symbols which cannot be referenced as normal JEXL variables, e.g. etl.getParameter('Column Name')
      Specified by:
      getParameter in interface ParametersCallback
      Parameters:
      name - parameter name.
      Returns:
      value of the parameter.
    • getGlobals

      public Map<String,Object> getGlobals()
      Getter for a global variables storage.

      This map is shared between all etl file elements and can be used for cases when there is a need to share some state globally. It is recommended to avoid using global variables except cases when it's really beneficiary and simplifies the ETL file.

      Returns:
      map of global variables in the scope of ETL file.
      Since:
      1.1
    • getConnection

      public Connection getConnection(String id)
      Returns the connection for the specified id, This method is convenient for cases when access to the native connection is required, e.g. invoking a specific method or for a manual control over a transaction boundaries.

      Note: The method should be used with caution because it might affect the flow of the ETL file execution and block some optimizations which may be added to the ETL engine in the future.

      Parameters:
      id - id of the required connection. Null is allowed if script has only one connection.
      Returns:
      connection for the specified id.
      Since:
      1.2