scriptella

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » scriptella 
Scriptella ETL
License:Apache Software License
URL:http://scriptella.javaforge.com
Description:Scriptella is an ETL (Extract-Transform-Load) and script execution tool.
Package NameComment
scriptella
scriptella.configuration Classes and interfaces to parse script files.

For now only XML format is supported

To create configuration from XML file use the following code:

        ConfigurationFactory factory = new ConfigurationFactory();
        factory.setResourceURL(resourceURL);
        Configuration configration = cf.createConfiguration();
    

scriptella.core Core classes for scripts execution.
scriptella.driver.alljdbc
scriptella.driver.auto Autodiscovery Driver for Scriptella.

Automatically discovers a driver based on the specified url.

Note: Autodiscovery serves for convenience purposes and works only with JDBC drivers and URL schemes supported by Scriptella, in other cases driver's name has to be specified manually.

General information

Driver class:scriptella.driver.auto.Driver
Driver alias name:auto
URL:Specific to an underlying driver
Runtime dependencies:Depends on an underlying driver.

Example

    <!-- connection to a SQL Server database via JTDS driver-->
    <connection driver="auto" url="jdbc:jtds:sqlserver://localhost:1433/northwind"/>

    <!-- connection to a JNDI bound datasource -->
    <connection driver="auto" url="jndi:ds/appDataSource"/>

    <!-- connection to a Spring managed datasource -->
    <connection driver="auto" url="spring:myDataSource"/>

    <!-- connection to Mail driver-->
    <connection driver="auto" url="mailto:user@host?subject=Hello">
        mail.smtp.host=mail.host.name
        mail.user=user
        mail.password=password
    </connection>


scriptella.driver.csv

CSV Driver for Scriptella.

The driver to write and query CSV files.

Note: The driver doesn't use SQL syntax

General information

Driver class:scriptella.driver.csv.Driver
URL:CSV file URL. URIs are resolved relative to a script file directory. If url has no value the output is read from/printed to the console (System.out).
Runtime dependencies:opencsv-1.6+.jar

Driver Specific Properties

Name Description Required
encoding Specifies charset encoding of CSV files. No, the system default encoding is used.
separator The delimiter to use for separating entries when reading from or writing to files. No, the default value is ,.
quote The character to use for quoted elements when reading from or writing to files. Use empty string to suppress quoting. No, the default value is ".
headers Value of true means the first line contains headers.

Only valid for <query> elements.

No, the default value is true(first line contains column names).
eol End-Of-Line suffix.

Only valid for <script> elements.

No, the default value is \n.
trim Value of true specifies that the leading and trailing whitespaces in CSV fields should be omitted. No, the default value is true.
skip_lines The number of lines to skip before start reading. Please note that if headers=true, the actual number of skipped lines is skipped_lines+1 No, the default value is 0 (no lines are skipped).
null_string Specifies value of a string token to be parsed as Java null literal. No, by default strings are preserved, i.e. empty CSV field is parsed as empty string.

Query Syntax

The driver utilizes query by example approach for CSV content filtering. If you want to read the whole CSV simply use empty query element, otherwise specify a set of lines containing comma-separated case insensitive regular expressions.
Example:
,food
,^Beverages$
    
This query selects rows where the second column equals "Beverages" or contains "food" substring.

The columns of the matched row can be referenced by name in nested queries/scripts. It is also possible to reference columns by an index, i.e. $1, $2, ...

Script Syntax

The script syntax is simple, just specify a comma-separated set of columns.
Example:
<script>
id,priority,summary,status
1,Critical,NullPointerException in Main class,Open
</script>
    
This script writes 2 lines to the output file.

IMPORTANT: Always use commas as a column separator inside both <script> and <query> elements no matter what separator is used in files being parsed or produced. This decision allows switching between different formats like tab or semicolumn while keeping scripts and queries unchanged.

Properties substitution

In CSV script and query elements use ${property} syntax for properties/variables substition.

Examples

<connection id="in" driver="csv" url="data.csv" classpath="lib/opencsv.jar">

</connection>
<connection id="out" driver="csv" url="report.csv" classpath="lib/opencsv.jar">
    #Use empty quote to turn off quoting
    quote=
    separator=;
</connection>

<script connection-id="out">
    ID,Priority,Summary,Status
</script>

<query connection-id="in">
    <!--Empty query means select all-->
    <script connection-id="out">
        $rownum,$priority,$summary,$status
    </script>
</query>

Copies rows from data.csv file to report.csv, additionally the ID column is added. The result file will be semicolon separated.
scriptella.driver.db2 DB2 Driver Adapter for Scriptella.

General information

Driver class:scriptella.driver.db2.Driver
URL:Same as for DB2 JDBC Driver.
Runtime dependencies: db2jcc.jar;db2jcc_license_cu.jar

Driver Specific Properties

Name Description Required

Examples

    <connection id="c1" driver="db2" url="jdbc:db2://localhost:50000/sample" user="username" password="password">
    </connection>
scriptella.driver.h2 H2 Database Driver Adapter for Scriptella.

General information

Driver class:scriptella.driver.h2.Driver
URL:Same as for H2. No URL means private in-memory database.
Runtime dependencies:h2.jar

Driver Specific Properties

Name Description Required

Examples

    <connection driver="h2" url="jdbc:h2:file:database" user="sa">
    </connection>

    <!--empty URL attribute means private In-Memory database -->
    <connection driver="h2"/>
scriptella.driver.hsqldb HSLQDB Driver Adapter for Scriptella.

General information

Driver class:scriptella.driver.hsqldb.Driver
URL:Same as for HSQLDB
Runtime dependencies:hsqldb.jar

Driver Specific Properties

Name Description Required
hsql.shutdown_on_exit True if SHUTDOWN command should be automatically executed before last connection closed. In 1.7.2, in-process databases are no longer closed when the last connection to the database is explicitly closed via JDBC, a SHUTDOWN is required No, default value is true

Example

    <connection driver="hsqldb" url="jdbc:hsqldb:file:db" user="sa">
        hsql.shutdown_on_exit=true;
    </connection>
scriptella.driver.janino Janino Driver for Scriptella.

This driver allows to embed Java code into <query> and <script> elements. This code is compiled by Janino and executed by Scriptella engine. For simple scripting solutions refer to JEXL expression language which is interpreted and less powerful.

Janino scripting elements are implicit subclasses of Query and Script base classes.

General information

Driver class:scriptella.driver.janino.Driver
Runtime dependencies:janino-2.5.11+.jar

Driver Specific Properties

Name Description Required

Script Syntax

In Scriptella Janino script is a Java "block", i.e. the body of a method. For convenience protected and public methods of JaninoScript are accessible from Janino <script> elements.

In other words the script element is an implementation of execute method of JaninoScript class.

Query Syntax

Queries are written using the same syntax as script elements with the only difference that protected/public methods from Query class are accessible from <query> element.

In other words the query element is an implementation of execute method of JaninoQuery class.

Properties substitution

The standard ant-style properties substitution is not supported. Instead, use get("variableName") to get the variable value and set("variableName", value) to set the variable value.

Example

    <connection driver="janino">/>

    <query>
        set("name", "John);
        next();
        <script>
            System.out.println("Processing: "+get("name"));
        </script>
    </query>
In this example the query produces a row having a column name=John. The child script is executed on a query result set and prints the message
Processing: John
to the console.

ODBC sample from Scriptella examples distribution also shows several use-cases for Janino.

scriptella.driver.jexl

JEXL Driver for Scriptella.

Allows usage of JEXL scripts in ETL <query> and <script> elements.

The driver uses commons-jexl library which is a part of Scriptella Core. JEXL scripts are interpreted at runtime and generally work slower than compiled scripts (e.g. Janino), nevertheless JEXL scripts are easier to write and maintain especially for non-Java developers.

General information

Driver class:scriptella.driver.jexl.Driver
Runtime dependencies:None

Query and Script Syntax

Standard JEXL scripts syntax is used inside ETL elements.

Bind variables from parent elements are accessible as simple variables. Assignment operator v="value" makes variable v available for nested ETL elements.

Implicit variable query is available in <query> elements. This variable should be used to produce a result set:

    <query>
        i=0; while(i lt 10) {
            i=i+1;
            query.next(); // Causes child script to be executed
        }
        <script>......</script>
    </query>
See ParametersCallbackMap class Javadoc for more details.

Examples

<connection id="jexl" driver="jexl"/>
<connection id="out" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:DB"/>

<query connection-id="jexl">
    i=0;while (i lt 10) {
        i=i+1;
        login='login'+i;
        query.next();
    }
    <script connection-id="out">
        INSERT INTO Table(ID, Login) VALUES (?i, ?login);
    </script>
</query>

The query executes a child script 10 times. As the result of execution 10 records are inserted in a database table.
scriptella.driver.jndi JNDI Datasource Driver for Scriptella.

This driver allows to work with JNDI-bound datasource connections, useful in J2EE environment

This driver acts as a proxy and relies on JDBC Bridge.

General information

Driver class:scriptella.driver.jndi.Driver
Driver alias name:jndi
URL:JNDI name of the datasource
Runtime dependencies:None

Notes

Depending on your environment you may need to specify additional JNDI properties inside a connection element. These settings will take precedence over jndi.properties and System properties.

Example

    <connection driver="jndi" url="ds/appDataSource">
        #Default settings should work in J2EE environment, but you may reconfigure JNDI here
        #java.naming.factory.initial=jndi.provider.Factory
    </connection>
scriptella.driver.ldap

LDAP Driver for Scriptella.

This driver allows to execute LDIF scripts and search filter queries.

Details of LDIF syntax are described in RFC 2849, LDAP Search Filters are described in RFC 2254

This driver supports ${} syntax for variables substitution

General information

Driver class:scriptella.driver.ldap.Driver
URL:ldap://host:port/dn?attributes?scope?filter?extensions according to RFC 2255
Runtime dependencies:None

Driver Specific Properties

Name Description Required
search.scope Search scope for queries. The value must be one of the: object, onelevel, subtree No, the default value is object.
search.basedn base dn for search. No, the default value is "". Specifiying may be required for searches using connections to the root directory context.
search.timelimit Time limit for queries. No, the default value is 0(wait indefinitely).
search.countlimit Maximum number of entries to be returned by queries. No, the default value is 0(all entries will be returned).
file.maxlength Maximum size in KBs of the external files referenced from LDIFs. No, the default value is 10000 (10MB).
readonly If true, LDIF update statements are logged but not executed. May be helpful for debugging. No, the default value is false.

This driver is JNDI-based and uses com.sun.jndi.ldap.LdapCtxFactory LDAP provider. You may specify additional JNDI settings as connection properties. For a complete list of JNDI properties see LDAP Naming Service Provider for the JNDI

Example

<connection driver="ldap" url="ldap://localhost:389/dc=scriptella" user="cn=root,dc=scriptella" password="secret" >
    search.scope=subtree
    #search.basedn=dc=scriptella
</connection>

<query>
    
     <![CDATA[(&(objectClass=groupOfUniqueNames)(uniqueMember=$dn))]]>
</query>

<script>
#LDIF add entry
#Avoid leading whitespaces because LDIF is a whitespace sensitive format.
dn: ou=people,dc=scriptella
objectClass: organizationalUnit
ou: people
</script>
Register an LDAP connection with subtree scope search mode and perform a search for entries satisfying specified search filter, $ is used for variables/expressions subsitution.

The script element is used to add ou=people,dc=scriptella entry.

scriptella.driver.ldap.ldif
scriptella.driver.lucene Lucene Driver for Scriptella.

This driver allows to search through Lucene v.2.x compatible indexed data.

Lucene scripting elements are implicit subclasses of Query base classe.

General information

Driver class:scriptella.driver.lucene.Driver
Runtime dependencies:lucene-core.jar

Driver Specific Properties

Name Description Required
fields List of comma-separated fields to be searched No, the Lucene default field 'contents' is used.
useMultiFieldQueryParser whether MultiFieldQueryParser or QueryParser to be used No, default value is false.
useLowercaseExpandedTerms whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not No, default value is true.

Note: if MultiFieldQueryParser is used instead of QueryParser then all the query's terms must appear, but it doesn't matter in what fields they appear.

Example

    <connection id="search" driver="lucene" url="file://PATH_TO_YOUR_LUCENE_INDEX">
        fields=default_field
    </connection>
    <connection id="out" driver="text" url="tst://testfile"/>
    <query id="search">
        title:script luc*e
        <script connection-id="out">$rownum+'. '+$title+' : '+$default_field</script>
    </query>
scriptella.driver.mail

E-Mail Driver for Scriptella.

Allows sending E-Mails via SMTP.

General information

Driver class:scriptella.driver.mail.Driver
URL:URL specifies TO recipients using the mailto scheme: mailto:sAddress[sHeaders]
Runtime dependencies: mail.jar and activation.jar

Driver Specific Properties

Name Description Required
type Specifies type of E-Mail message content: text or html. No, default value is text.
subject Specifies e-mail subject. No.
mail.host Specifies the default Mail server. No, see JavaMail Environment Properties for details
mail.from Specifies e-mail address of sender. No, see JavaMail Environment Properties for details

Properties substitution

Mail script elements support ${property} or $property syntax for properties/variables substition. Additionally connection URL parameter supports dynamically resolved binding variables.
Example:
mailto:$email, the email variable would be reevaluated if mail script is executed by a parent query.

Notes:

  • In addition to the above mentioned properties the driver supports all JavaMail environment properties.
  • Connection properties may be specified inside a connection element or as a a part of URL, e.g. mailto:user@nosuchhost.com?subject=Hello
  • This driver supports dynamic properties substitution in an URL, e.g. mailto:$email?subject=$subject ,it makes possible sending emails to recipients specified by in a row set.

Examples

The following example sends a simple text message

<etl>
    <connection driver="mail" url="mailto:user@nosuchhost.com?subject=Hello"
            classpath="mail.jar:activation.jar">
        mail.smtp.host=mail.host.name
        mail.user=user
        mail.password=password
        mail.from=Firstname Lastname &lt;user@nosuchhost.com&gt;
    </connection>
    <script>Message produced by Scriptella ETL</script>
</etl>
    

Use type=html property to send HTML content.

<etl>
    <connection driver="mail" url="mailto:user@nosuchhost.com?subject=Hello"
            classpath="mail.jar:activation.jar">
        type=html
        mail.smtp.host=mail.host.name
        mail.user=user
        mail.password=password
        mail.from=Firstname Lastname &lt;user@nosuchhost.com&gt;
    </connection>
    <script><![CDATA[
        <html>
            <body>
                Hello,
                <hr>
                <a href="http://scriptella.javaforge.com/" title="Powered by Scriptella ETL">
                    <img src="http://scriptella.javaforge.com/images/scriptella-powered.gif" 
                            width="88" height="31" border="0" alt="Powered by Scriptella ETL">
                </a>
            </body>
        </html>]]>
    </script>
</etl>
    

The following example sends a message to a list selected from the database

<etl>
    <connection id="mail" driver="mail" url="mailto:$email?subject=Hello $name"
            classpath="mail.jar:activation.jar">
        mail.smtp.host=mail.host.name
        mail.user=user
        mail.password=password
        mail.from=Administrator &lt;user@nosuchhost.com&gt;
    </connection>
    <connection id="db" .../>
    <query connection-id="db" >
        SELECT * FROM Users
        <script connection-id="mail">
            #$rownum
            Message produced by Scriptella ETL
        </script>
   </query>
</etl>
    
scriptella.driver.mssql Microsoft SQL Server Driver Adapter for Scriptella.

Note: The driver tries to load any available JDBC driver for Microsoft SQL Server. It supports both Microsoft and JTDS JDBC drivers.

General information

Driver class:scriptella.driver.mssql.Driver
URL:The same as used by the underlying JDBC driver
Runtime dependencies: Any driver from the following list:

Driver Specific Properties

Name Description Required

Examples

    <connection id="c1" driver="mssql" url="jdbc:sqlserver://localhost;database=test" user="username" password="password">
    </connection>
    <connection id="c2" driver="mssql" url="jdbc:jtds:sqlserver://host/test" user="username" password="password">
    </connection>
scriptella.driver.mysql MySQL Driver Adapter for Scriptella.

Note: The driver tries to load MySQL JDBC driver.

General information

Driver class:scriptella.driver.mysql.Driver
URL:Same as for MySQL JDBC Driver.
Runtime dependencies: mysql-connector-java.jar

Driver Specific Properties

Name Description Required

Examples

    <connection driver="mysql" url="jdbc:mysql://localhost:3306/test" user="username" password="password">
    </connection>
scriptella.driver.oracle Oracle Driver Adapter for Scriptella.

General information

Driver class:scriptella.driver.oracle.Driver
URL:Same as for Oracle JDBC Driver.
Runtime dependencies: ojdbc14.jar

Driver Specific Properties

Name Description Required
plsql If true the slash on a single line is used as a separator for SQL statements. This mode is required to create triggers and execute blocks of PL/SQL code. No, the default value is false

Examples

    <connection id="c1" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:DB" user="sys as sysdba" password="password">
    </connection>

    <connection id="c2" driver="oracle" url="jdbc:oracle:oci:@localhost:1521:DB" user="scott" password="tiger">
        plsql=true;
    </connection>

    <script connection-id="c2"/>
        CREATE OR REPLACE PACKAGE PK_TEST_PACKAGE1 AS
            PROCEDURE PP_TEST_PROCEDURE1( param   IN  VARCHAR2);
        END PK_TEST_PACKAGE1;
        /
        CREATE OR REPLACE PACKAGE PK_TEST_PACKAGE2 AS
            PROCEDURE PP_TEST_PROCEDURE2( param   IN  VARCHAR2);
        END PK_TEST_PACKAGE2;
        /
    </script>

scriptella.driver.postgresql PostgreSQL Driver Adapter for Scriptella.

General information

Driver class:scriptella.driver.postgresql.Driver
URL:Same as for PostgreSQL JDBC Driver.
Runtime dependencies: postgresql-8x.jdbc3.jar

Driver Specific Properties

Name Description Required

Examples

    <connection driver="posgresql" url="jdbc:postgresql://localhost:5432/test" user="username" password="password">
    </connection>
scriptella.driver.script

Scriptella bridge for the JSR 223: Scripting for the Java™ Platform.

Allows usage of JSR 223 compatible scripting languages in ETL <query> and <script> elements.

The driver relies on javax.script package from Java SE 6. The default language expected by the driver is JavaScript which is bundled with JRE.

General information

Driver class:scriptella.driver.script.Driver
URL:URL of the file to read from and send output to. URIs are resolved relative to a script file. If url is not specified console (System.in/out) is used.
Runtime dependencies:Java SE 6 is required. Additional dependencies are specific to a scripting language.

Driver Specific Properties

Name Description Required
language Language used in scripts and queries. No, the default language is JavaScript.
encoding Specifies charset encoding of a character stream specified by an url connection parameter. No, the system default encoding is used.

Query and Script Syntax

This driver does not impose any limitations on a language syntax. See JSR-223 script engines project for more details on supported languages.

Scripts and queries can reference variables from ancestor elements. Declared variables are exposed to nested elements.

Implicit variable query is available in <query> elements. This variable should be used to produce a result set:

    <query><![CDATA[
        var v1 = 'This variable is visible in a child script';
        for (var i = 0; i < 10; i++) {
            query.next(); // Triggers execution of a child script.
        }]]>
        <script>
            ......
            v2 = v1 + '!';
            ......
        </script>
    </query>
See ParametersCallbackMap class Javadoc for more details.

Examples

The following query executes a child script 10 times. As the result of execution 10 records are inserted into a database table. Additionally a log file log.txt is produced.
<connection id="script" driver="script"/>
<connection id="out" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:DB"/>
<connection id="log" driver="script" url="log.txt"/>

<query connection-id="script">
    <![CDATA[
    for (var i = 0; i < 10; i++) {
        login = 'login' + i;
        //You can instantiate Java objects and invoke static methods
        var now = new java.sql.Timestamp(java.lang.System.currentTimeMillis());
        query.next(); //Executes a child script element
    }]]>

    <!-- Inserts a parameterized row into a database -->
    <script connection-id="out">
        INSERT INTO Table(ID, Login, Login_Time) VALUES (?i, ?login, ?now);
    </script>
    
    <!-- Logs the message using MessageFormat class and parent context variables -->
    <script connection-id="log">
        // create Java String array of 2 elements
        var a = java.lang.reflect.Array.newInstance(java.lang.Object, 2)
        a[0] = now;a[1] = i;
        println(format.format(a));
    >/script>
</query>

scriptella.driver.scriptella

Driver for running Scriptella ETL files.

The idea of this driver is similar to Ant's <ant> task, i.e. it is suitable for splitting ETL files into sub-projects.

When ETL file is executed from another Scriptella ETL file variables context is propagated to the callee.

General information

Driver class:scriptella.driver.scriptella.Driver
URL:URL of the ETL file to execute. URIs are resolved relative to a script file. Not required.
Runtime dependencies:None

Driver Specific Properties

Name Description Required

Script Syntax

Put ETL file names or absolute URLs directly in the body of <script> element. File paths are separated by End-Of-Line tokens.

Use standard ${name} or $name syntax for properties substitution.

<query> elements are not supported.

Examples

The following example creates a database by executing external ETL file named create_db.etl.xml and then executes an SQL script over it:
<etl>
    <connection id="createdb" driver="scriptella" url="createdb.etl.xml"/>
    <connection id="db" driver="oracle" url="jdbc:...."/>

    <script connection-id="db">
        INSERT INTO ...
    </script>
</etl>

The following example selects user_id, email from Users table and runs genreport.etl.xml and sendreport.etl.xml for each record found:

<etl>
    <connection id="db" driver="oracle" url="jdbc:...." />
    <connection id="scriptella" driver="scriptella" />

    <query connection-id="db">
        <!-- Selects User_ID and EMail, this variables are visible in nested scripts -->
        SELECT User_ID, Email FROM Users
        <script connection-id="scriptella">
            genreport.etl.xml <!-- Generates report for User_ID -->
            sendreport.etl.xml <!-- Sends produced report to Email -->
        </script>
    </query>
</etl>
scriptella.driver.spring Spring Framework Integration Driver for Scriptella.

This driver allows working in The Spring Framework environment and provides an ability to locate Spring-managed data sources.

This driver acts as a proxy and relies on JDBC Bridge.

Important:

The driver requires EtlExecutorBean to operate, see examples below.

General information

Driver class:scriptella.driver.spring.Driver
URL:Name of the DataSource bean specified in the bean factory/application context
Runtime dependencies:Spring Framework

Driver Specific Properties

Name Description Required

ETL Executor Configuration

EtlExecutorBean is intended to be configured from Spring XML configuration files. See EtlExecutorBean Javadoc for details on how to configure the executor in Spring.

Example

This example creates a table Spring_Table using a connection from Spring Datasource.

Spring Application Context

Spring application context declares a datasource and an executor. Additional properties and dependencies like progress indicator may also be injected.
<beans>
    <bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property>
        <property name="url"><value>jdbc:hsqldb:mem:spring</value></property>
        <property name="username"><value>sa</value></property>
        <property name="password"><value></value></property>
    </bean>
    <bean id="progress" class="scriptella.interactive.ConsoleProgressIndicator"/>
    <bean id="executor" class="scriptella.driver.spring.EtlExecutorBean">
        <property name="configLocation"><value>etl.xml</value></property>
        <property name="progressIndicator"><ref local="progress"/></property>
        <property name="properties"><map>
            <entry key="tableName"><value>Spring_Table</value></entry>
            </map>
        </property>
    </bean>
</beans>
ETL file etl.xml
<etl>
    <connection driver="spring" url="datasource"/>
    <script>
        CREATE TABLE ${tableName} (
            ID INT
        )
    </script>
</etl>
The usage of executor is straightforward:
EtlExecutor exec = (EtlExecutor) beanFactory.getBean("executor");
exec.execute();
Additionally you can use java.util.concurrent.Callable or java.lang.Runnable invocation interface to avoid unnecessary dependency on Scriptella in application code:
Callable exec = (Callable) beanFactory.getBean("executor");
exec.call();
scriptella.driver.sybase Scriptella Driver Adapter for Sybase ASE and ASA.

Note: The driver tries to load any of the known JDBC drivers in the following order:

  • jdbc3,jdbc2 or jdbc driver from Sybase.
  • JTDS driver

General information

Driver class:scriptella.driver.sybase.Driver
URL:Same as for Sybase JDBC Driver.
Runtime dependencies: jconn3.jar or jtds-VERSION.jar.

Driver Specific Properties

Name Description Required

Examples

    <connection driver="sybase" url="jdbc:sybase:Tds:localhost:2638/tst" user="username" password="password">
    </connection>
scriptella.driver.text

Text Driver for Scriptella.

It allows querying a text file based on regular expressions, the text driver can also be used as a lightweight replacement for Velocity to produce simple output with properties substitution.

Text driver does depends on additional libraries and is generally faster than CSV or Velocity driver.

Note: The driver doesn't use SQL syntax

General information

Driver class:scriptella.driver.text.Driver
URL:Text file URL. URIs are resolved relative to a script file directory. If url has no value the output is read from/printed to the console (System.out).
Runtime dependencies:None

Driver Specific Properties

Name Description Required
encoding Specifies charset encoding of Text files. No, the system default encoding is used.
eol End-Of-Line suffix.

Only valid for <script> elements.

No, the default value is \n.
trim Value of true specifies that the leading and trailing whitespaces in text file lines should be omitted. No, the default value is true.
flush Value of true specifies that the outputted content should flushed immediately when the <script> element completes. No, the default value is false.
skip_lines The number of lines to skip before start reading. No, the default value is 0 (no lines are skipped).

Query Syntax

Text driver supports Regular expressions syntax to query text files. The file is read line-by-line from the location specified by the URL connection property and each line is matched against the regex pattern.

If a line or a part of it matches the pattern this match produces a virtual row in a result set. The column names in a virtual result set correspond to matched regex group names. For example query foo(.*) matches foobar line and the produced result set row contains two columns(groups): 0-foobar, 1-bar. These columns can be referenced in child script or query elements by a numeric name or by a string name columnN.

It also possible to specify more than one regular expressions to match file content. Specify each regular expression on a separate line to match them using OR condition.

The Text driver uses java.util.regex implementation for pattern matching. See java.util.Pattern for supported syntax Javadoc.

Additional notes:

  • Regular expressions matching is case-insensitive
  • Empty query selects all lines from the input file.
  • The 0(zero) column name in the produced result set contains the matched line.
  • Leading and trailing whitespaces in query element and input file lines are trimmed by default.
  • Use ^ and $ boundary matchers to match the whole line.


Example:
<query>
  ^ERROR: (.*)
  WARNING: (.*Failed.*)
  ([\d]+) errors?
</query>
    
This query consists of 3 regular expressions:
  1. selects lines starting with ERROR: prefix
  2. selects WARNING lines having Failed substring
  3. selects lines containg a number of errors, e.g. "Found 5 errors".
The query selects any line satisfying one of these 3 regular expressions. Suppose input file has the following content:
Log file started...
INFO: INIT
WARNING: CPU is slow
WARNING: Failed to increase heap size
ERROR: Process interrupted
Operation completed with 1 error.
As the result of query execution the following set of rows is produced:
0 1
WARNING: Failed to increase heap size Failed to increase heap size
ERROR: Process interrupted Process interrupted
1 error 1

Script Syntax

The <script> element content is read line-by-line, for each line properties are expanded and the output is sent to the file specifed by a url connection attribute.

Additional notes:

  • Lines in the outputted file are separated by a EOL string specified by eol connection property.
  • Leading and trailing whitespaces in the output file lines are trimmed by default.
  • No escaping is performed when properties are expanded. Use String.replace or other escaping techniques to achieve output similar to CSV etc.
  • If a script is executed multiple times (e.g. inside a parent query) the output is appended to the file content.


Example:
<script>
    Inserted a record with ID=$id. Table=${table}
</script>
    
For id=1 and table=system this script produces the following output:
Inserted a record with ID=1. Table=system
    

Properties substitution

In text script and query elements ${property} or $property syntax is used for properties/variables substition.

Examples

<connection id="in" driver="text" url="data.csv">
</connection>
<connection id="out" driver="text" url="report.csv">
</connection>

<script connection-id="out">
    ID;Priority;Summary;Status
</script>

<query connection-id="in">
    <script connection-id="out">
        $rownum;$column0;$column1;$column2
    </script>
</query>

Copies rows from data.csv file to report.csv, additionally the ID column is added. The result file is semicolon separated.
scriptella.driver.velocity

Velocity Adapter for Scriptella.

This driver allows to integrate velocity templates into script files.

The content inside scipt elements managed by this driver is evaluated by Velocity engine and the output is sent to the URL specified as connection parameter.

General information

Driver class:scriptella.driver.velocity.Driver
URL:URL to send output to. URIs are resolved relative to a script file directory.
Runtime dependencies:velocity-dep-1.4.jar

Driver Specific Properties

Name Description Required
encoding Character encoding for output streams. No, the JVM default charset is used.

Example

<connection driver="scriptella.spi.velocity.Driver" url="report.html">
    encoding=UTF-8;
</connection>
Registers a velocity connection which renders its output to a file report.html in the same directory where the script file resides. UTF-8 is used to encode output.
scriptella.driver.xpath

XPath Driver for Scriptella.

Allows querying an XML file based on XPath expressions.

General information

Driver class:scriptella.driver.xpath.Driver
URL:XML file URL. URIs are resolved relative to a script file directory.
Runtime dependencies:None

Driver Specific Properties

Name Description Required
trim Value of true specifies that the leading and trailing whitespaces in text file lines should be omitted.. No, the default value is true.

Query Syntax

XPath driver supports XPath syntax to query text files.

The query is executed on a XML Document and produces a rowset for matched nodes. The attribute and element values can be referenced from nested scripts/queries. The following example illustrates querying mechanism:

Example:

XPath: /A selects root element <A>

<A B="1">
    <B>2</B>
    <C>3</C>
</A>
Available variables for matched element <A>:
NameValue
A2 3
B1
C3
The value of variable A represents text content inside XML element <A>, the value of variable B represents value of B attribute and the value of variable C represents text content inside element <C>.

Additional notes:

  • Currently only Node Set can be selected in XPath expressions, i.e. attributes or elements but not String, Boolean or Number

Script Syntax

<script> elements are not supported by the driver.

Properties substitution

In query elements ${property} or $property syntax is used for properties/variables substition.

Examples

<connection id="in" driver="xpath" url="data.xml"/>
<connection id="out" driver="text" url="report.csv"/>

<query connection-id="in">
    /HTML/BODY/TABLE/TR
    <script connection-id="out">
        $rownum;${td[0]};${td[1]}
    </script>
</query>

Extracts rows from tables in data.xml file and produces report.csv.
scriptella.execution Facade classes for xml scripts execution.
scriptella.expression Classes for working with expressions and properties substitution.
scriptella.interactive Progress Indicators and other classes related to user interaction.
scriptella.jdbc Scriptella JDBC Bridge.

As specified in Service Provider API all JDBC drivers are registered via this bridge. This procedure is transparent to end user, he only have to specify jdbc driver class name or an alias.

General information

Driver class:JDBC driver class name
URL:JDBC driver URL, e.g. jdbc:mydb:...
Runtime dependencies:Set of libraries required by the JDBC driver.

JDBC Bridge Properties

JDBC bridge makes the following configuration properties available in configuration element:

Name Description Required
statement.cache Size of prepared statements cache or 0 to disable statement caching. No, the default value is 100.
statement.separator SQL statements separator string. Similar to Ant delimiter property. No, the default value is ; (semicolon).
statement.separator.singleline True if the delimiter should only be recognized on a line by itself. Leading and trailing whitespaces are ignored when searching for a separator in statement.separator.singleline=true mode. Similar to Ant delimitertype property. No, the default value is false.
keepformat True if the original SQL formatting should be preserved.

This property is similar to Ant keepformat property except that Oracle-style hints (?*+ hint */) are always preserved in Scriptella.

No, the default value is false, i.e. extra whitespaces and comments removed.
transaction.isolation Transaction isolation level name or an integer value according to java.sql.Connection javadoc. The valid level names are: READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ and SERIALIZABLE. No, the default value is driver specific.
autocommit True if connection is in auto-commit mode. If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions.See also autocommit.size.

Note: In general avoid setting autocommit to true, because in this case an ETL process cannot be rolled back correctly. Use this parameter only for performance critical operations (bulk inserts etc.).

No, the default value is false.
autocommit.size If positive, specifies the number of statements to execute before producing implicit commit, i.e. controls how much data is committed in its batches.

Notes:

  • In general avoid using autocommit.size, because in this case an ETL process cannot be rolled back correctly. Use this parameter only for performance critical operations (bulk inserts etc.).
  • If the autocommit is true, then setting autocommit.size has no effect

No, the default value is false.

Properties Substitution

The bridge supports standard ${} variables expansion and allows to set prepared statement parameters via ?{} syntax.

Example:


var=_name
id=11
--------------------------------------
select * FROM table${var} where id=?id
-- is transformed to a JDBC prepared statement---
select * FROM table_name where id=?
-- where parameter id=11

Notes:

  • $ prefixed expressions are substituted in all parts except comments.
  • ? prefixed expressions are not substituted inside quotes and comments.

  • Example:
    --only ${prop} and ?surname are handled
         SELECT * FROM "Table" WHERE NAME="?John${prop}" and SURNAME=?surname;
        

Examples

    <connection id="in" driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:file:tmp" user="sa" classpath="hsqldb.jar">
        #Disable cache - just for example
        statement.cache=0
        #Set SQL statements separator
        statement.separator=;
    </connection>

    <connection id="out" driver="h2" url="jdbc:h2:file:out" user="sa"/>
    <query connection-id="in">
        SELECT * from Bug
        <script connection-id="out">
            INSERT INTO Bug VALUES (?ID, ?priority, ?summary, ?status);
        </script>
    </query>
scriptella.spi Service Provider Interface classes.

Service Provider Requirements

Although Scriptella supports any JDBC Driver through JDBC Bridge, writing a custom Provider may be easier and more effective. The requirements for Service Provider are minimal:

Driver Registration

No special steps are required to register Scriptella Provider. Simply specify driver class name in a driver attribute of <connection> element. Examples:
    <connection driver="provider.class.name" url="provider:url"/>
You may also specify a driver's classpath. Classpath URIs are resolved relative to an ETL file:
    <connection driver="provider.class.name" url="provider:url" classpath="driver.jar;lib/driver-addons.jar"/>
In this case the driver is loaded using a separate classloader

Driver Alias

Putting a driver into scriptella.driver.SHORT_NAME package and specifying "Driver" as a class name automatically allows referencing the driver by a SHORT_NAME alias.
Example:
<connection driver="SHORT_NAME">
loads scriptella.driver.SHORT_NAME.Driver class.

Additional Recommendations

  • url is not a required attribute for custom providers, nevertheless it may make sense to specify URL protocol for your driver.
  • If your solution performs scripts compilation and this procedure is expensive, use caching based on Resource indentities as described in javadoc for Connection.
  • Pack your provider as a JAR file setting specification title, version and other attributes in manifest. Adding a simple readme file inside a JAR may help users to quickly get how to use it.
  • Scriptella built-in drivers can be used as a reference implementation to create a new driver.
scriptella.spi.support
scriptella.tools.ant Ant tasks.

How to register

To use Scriptella tasks in a build file, the following taskdef declaration should be added:

    <taskdef resource="antscriptella.properties" classpath="scriptella.jar"/>
Note: Additional libraries required for ETL execution may also be appended to classpath:

    <taskdef resource="antscriptella.properties" classpath="scriptella.jar;hsqldb.jar"/>

EtlExecuteTask (etl)

Parameters

AttributeDescriptionRequired
fileThe script file to execute.

The .etl.xml file extension part may be ommited.

Yes, unless a nested <fileset> element is used.
inheritAllIf true, pass all properties to ETL executor. Defaults to true.No
debugIf true print debugging information.No, default value is false.
quietIf true be extra quiet.No, default value is false.
The following attributes are not supported yet
forkif enabled triggers the class execution in another VM (disabled by default)No
maxmemoryMax amount of memory to allocate to the forked VM (ignored if fork is disabled) No

Nested Elements

The task supports nested <fileset> element.

Examples

Executes etl.xml file in the current directory:
<etl/>
Executes name.etl.xml file in the current directory:
<etl file="name" />
<!--Or explicitly specifying the full name-->
<etl file="name.etl.xml" />
Executes all .etl.xml files in db directory:
<etl>
    <fileset dir="db" includes="*.etl.xml" />
</etl>

EtlTemplateTask (etl-template)

Parameters

AttributeDescriptionRequired
nameETL template name.No, default ETL template is generated.
inheritAllIf true, pass all properties to Scriptella. Defaults to true.No
debugIf true print debugging information.No, default value is false.
quietIf true be extra quiet.No, default value is false.

Nested Elements

The task has no nested elements.

Supported Templates

  • Default(no name) - Produces a simple ETL template for a quick start.
  • DataMigrator - Produces an ETL template for transferring data between tables of different databases.

Examples

Produce default ETL template
<etl-template/>
Produce data migration template:

    <property file="etl.properties"/>
    <!--
    Ant properties
        driver,class,user,password
    must be set before calling "DataMigrator" etl-template 
    -->
    <etl-template name="DataMigrator"/>
scriptella.tools.launcher Command line ETL launcher.

Examples

Execute etl.xml file in the current directory:
scriptella
Execute name.etl.xml file in the current directory:
scriptella name
Also the full name of ETL file can be specified:
scriptella name.etl.xml
Produce a quick start template named etl.xml in the current directory:
scriptella -t
scriptella.tools.template ETL templates and support classes.
scriptella.util Miscellaneous utility classes.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.