<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: java code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 29 Aug 2008 16:25:24 GMT</pubDate>
    <description>DZone Snippets: java code</description>
    <item>
      <title>Using JavaScript for ETL transformations</title>
      <link>http://snippets.dzone.com/posts/show/5236</link>
      <description>&lt;a href="http://scriptella.javaforge.com"&gt;Scriptella&lt;/a&gt; provides a simple way to perform various transformations in JavaScript (or other scripting language which have a corresponding driver). &lt;br /&gt;Our example transformation consists of 3 steps:&lt;br /&gt;1) Select rows from source table.&lt;br /&gt;2) Transform a column value from number to text&lt;br /&gt;3) Insert a transformed value into a destination table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;connection id="db" driver="auto" url="jdbc:hsqldb:mem:tst" user="sa" password="" classpath="../lib/hsqldb.jar"/&gt;&lt;br /&gt;    &lt;connection id="js" driver="script"/&gt; &lt;br /&gt;    &lt;connection id="log" driver="text"/&gt; &lt;!-- For printing debug information on the console --&gt;&lt;br /&gt;&lt;br /&gt;    &lt;script connection-id="db"&gt;&lt;br /&gt;        CREATE TABLE Table_In (&lt;br /&gt;            Error_Code INT&lt;br /&gt;        );&lt;br /&gt;        CREATE TABLE Table_Out (&lt;br /&gt;            Error VARCHAR(10)&lt;br /&gt;        );&lt;br /&gt;        &lt;br /&gt;        INSERT INTO Table_IN VALUES (1);&lt;br /&gt;        INSERT INTO Table_IN VALUES (7);&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;&lt;br /&gt;    &lt;query connection-id="db"&gt;&lt;br /&gt;        SELECT * FROM Table_In&lt;br /&gt;        &lt;script connection-id="log"&gt;&lt;br /&gt;            Transforming $Error_Code&lt;br /&gt;        &lt;/script&gt;&lt;br /&gt;        &lt;!-- Transformation is described as an enclosing query&lt;br /&gt;         which is executed before nested elements --&gt;&lt;br /&gt;        &lt;query connection-id="js"&gt; &lt;br /&gt;            &lt;![CDATA[&lt;br /&gt;               if (Error_Code &lt; 5) {&lt;br /&gt;                    Error_Code='WARNING'; //Set a transformed value&lt;br /&gt;               } else {&lt;br /&gt;                    Error_Code='ERROR'; //Set a transformed value&lt;br /&gt;               }&lt;br /&gt;               query.next(); //Don't forget to trigger nested scripts execution&lt;br /&gt;            ]]&gt;&lt;br /&gt;            &lt;script connection-id="db"&gt;&lt;br /&gt;                &lt;!-- Insert transformed value --&gt;&lt;br /&gt;                INSERT INTO Table_Out VALUES (?Error_Code); &lt;br /&gt;            &lt;/script&gt;&lt;br /&gt;            &lt;script connection-id="log"&gt;&lt;br /&gt;                Transformed to $Error_Code&lt;br /&gt;            &lt;/script&gt;&lt;br /&gt;        &lt;/query&gt;&lt;br /&gt;    &lt;/query&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 16 Mar 2008 12:01:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5236</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>How to execute Scriptella ETL files</title>
      <link>http://snippets.dzone.com/posts/show/4862</link>
      <description>&lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; provides several ways to execute ETL files:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Invocation from Ant&lt;/b&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;taskdef resource="antscriptella.properties" classpath="/path/to/scriptella.jar[;additional_drivers.jar]"/&gt;&lt;br /&gt;&lt;etl file="path/to/etl/file/&gt; &lt;!-- Execute ETL file from specified location --&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;b&gt;Command-Line Execution&lt;/b&gt;&lt;br /&gt;Just type scriptella to run the file named etl.xml in the current directory. Alternatively you can use Java launcher:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;java -jar scriptella.jar [arguments]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;b&gt;Executing ETL Files from Java&lt;/b&gt;&lt;br /&gt;It is extremely easy to run Scriptella ETL files from java code. Just make sure scriptella.jar is on classpath and use any of the following methods to execute an ETL file:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;EtlExecutor.newExecutor(new File("etl.xml")).execute(); //Execute etl.xml file&lt;br /&gt;EtlExecutor.newExecutor(getClass().getResource("etl.xml")).execute(); //Execute etl.xml file loaded from classpath&lt;br /&gt;EtlExecutor.newExecutor(&lt;br /&gt;    servletContext.getResource("/WEB-INF/etl.xml")).execute(); //Execute etl.xml file from web application WEB-INF dir&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;b&gt;Integration with Spring Framework&lt;/b&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;beans&gt;&lt;br /&gt;    &lt;!-- Spring beans declarations --&gt;&lt;br /&gt;&lt;br /&gt;    &lt;!-- Spring managed bean which executes etl.xml file --&gt;&lt;br /&gt;    &lt;bean id="executor" class="scriptella.driver.spring.EtlExecutorBean"&gt;&lt;br /&gt;        &lt;property name="configLocation" value="etl.xml"/&gt;&lt;br /&gt;    &lt;/bean&gt;&lt;br /&gt;&lt;/beans&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The usage of executor is straightforward:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;EtlExecutor exec = (EtlExecutor) beanFactory.getBean("executor");&lt;br /&gt;exec.execute();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;See &lt;a href="http://scriptella.javaforge.com/docs/api/scriptella/driver/spring/package-summary.html#package_description"&gt;Spring Driver JavaDoc&lt;/a&gt; for additional details.&lt;br /&gt;</description>
      <pubDate>Fri, 07 Dec 2007 21:10:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4862</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>How to produce daily database table dumps in CSV format</title>
      <link>http://snippets.dzone.com/posts/show/4790</link>
      <description>The following code demonstrates how to produce CSV files with dynamic&lt;br /&gt;file name pattern based on a current day. The produced files have the following naming format:&lt;br /&gt;TABLE_NAME_MM_DD_YYYY.csv&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;properties&gt; &lt;!-- Configure table name --&gt;&lt;br /&gt;        table_name=test&lt;br /&gt;    &lt;/properties&gt;&lt;br /&gt;    &lt;connection id="in" driver="auto" url="jdbc:oracle:thin:@localhost:1521:ORCL" &lt;br /&gt;      classpath="ojdbc14.jar" user="scott" password="tiger"/&gt;&lt;br /&gt;    &lt;connection id="out" driver="csv" url="${table_name}_${etl.date.now('MM_dd_yyyy')}.csv" /&gt;&lt;br /&gt;    &lt;query connection-id="in"&gt; &lt;!-- Query table rows --&gt;&lt;br /&gt;        SELECT * FROM ${table_name}&lt;br /&gt;        &lt;script connection-id="out"&gt; &lt;!-- Export each row into a CSV --&gt;&lt;br /&gt;            $ID, $Name, $Surname &lt;!-- Use column names from selected table --&gt;&lt;br /&gt;        &lt;/script&gt;&lt;br /&gt;    &lt;/query&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Use &lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; to run the example. &lt;br /&gt;&lt;br /&gt;See &lt;a href="http://snippets.dzone.com/posts/show/4862"&gt;How to execute an ETL file&lt;/a&gt; from command line, Ant or directly from Java .</description>
      <pubDate>Fri, 16 Nov 2007 21:08:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4790</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>Splitting large Scriptella ETL files</title>
      <link>http://snippets.dzone.com/posts/show/4216</link>
      <description>The following example demonstrates how to split a large &lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; file into several parts. This example is based on a traditional XML parsed entities approach:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&lt;br /&gt;[&lt;br /&gt;    &lt;!-- Declaring the first external parsed entity to include --&gt;&lt;br /&gt;    &lt;!ENTITY part1 SYSTEM "part1.xml"&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;!-- Declaring the second external parsed entity to include --&gt;&lt;br /&gt;    &lt;!ENTITY part2 SYSTEM "part2.xml"&gt;&lt;br /&gt;]&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;connection driver="text"/&gt;&lt;br /&gt;&lt;br /&gt;    &lt;!-- Including file #1 --&gt;&lt;br /&gt;    &amp;part1;&lt;br /&gt;&lt;br /&gt;    &lt;script&gt;&lt;br /&gt;        content of the script&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;!-- Including file #2 --&gt;&lt;br /&gt;    &amp;part2;&lt;br /&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 27 Jun 2007 20:33:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4216</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>List of Countries and ISO codes Supported by the JVM.</title>
      <link>http://snippets.dzone.com/posts/show/3787</link>
      <description>The following code displays country names and ISO-codes for the locales supported by the JVM.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;        for (Locale locale : Locale.getAvailableLocales()) {&lt;br /&gt;            final String contry = locale.getDisplayCountry();&lt;br /&gt;            if (contry.length() &gt; 0) {&lt;br /&gt;                System.out.println("Country = " + contry + ". ISO code: " + locale.getISO3Country());&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 09 Apr 2007 09:04:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3787</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>Package Name as a Constant</title>
      <link>http://snippets.dzone.com/posts/show/3762</link>
      <description>getClass().getPackage().getName() is not a reliable solution, because getPackage() can be null depending on a class loader.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;static final String PACKAGE_NAME = MyClass.class.getName().substring(0, &lt;br /&gt;            MyClass.class.getName().lastIndexOf('.'));&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 04 Apr 2007 19:21:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3762</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
  </channel>
</rss>
