17.00 - DynamicLibrary - Parallel Transporter

Teradata® Parallel Transporter Application Programming Interface Programmer Guide

Parallel Transporter
June 2020
Programming Reference

A dynamic library wrapper class, called DynamicLibrary, encapsulates the loading of the Teradata PT API library and the loading of objects from the shared library, hiding the low-level details from the rest of the application. The class is implemented as a singleton class to ensure that the library is dynamically loaded once and to provide a global point of access to the loaded library.

The following is the class interface:

// To load TPTAPI library
static DynamicLibrary*  Instance ();

// Create objects out of the loaded library
ConnectionX*   newConnectionX ();
ConnectionX*   newConnectionX (TD_Encoding encoding);
DMLGroupX*     newDMLGroupX ();
DMLGroupX*     newDMLGroupX (TD_Encoding encoding);
SchemaX*       newSchemaX (char* stype);
SchemaX*       newSchemaX (TD_Encoding encoding);

// Delete objects created out of the loaded library
void  delConnectionX (ConnectionX*);
void  delDMLGroupX (DMLGroupX*);
void  delSchemaX (SchemaX*);  

A DynamicLibrary object is created through the static method DynamicLibrary::Instance(), which loads the Teradata PT API library and all the entry function pointers available in the library. Once the library has been loaded, the DynamicLibrary can be used to create new objects of the class ConnectionX, DMLGroupX, and SchemaX by calling the appropriate function (for example, newConnectionX(), new DMLGroupX, new SchemaX).

After an object is created, simply call any available methods on the object via its pointer. The loaded library is closed when the DynamicLibrary object is deleted. The DynamicLibrary destructor handles closing the loaded library.

The following code snippet shows how easily dynamic loading can be implemented in an application:

DynamicLibrary  *lib_hdl;
lib_hdl = DynamicLibrary::Instance(); //Load the library

//Create ConnectionX object
ConnectionX *conn = lib_hdl->newConnectionX();

//Create SchemaX object
SchemaX *schema = lib_hdl >newSchemaX("input");

//Create DMLGroupX object
DMLGroupX * dmlGr = lib_hdl->newDMLGroupX();

lib_hdl->delConnectionX(conn);  //Delete ConnectionX object
lib_hdl->delDMLGroupX(dmlGr);   //Delete DMLGroupX object
lib_hdl->delSchemaX(schema);    //Delete SchemaX object
delete(lib_hdl);   //Unload the library