DynamicLibrary - Parallel Transporter

Teradata® Parallel Transporter Application Programming Interface Programmer Guide

Product
Parallel Transporter
Release Number
17.10
Published
June 2021
Language
English (United States)
Last Update
2021-07-01
dita:mapPath
ang1608578408836.ditamap
dita:ditavalPath
obe1474387269547.ditaval
dita:id
B035-2516
lifecycle
previous
Product Category
Teradata Tools and Utilities

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
............
conn->AddAttribute(TD_SYSTEM_OPERATOR,TD_LOAD);
schema->AddColumn("Associate_Id",TD_INTEGER,4,1,1);
dmlGr->AddStatement(dml_statment);
...............
delete(lib_hdl);   //Unload the library