Extracts

This section provides instructions on how to use Transform4J to accomplish data extracts.

Extracts require three Transform4J constructs: Transformer, TransformerDataSource, and TransformerDataTarget. TransformerDataSource classes retrieve data from a supported data source such as any relational database with a JDBC driver, CSV files, MongoDB, etc. TransformerDataTarget classes write data to any supported data storage media such as any relational database with a JDBC driver, CSV files, MongoDB, etc. Transformer classes move data from the source to the target making any changes desired along the way.

SimpleExtract Utility

Transform4J provides a basic Transformer for data extracts called SimpleExtract and we will use it for all our examples. However, if you want to make custom transformations in the extract, it's easy to implement your own Transformer.

The SimpleExtract utility supports functions. Functions are classes that compute additional fields based on the extract input. See Functions for more information.

The SimpleExtract utility supports filters. Filters are classes that screen out unwanted input records. See Filters for more information.

You can register field name simple field name changes. Sometimes this is useful if the target is a relational database which has pre-defined names that don't match your input. For example, I can change field 'firstName' in the input to 'FIRST_NAME' in the output without creating a custom transformation.

See SimpleExtract javadoc.

Example: CSV Extract from a relational database

This code runs a CSV extract in line (i.e. in the same thread)

JdbcDataSource source = new JdbcDataSource(myDataSource, "select * from customer");
CsvDataTarget target = new CsvDataTarget(new File("c:/extracts/myFile.csv"));

SimpleExtract extract = new SimpleExtract(source, target);
Transform4j.runTransformation(extract);
				

This code runs the same extract in a spawned separate thread asynchronously. Instead of manually creating a new thread for the extract, I could have scheduled it with a product like Spring Batch or Quartz.

JdbcDataSource source = new JdbcDataSource(myDataSource, "select * from customer");
CsvDataTarget target = new CsvDataTarget(new File("c:/extracts/myFile.csv"));

SimpleExtract extract = new SimpleExtract(source, target);
Runnable extractRunnable = Transform4j.makeRunnable(extract);
(new Thread(extractRunnable)).start();