Post date: May 31, 2016 5:49:40 AM
The generated eDapters now support get and put Object list. Below are the code snippets for the getting and putting object list for an eDapter. DataHandler class should be instantiated with valid eDapter Toolkit URL before calling these methods in the code.
Call getObjectListFromEdapterR2O method in dataHandler by passing the eDapter R2O module name and where clause with parameter values. This method returns ArrayList which contains required eDapter bean objects.
Create DataHandler class object before using the below API - Here is the code snippet to create DataHandler, tconnector.jar contains DataHandler class, keep this jar in the classpath to execute.
DataHandler dataHandler = new DataHandler(etkServiceURL);
For example: etkServiceURL = http://hletkdev.global.triniti.com:8680/etk/jsp/InstanceRunnerServlet;
get object list code snippet
if(t_gps_nodetype_states.NODETYPE_STATE_ID != null && dataHandler != null)
{
String whereClause = "T_GPS_PROPERTY_CHANGE_SETS.NODETYPE_STATE_ID = ?";
Vector valueVector = ObjectPool.getVector();
valueVector.add(t_gps_nodetype_states.NODETYPE_STATE_ID);
valueVector.add("java.lang.Double");
ArrayList objectList = dataHandler.getObjectListFromEdatperR2O("code.TAB_WHAT_IF_PROPERTIES_CHANGE.TrinitiJavaCode_TAB_WHAT_IF_PROPERTIES_CHANGE_R2O", whereClause, valueVector);
if(objectList != null && !objectList.isEmpty())
{
t_gps_nodetype_states.t_gps_property_change_sets = (T_GPS_PROPERTY_CHANGE_SETS[])objectList.toArray(new T_GPS_PROPERTY_CHANGE_SETS[objectList.size()]);
}
/*
* clean objects
*/
ObjectPool.freeVector(valueVector);
}
Call putObjectListToEdapterO2R method in dataHandler by passing ArrayList which contains required eDapter bean objects and eDapter O2R module name. This method returns commit count.
put object list code snippet
ArrayList objectList = new ArrayList(Arrays.asList(t_GPS_NODETYPE_STATES.t_gps_property_change_sets));
if(objectList != null && !objectList.isEmpty() && dataHandler != null)
{
int commitCount = dataHandler.putObjectListToEdapterO2R(objectList, "code.TAB_WHAT_IF_PROPERTIES_CHANGE.TrinitiJavaCode_TAB_WHAT_IF_PROPERTIES_CHANGE_O2R");
LOGGER.debug("code.TAB_WHAT_IF_PROPERTIES_CHANGE.TrinitiJavaCode_TAB_WHAT_IF_PROPERTIES_CHANGE_O2R commitCount : " + commitCount);
}
Here are some technical details about this API:
DataHandler object takes java objects and convert them into XML content before sending it to eDapter Engine for processing. This XML conversion is required when API is called from signed code because eDapter Toolkit doesn't sign the generated eDapters and respected bean classes. If this XML conversion is not available, then API calling from signed code will raise exceptions at server side due to mismatch between signed and unsigned bean classes.
If client application uses un-signed jars, then below API syntax should be used to eliminate the XML conversion - object to XML and XML to object, in the process:
boolean isXMLConversionRequired = false;
int commitCount = dataHandler.putObjectListToEdapterO2R(objectList, "code.TAB_WHAT_IF_PROPERTIES_CHANGE.TrinitiJavaCode_TAB_WHAT_IF_PROPERTIES_CHANGE_O2R",isXMLConversionRequired );
These methods are very useful when eDapters are used in the implementation code.
In case of failure in getting or putting data to eDapter through DataHandler, exception / error raised during the process can be accessed using the following code:
Exception exception = dataHandler.getGeneratedException();
eDapter tool kit has introduced a new API to call eDapters from Java code using the below code snippet.
Code snippet for eDapter call
To run a eDapter from Java code, pass the eDapter model name as a parameter to runETKModel method in DataHandler class.
HashMap resultMap = dataHandler.runETKModel(modelName);
It will return a HashMap with the result of the call.
if(!resultMap.containsKey("generatedException"))
{
String result = (String)resultMap.get("result");
}
else
{
String exceptionMessage= (String)resultMap.get("generatedException");
}
eDapter tool kit has enhanced the API's to add below functionalities
Run eDapter (R2O / O2R / Model) with dynamic connections
Pass Where condition while calling an eDapter
Code snippet for Dynamic connections
ArrayList objectList = dataHandler.getObjectListFromEdapterR2O(R2OclassName, whereCondition, valueVector, loggedInUser, sourceDataBase);
sourceDataBase - Represents the connection to be used in R2O execution
Ex : ArrayList objectList = dataHandler.getObjectListFromEdatperR2O("code.TAB_WHAT_IF_PROPERTIES_CHANGE.TrinitiJavaCode_TAB_WHAT_IF_PROPERTIES_CHANGE_R2O", whereClause, valueVector, "TRINITI");
For calling O2R :
int commitCount = putObjectListToEdapterO2R(objectList, O2RClass, loggedInUser, destinationDataBase);
destinationDataBase - Represents the connection to be used in O2R execution
Ex: int commitCount = dataHandler.putObjectListToEdapterO2R(objectList, "code.TAB_WHAT_IF_PROPERTIES_CHANGE.TrinitiJavaCode_TAB_WHAT_IF_PROPERTIES_CHANGE_O2R" , "TRINITI");
Limitation - The selected connections (sourceDataBase, destinationDataBase) should be there in ETK Pool Configuration before running the model.
Code snippet for eDapter call
HashMap paramHash = new HashMap();
paramHash.put("SOURCE_DB", "TRINITI"); -- To set the connection for R2O node
paramHash.put("DESTINATION_DB", "TEST"); -- To set the connection for O2R node
paramHash.put("dynamicWhereClause", "BATCH_ID = 12"); -- To pass Where condition to the Select query in R2O node
dataHandler.runETKModel("ParentModel",paramHash);
Code snippet for eDapter call with Query Tokens
String whereConditionClause = "TRIM(AD_CLIENT.NAME) = ? AND TRIM(AD_ORG.NAME) = ?";
Vector whereConditionsVector = new Vector();
whereConditionsVector.add(vendor_INVOICE.getCLIENT());
whereConditionsVector.add(vendor_INVOICE.getCLIENT().getClass().getName());
whereConditionsVector.add(vendor_INVOICE.getORGANIZATION());
whereConditionsVector.add(vendor_INVOICE.getORGANIZATION().getClass().getName());
HashMap queryTokensMap = new HashMap();
queryTokensMap.put("$CREATED_BY$", vendor_INVOICE.getCREATED_BY());
queryTokensMap.put("$ISO_CODE$", vendor_INVOICE.getCURRENCY());
queryTokensMap.put("$CURRENCY_CONVERSION_TYPE$", vendor_INVOICE.getCURRENCY_CONVERSION_TYPE());
queryTokensMap.put("$DOC_TYPE_INVOICE$", vendor_INVOICE.getDOC_TYPE_INVOICE());
queryTokensMap.put("$DOC_TYPE_PAYMENT$", vendor_INVOICE.getDOC_TYPE_PAYMENT());
queryTokensMap.put("$PRICELIST$", vendor_INVOICE.getPRICELIST());
queryTokensMap.put("$UOM$", vendor_INVOICE.getUOM());
queryTokensMap.put("$BANK_ACCOUNT$", vendor_INVOICE.getBANK_ACCOUNT());
queryTokensMap.put("$TAX$", vendor_INVOICE.getTAX());
Object[] rowsArray = (Object[]) dataHandler.getDataFromETK("code.VENDOR_INVOICE_REQUIRED_DATA.TrinitiJavaCode_VENDOR_INVOICE_REQUIRED_DATA_R2O", whereConditionClause, whereConditionsVector, "getColumnAndDataArraysHashMap", null, null, queryTokensMap);