Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Fyodor Kupolov http://j2ee.by.ru

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Using JavaScript for ETL transformations

Scriptella provides a simple way to perform various transformations in JavaScript (or other scripting language which have a corresponding driver).
Our example transformation consists of 3 steps:
1) Select rows from source table.
2) Transform a column value from number to text
3) Insert a transformed value into a destination table.


<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
    <connection id="db" driver="auto" url="jdbc:hsqldb:mem:tst" user="sa" password="" classpath="../lib/hsqldb.jar"/>
    <connection id="js" driver="script"/> 
    <connection id="log" driver="text"/> <!-- For printing debug information on the console -->

    <script connection-id="db">
        CREATE TABLE Table_In (
            Error_Code INT
        );
        CREATE TABLE Table_Out (
            Error VARCHAR(10)
        );
        
        INSERT INTO Table_IN VALUES (1);
        INSERT INTO Table_IN VALUES (7);
    </script>

    <query connection-id="db">
        SELECT * FROM Table_In
        <script connection-id="log">
            Transforming $Error_Code
        </script>
        <!-- Transformation is described as an enclosing query
         which is executed before nested elements -->
        <query connection-id="js"> 
            <![CDATA[
               if (Error_Code < 5) {
                    Error_Code='WARNING'; //Set a transformed value
               } else {
                    Error_Code='ERROR'; //Set a transformed value
               }
               query.next(); //Don't forget to trigger nested scripts execution
            ]]>
            <script connection-id="db">
                <!-- Insert transformed value -->
                INSERT INTO Table_Out VALUES (?Error_Code); 
            </script>
            <script connection-id="log">
                Transformed to $Error_Code
            </script>
        </query>
    </query>
</etl>

JS cache control

The following JSP snippet shows a simple caching policy for JS files, i.e.
the browser fetches js files when a new build is available.

qBuildNum is a build number or a repository revision suffix, e.g.?102 etc.
ServerInfoService.getBuildNumber() is a function which returns current build number. This function has to be coded manually, alternatively a servlet context attribute can be used...
<%
    String qBuildNum = '?' + ServerInfoService.getBuildNumber(); //Suffix for JS to avoid caching
%>
<script type="text/javascript" src="dwr/engine.js?113"></script>
<script type="text/javascript" src="dwr/util.js?113"></script>
<script type="text/javascript" src="rico/prototype.js?14"></script>
<script type="text/javascript" src="rico/rico.js?112"></script>
<script type="text/javascript" src="script/controller.js<%=qBuildNum%>"></script>
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS