public class EtlVariable extends java.lang.Object implements ParametersCallback
etl
variable available for all ETL file elements.
The variable provides the following functionalities:
EtlVariable.DateUtils.format(java.util.Date, String)
or
EtlVariable.TextUtils.nullIf(Object, Object)
getConnection(String)
method for obtaining underlying connection objectsgetGlobals()
- container for global variables shared across different parts of ETL fileAs of 1.1 a new syntax is introduced based on JEXL function namespaces:
date:
namespace contains functions from
EtlVariable.DateUtils
, e.g. date:now()
text:
namespace contains functions from
EtlVariable.TextUtils
, e.g. text:ifNull()
class:
namespace contains functions from
EtlVariable.ClassUtils
,
e.g. class:forName('java.lang.System').getProperty('java.version')
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>
<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>
Modifier and Type | Class and Description |
---|---|
static class |
EtlVariable.ClassUtils
Utility class for ETL expressions.
|
static class |
EtlVariable.DateUtils
Utility class for ETL file expressions.
|
static class |
EtlVariable.TextUtils
Utility class for ETL file expressions.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
NAME |
Constructor and Description |
---|
EtlVariable() |
EtlVariable(ParametersCallback parametersCallback,
EtlContext globalContext) |
Modifier and Type | Method and Description |
---|---|
EtlVariable.ClassUtils |
getClazz() |
Connection |
getConnection(java.lang.String id)
Returns the
for the specified id,
This method is convenient for cases when access to the native connection is required, e.g. |
EtlVariable.DateUtils |
getDate() |
java.util.Map<java.lang.String,java.lang.Object> |
getGlobals()
Getter for a global variables storage.
|
java.lang.Object |
getParameter(java.lang.String name)
Accessor method for parameters available in the current execution context.
|
EtlVariable.TextUtils |
getText() |
java.lang.Class |
loadClass(java.lang.String name) |
public static final java.lang.String NAME
public EtlVariable(ParametersCallback parametersCallback, EtlContext globalContext)
public EtlVariable()
public EtlVariable.DateUtils getDate()
public EtlVariable.TextUtils getText()
public EtlVariable.ClassUtils getClazz()
public java.lang.Class loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public java.lang.Object getParameter(java.lang.String name)
etl.getParameter('Column Name')
getParameter
in interface ParametersCallback
name
- parameter name.public java.util.Map<java.lang.String,java.lang.Object> getGlobals()
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.
public Connection getConnection(java.lang.String id)
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.
id
- id of the required connection. Null is allowed if script has only one connection.Copyright © Copyright 2006-2019 The Scriptella Project Team.