Data Target Library

This section provides instructions on supported Transform4J Data Targets.

Topics on this page:

Next section.

CSV Output

A relatively complete description of the CSV format can be found here. This format doesn't have a formal specification.

As there isn't a formal specification for the CSV format, rules are as follows. CsvDataTarget will automatically do the following:

  • String values with spaces are enclosed in double-quote characters.
  • Field values containing double-quote characters as content are escaped them with the '\' character.
  • Fields are separated by commas; tab or space delimiters aren't currently supported.
  • Example usage is as follows:

    CsvDataTarget  csvTarget = new CsvDataTarget("myFileName");
    
    //  From within a Transformer...
    csvTarget.insert(dataRecord);
    				

    Additional information can be found in the CsvDataTarget javadoc.

    JSON Output

    A description of the JSON format can be found here.

    Example usage is as follows:

    JsonDataTarget  jsonTarget = new JsonDataTarget("myFileName");
    
    //  From within a Transformer...
    jsonTarget.insert(dataRecord);
    				

    Additional information can be found in the JsonDataTarget javadoc.

    Relational Databases

    Any relational database that can be updated via JDBC is supported by Transform4J.

    There are a few things to remember:

  • Only database connections created by JdbcDataTarget will be closed. If you provide an established connection, JdbcDataTarget will not close it as it doesn't have execution context.
  • Example usage is as follows: myDataSource must be an instance of javax.sql.DataSource.

    JdbcDataTarget  dataTarget = new JdbcDataTarget(myDataSource, "Customer_Table", new String[]{"Customer_Id"});
    
    //  From within a Transformer...
    dataTarget.insert(dataRecord);
    
    //  Will either update rows if found using the keys, or insert rows if they don't exist
    dataTarget.saveOrUpdate(dataRecord);
    
    //  Will update rows if found using the keys
    dataTarget.update(dataRecord);
    
    //  Will delete rows if found using the keys.
    dataTarget.delete(dataRecord);
    				

    Additional information can be found in the JdbcDataTarget javadoc.

    If you're not executing Transform4J in a Java EE container and don't have an implementation of javax.sql.DataSource already available, Transform4J provides a basic implementation here

    Cassandra

    Cassandra databases are supported through the MongoDB Java driver. Both normal and map reducing reads are supported.

    Example setup follows:

    CassandraDataTarget  dataTarget = new CassandraDataTarget("localhost");
    dataTarget.setKeyFields(new String[]{"id"});
    dataTarget.setTableName("testMe.myDatabases");
    				

    Example usage from within a Transformer

    //  From within a Transformer...
    dataTarget.insert(dataRecord);
    
    //  Will either update rows if found using the keys, or insert rows if they don't exist
    dataTarget.saveOrUpdate(dataRecord);
    
    //  Will update rows if found using the keys
    dataTarget.update(dataRecord);
    
    //  Will delete rows if found using the keys.
    dataTarget.delete(dataRecord);
    				

    Additional information can be found in the CassandraDataTarget JavaDoc.

    MongoDB

    MongoDB databases are supported through the MongoDB Java driver. Both normal and map reducing reads are supported.

    Example setup follows:

    MongoDbDataTarget  dataTarget = new MongoDbDataTarget();
    dataTarget.setDatabaseName("myDatabaseName");
    dataTarget.setDatabaseLocation(new ServerPortVO[]{new ServerPortVO("localhost", 27017)});
    dataTarget.setCollectionName("myCollectionName");
    dataTarget.setKeyFields(new String[]{"Customer_Id"});
    				

    Example usage from within a Transformer

    //  From within a Transformer...
    dataTarget.insert(dataRecord);
    
    //  Will either update rows if found using the keys, or insert rows if they don't exist
    dataTarget.saveOrUpdate(dataRecord);
    
    //  Will update rows if found using the keys
    dataTarget.update(dataRecord);
    
    //  Will delete rows if found using the keys.
    dataTarget.delete(dataRecord);
    				

    Additional information can be found in the MongoDbDataTarget JavaDoc.