// ToDo: Enter the Java packages to be imported here // For example, if you want to use Hashtable in any of the snippets, import the Hashtable // as shown below: // // import java.util.Hashtable; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.ListIterator; import java.lang.Math; import java.text.SimpleDateFormat; import java.util.*; import java.util.HashMap; static String logInfoOption=" "; static HashMap TransactionList=new HashMap(); static HashMap MaxTrnIdList=new HashMap();
double getMaxTransIdLocal(String acctNumber) { double maxTransId=0; //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Looking for max trans id in LOCAL ARRAY for "+acctNumber); try { //long startTime=System.currentTimeMillis(); if(MaxTrnIdList.containsKey(acctNumber)) { Double maxId=(Double)(MaxTrnIdList.get(acctNumber)); maxTransId=maxId.doubleValue(); } //long endTime=System.currentTimeMillis(); // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Lookup completed in "+((endTime-startTime))+" milliSeconds"); }
catch(NumberFormatException npe) { printLogMsg("NumberFormatException in getMaxTransIdLocal(): args>"+acctNumber+"--"+npe.getMessage()); } finally { return maxTransId; } } Double getMaxTransIdDB(String acctNumber) { Double transId=new Double(0); Double temp=new Double(0); // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Looking for max trans id in DATABASE for "+acctNumber); try { //long startTime=System.currentTimeMillis(); if((temp=(Double)invokeJExpression(":LKP.LKP_GET_MAX_TRAN(X1)", new Object [] {acctNumber}))!=null) { transId=temp; } //long endTime=System.currentTimeMillis(); // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Lookup completed in "+((endTime-startTime))+" milliSeconds"); } catch(SDKException sde) { printLogMsg("SDKException caught in getDupRecDB() on: "+acctNumber+" :"+sde.getMessage()); } finally { return transId; } }
Double getDupRecDB(String acctNumber, String transTime) { Double transId=new Double(0); Double temp=new Double(0); // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Looking for duplicate records in DATABASE for "+acctNumber+ ", "+transTime); try { //long startTime=System.currentTimeMillis(); if((temp=(Double)invokeJExpression(":LKP.LKP_GET_DUP_REC(X1, X2)", new Object [] {acctNumber, transTime}))!=null) { transId=temp; } //long endTime=System.currentTimeMillis(); // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Lookup completed in "+((endTime-startTime))+" milliSeconds"); } catch(SDKException sde) { printLogMsg("SDKException caught in getDupRecDB() on: "+acctNumber+", "+transTime.toString()+" :"+sde.getMessage()); } finally { return transId; } } double getDupRecLocal(String acctNumber, String transTime) { String[] transactionDetails; double TransId=0; // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Looking for duplicate records in LOCAL ARRAY for "+acctNumber+ ", "+transTime); try {
// long startTime=System.currentTimeMillis();
if(TransactionList.containsKey(acctNumber+"#"+transTime)) { Double OTransId=(Double)(TransactionList.get(acctNumber+"#"+transTime)); TransId=OTransId.doubleValue(); } // long endTime=System.currentTimeMillis(); // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Lookup completed in "+((endTime-startTime))+" milliSeconds"); } catch(NumberFormatException npe) { printLogMsg ("NumberFormatException in getDupRecLocal(): args>"+acctNumber+", "+transTime+"--"+npe.getMessage()); } finally { return TransId; } } /** * printLogMsg() takes a String argument and logs it after concatenating * with a specified string. */ void printLogMsg (String msg) { logInfo ("group transaction Java Log: " + msg); } /**End of Method Declaration**/
IS_DUP="n"; String acctNumString=new String(ACCT_NO);/*Integer.toString(tempAcctNumInt);*/ String transTimeString=new String(TRAN_TIME);/*(dateFormatter.format(date)).toString();*/ if((getDupRecLocal(acctNumString, transTimeString))==0)
{ //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("No dupe record in DB--checking in Hashmap--"); double duplicateTIdDB=getDupRecDB(acctNumString, transTimeString).doubleValue(); if(duplicateTIdDB==0) { //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("No dupe record in hashmap.Fetching max TIds from hashmap..."); double maxTIdLocal=getMaxTransIdLocal(acctNumString); double maxTIdDB=0; double TIdNew=0; if(maxTIdLocal==0) { //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("No records in hashmap for this a/c no.Fetching max TIds from DB..."); maxTIdDB=getMaxTransIdDB(acctNumString).doubleValue(); if(maxTIdDB==0) { //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("No records in DB for this a/c no.Assigning 1 as the TId"); TIdNew=1; TransactionList.put(acctNumString+"#"+transTimeString,new Double(TIdNew)); MaxTrnIdList.put(acctNumString,new Double(TIdNew)); } else { // if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Record exist in DB for this a/c no..Max TRN_ID found is :"+ maxTIdDB+"..Adding +1 and reassigning TId"); TIdNew=maxTIdDB+1; TransactionList.put(acctNumString+"#"+transTimeString,new Double(TIdNew)); MaxTrnIdList.put(acctNumString,new Double(TIdNew)); } } else {
//if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Record exist in hashmap for this a/c no..TRN_ID :"+maxTIdLocal+"....Adding +1 and reassigning TId"); TIdNew=maxTIdLocal+1; TransactionList.put(acctNumString+"#"+transTimeString,new Double(TIdNew)); MaxTrnIdList.put(acctNumString,new Double(TIdNew)); } //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("New record inserted with acct_no,trns_ts and trn_no as :-"+acctNumString+","+transTimeString+","+TIdNew); TRN_NO=TIdNew; ACCT_NO_OUT=acctNumString; } else { //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Dupe record exists in DB. Output TId="+duplicateTIdLocal); TRN_NO=duplicateTIdDB; ACCT_NO_OUT=acctNumString; IS_DUP="y"; } } else { double outputTId=getDupRecLocal(acctNumString, transTimeString); //if(logInfoOption.compareToIgnoreCase("verbose")==0) printLogMsg("Dupe record exists in hashmap. Output TId="+outputTId); TRN_NO=outputTId; ACCT_NO_OUT=acctNumString; IS_DUP="y"; } / ToDo: Enter code that executes when all the input data is received by the transformation here // // logInfo("The number of null rows for this partition is : " + partCountNullRows); // synchronized(lock)
// { // logInfo("The total number of null rows across partitions till now is : " + countNullRows); // }