Topics on this page:

Installation Instructions

This section provides installation instructions and lists dependencies.

Dependencies

Transform4J requires the following software:

  • Java JDK 1.6 or above
  • Transform4J unit tests are run using Java JDK versions 1.6, 1.7, and 1.8

  • SLF4J
  • SLF4J can be downloaded from the site here. Transform4J is tested against version 1.5.11 of SLF4J.

    The MongoDB data source and target depend on the Java MongoDB Driver available here.

    The Cassandra data source and target depend on the DataStax Java Driver available here.

    Not to state the obvious, but the JDBC data source and target requires a JDBC driver implementation for your chosen relational database.

    Installation

    Download Transform4J and place the bundled jar in your classpath. You can download Transform4J here.

    Running simple extracts and loads

    This example will create a JSON format extract file based on a relational database source.

    Create a class (either class with Main() or test case). Copy the code below into it. Note that you will need to change the JDBC connect url and supply a valid user and password. You'll also need to supply a valid select statement. Run the sample!

    // Register your JDBC driver using DriverManager.registerDriver()
    JDBCDataSource myDataSource = new JDBCDataSource("driverConnectUrl", "myLogin", "myPassword")
    JdbcDataSource source = new JdbcDataSource(myDataSource, "select * from customer");
    JsonDataTarget target = new JsonDataTarget(new File("c:/myFile.json"));
    target.setPrettyPrinting(true);
    
    SimpleExtract extract = new SimpleExtract(source, target);
    Transform4j.runTransformation(extract);
    			

    More information on running extracts can be found here.

    Writing your first transformation

    This simple transformation combines the first name, last name, and middle initial to the format "Last, First I". Real-life transformations will have more custom logic than this, but you get the idea.

    public class MyTranformation extends Transformer<DataRecord> {
    
    	@Override
    	protected void process(DataRecord input) {
    
    		DataRecord output = new DataRecord();
    		
    		// Insert logic to derive the full name here
    		StringBuffer nameBuffer = new StringBuffer(input.getValueAsString("lastName"));
    		nameBuffer.append(", ");
    		nameBuffer.append(input.getValueAsString("firstName"));
    		
    		String middleInitial = input.getValueAsString("middleInitial");
    		if (middleInitial != null) {
    			nameBuffer.append(" ");
    			nameBuffer.append(middleInitial);
    		}
    		
    		// Set the output with the full name and write it.
    		output.setValue("fullName", nameBuffer.toString());		
    		this.getTransformerDataTarget().insert(record);
    	}
    
    }
    			

    More information on writing transformations can be found here.