Data Source Library

This section provides instructions on supported Transform4J Data Sources.

Topics on this page:

Next section.

CSV Inputs

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:

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

    CsvDataSource  dataSource = new CsvDataSource("myFileName");
    dataSource.setFieldNames(new String[]{"First Name", "Last Name", "Middle Initial"}); 
    				

    Additional information can be found in the CsvDataSource javadoc.

    JSON Inputs

    A description of the JSON format can be found here.

    Example usage is as follows:

    JsonDataSource  dataSource = new JsonDataSource("myFileName");
    				

    Additional information can be found in the JsonDataSource javadoc.

    Relational Databases

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

    There are a few things to remember:

  • Only database connections created by JdbcDataSource will be closed. If you provide an established connection, JdbcDataSource 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.

    JdbcDataSource  dataSource = new JdbcDataSource(myDataSource, "select * from Customer");
    				

    Additional information can be found in the JdbcDataSource 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

    MongoDB

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

    Example usage for the full read of a collection follows:

    MongoDbDataSource  dataSource = new MongoDbDataSource();
    dataSource.setDatabaseName("myDatabaseName");
    dataSource.setDatabaseLocation(new ServerPortVO[]{new ServerPortVO("localhost", 27017)});
    dataSource.setCollectionName("myCollectionName");
    				

    Example usage for map reducing read follows: myMapReduceCommand must be an instance of com.mongodb.MapReduceCommand.

    MongoDbMapReduceDataSource  dataSource = new MongoDbMapReduceDataSource();
    dataSource.setDatabaseName("myDatabaseName");
    dataSource.setDatabaseLocation(new ServerPortVO[]{new ServerPortVO("localhost", 27017)});
    dataSource.setCollectionName("myCollectionName");
    dataSource.setMapReduceCommand(myMapReduceCommand);
    				

    Additional information can be found in the MongoDbDataSource and MongoDbMapReduceDataSource JavaDoc.

    Cassandra Databases

    Cassandra databases are supported using the Cassandra DataStax client driver, which can be found here.

    Example usage is as follows: myClusterServerName is the host name or IP of your Cassandra database cluster.

    CassandraDataSource  dataSource = new CassandraDataSource(myClusterServerName, "select * from Customer");
    				

    Additional information can be found in the CassandraDataSource javadoc.

    Next section.