Best way to get a JDBC connection inside a custom transform?

Discussion on developing CloverETL engine, transformation components etc.

davidleelambert
Posts: 2
Joined: Mon Aug 16, 2010 11:05 pm

Best way to get a JDBC connection inside a custom transform?

Postby davidleelambert » Sat Mar 17, 2012 3:40 pm

I'm writing some CloverETL graphs that have one JDBC source connection and write one or more flat files. One of the problems I need to solve is mismatch between the data-format of certain database fields and how they are supposed to appear in the flat file. I have a database table that provides the lookup information I need; however, I don't want to use a CloverETL DBJoin or LookupJoin node to solve it, because I have many fields in the record that all need the exact same transformation.

Is there an easy way of getting the set of all JDBC connections defined in the current graph, from within custom transformation code (that is, from within a class that implements "org.jetel.component.DataRecordTransform" and whose fully-qualified name is used as the value of the "Transform class" property of a node)?

(for my particular problem, so far, I can assume that there is only one such connection, and that it is suitable for that purpose; if there was more than one, could I choose a particular one by ID, or by its "name" property?)

mzatopek
Posts: 76
Joined: Fri May 11, 2007 9:49 am

Re: Best way to get a JDBC connection inside a custom transform?

Postby mzatopek » Mon Mar 19, 2012 1:35 pm

Within your custom transformation code you can easily get a connection with following code:

Code: Select all

public class MyTrans extends DataRecordTransform {
...
public boolean init() {
  DBConnection bdConnection = getGraph().getConnection(parameters.getProperty("myCustomPropertyNameWithConnectionId"));
  //OR
  for (String connectionId : getGraph().getConnections()) {
    bdConnection = (DBConnection) getGraph().getConnection(connectionId);
  }
  return true;
}


Variable parameters is available from DataRecordTransform class and contains all custom attributes of your Reformat component:

Code: Select all

<Node enabled="enabled" guiName="Reformat" id="REFORMAT1" type="REFORMAT" myCustomPropertyNameWithConnectionId="connectionId">


Martin
Martin Zatopek
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at http://www.cloveretl.com