Package scriptella.core
Class EtlVariable
java.lang.Object
scriptella.core.EtlVariable
- All Implemented Interfaces:
ParametersCallback
Represents a global
etl variable available for all ETL file elements.
The variable provides the following functionalities:
- Utility methods useful in JEXL expressions, e.g
EtlVariable.DateUtils.format(java.util.Date, String)orEtlVariable.TextUtils.nullIf(Object, Object) getConnection(String)method for obtaining underlying connection objectsgetGlobals()- container for global variables shared across different parts of ETL file
As of 1.1 a new syntax is introduced based on JEXL function namespaces:
date:namespace contains functions fromEtlVariable.DateUtils, e.g.date:now()text:namespace contains functions fromEtlVariable.TextUtils, e.g.text:ifNull()class:namespace contains functions fromEtlVariable.ClassUtils, e.g.class:forName('java.lang.System').getProperty('java.version')
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUtility class for ETL expressions.static classUtility class for ETL file expressions.static classUtility class for ETL file expressions. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEtlVariable(ParametersCallback parametersCallback, EtlContext globalContext) -
Method Summary
Modifier and TypeMethodDescriptiongetClazz()getConnection(String id) Returns thefor the specified id, This method is convenient for cases when access to the native connection is required, e.g.connectiongetDate()Getter for a global variables storage.getParameter(String name) Accessor method for parameters available in the current execution context.getText()
-
Field Details
-
NAME
- See Also:
-
-
Constructor Details
-
EtlVariable
-
EtlVariable
public EtlVariable()
-
-
Method Details
-
getDate
-
getText
-
getClazz
-
loadClass
- Throws:
ClassNotFoundException
-
getParameter
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:
getParameterin interfaceParametersCallback- Parameters:
name- parameter name.- Returns:
- value of the parameter.
-
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
Returns thefor 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.connectionNote: 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
-