Retrieve Media Object Text from F00165
I used the cache API's to add the media text to cache and retrieve the media text from cache.Firstly I used an API called "jdeGTGet_GenericTextKeyStr" to load the Media Text in to a data structure field is "pMOData" by using the primary keys in a table F00165.
jdeGTGet_GenericTextKeyStr (lpDS->szNameObject, lpDS->GenericTextKey, iSequenceNum, &pMOData, &lTotalRec);
Actually we have the media object system function GTXXXX used to retrieve the Media Text,why i created this business function is to retrieve the Media Text by the Specified size of characters in a line,so we cannot retrieve the Media text directly for huge length of text,thatswhy i used the cache API's to Add and Fetch Media Text from the Cache.The API's used as follows
To add into Cache
jdeCacheAdd(hCache, (void *) &dsCacheData,(long int) sizeof(DS5600165C));
Retrieve From Cache
jdeCacheFetchPosition(hCache, hCacheCursor,&dsCacheKeys,(short int)0,&dsCacheData,sizeof(dsCacheData));
jdeCacheFetch(hCache, hCacheCursor, &dsCacheData ,(void *)NULL);
I used a logic to split the Media Text from the whole Media Text
iLength = jdeStrlen(pMOData->pData);
jdeStrncpy(pMOData->pData,
pMOData->pData,
DIM(pMOData->pData)-1);
iCounter = 0;
while ( iLoopIndex < iLength )
{
dsCacheData.szMediaText[iCounter++] = pMOData->pData[iPosition++];
if(iLoopIndex%120==0)
{
jdeStrncpy(dsCacheData.szMediaText,
pMOData->pData,
DIM(pMOData->pData)-1);
MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
JDECMReturn = jdeCacheAdd(hCache, (void *) &dsCacheData,(long int) sizeof(DS5600165C)); jdeStrcpy(dsCacheData.szMediaText,dsCacheData.GenericTextKey,DIM(dsCacheData.GenericTextKey)-1);
iCounter=0;
}
I used the Data structure for Cache and Media Object Text as follows as
LPMODATA pMOData;/* Data Structure for the Media Object */
typedef struct
{
MATH_NUMERIC mnJobnumber;
JCHAR szComputerID[16];
JCHAR cModeProcessing;
JCHAR szNameObject[11];
JCHAR GenericTextKey[255];
MATH_NUMERIC mninsertCounter;
int nMediaObjectSequenceNumber;
JCHAR cSuppressErrorMessage;
JCHAR szErrorMessageId[11];
JCHAR szMediaText[255];
/*PJSTR pMediaText;*/
} DS5600165C, *LPDS5600165C;/* Data Structure for the Cache */
typedef struct
{
MATH_NUMERIC mnJobnumber;
MATH_NUMERIC insertCounter[15];
JCHAR szComputerID[16];
} KEY_DS5600165C, LPKEY_DS5600165C;
Cache Business Function Header File as follows as
/*****************************************************************************
* Header File: B5600165.h
*
* Description: Retrieve Media Object Text from F00165 Header File
*
* History:
* Date Programmer SAR# - Description
* ---------- ---------- -------------------------------------------
* Author 09-06-2014 Unkno Unknown - Created
*
*
* Copyright (c) J.D. Edwards World Source Company, 1996
*
* This unpublished material is proprietary to J.D. Edwards World Source
* Company. All rights reserved. The methods and techniques described
* herein are considered trade secrets and/or confidential. Reproduction
* or distribution, in whole or in part, is forbidden except by express
* written permission of J.D. Edwards World Source Company.
****************************************************************************/
#ifndef __B5600165_H
#define __B5600165_H
/*****************************************************************************
* Table Header Inclusions
****************************************************************************/
/*****************************************************************************
* External Business Function Header Inclusions
****************************************************************************/
#include <b0000564.h>
/*****************************************************************************
* Global Definitions
****************************************************************************/
/*****************************************************************************
* Structure Definitions
****************************************************************************/
LPMODATA pMOData;/* Data Structure for the Media Object */
typedef struct
{
MATH_NUMERIC mnJobnumber;
JCHAR szComputerID[16];
JCHAR cModeProcessing;
JCHAR szNameObject[11];
JCHAR GenericTextKey[255];
MATH_NUMERIC mninsertCounter;
int nMediaObjectSequenceNumber;
JCHAR cSuppressErrorMessage;
JCHAR szErrorMessageId[11];
JCHAR szMediaText[255];
/*PJSTR pMediaText;*/
} DS5600165C, *LPDS5600165C;/* Data Structure for the Cache */
typedef struct
{
MATH_NUMERIC mnJobnumber;
MATH_NUMERIC insertCounter[15];
JCHAR szComputerID[16];
} KEY_DS5600165C, LPKEY_DS5600165C;
/*****************************************************************************
* DS Template Type Definitions
****************************************************************************/
/**
* TYPEDEF for Data Structure
* D5600165 : Add Media Objects to Cache
*
* Copyright Oracle USA
*
* This is a JDEdwards EnterpriseOne generated file.
* Do not modify this file.
* Only re-generate with the appropriate tool.
* Generation Date : 15-06-2014
*/
#ifndef DATASTRUCTURE_D5600165
#define DATASTRUCTURE_D5600165
typedef struct tagDSD5600165
{
MATH_NUMERIC mnJobnumber;
JCHAR szComputerID[16];
JCHAR cActionCode;
JCHAR szNameObject[11];
JCHAR GenericTextKey[255];
int nMediaObjectSequenceNumber;
JCHAR cSuppressErrorMessage;
JCHAR szErrorMessageId[11];
JCHAR szLengthOfString[4];
MATH_NUMERIC mnLengthOfString;
} DSD5600165 , *LPDSD5600165;
#define IDERRmnJobnumber_1 1L
#define IDERRszComputerID_2 2L
#define IDERRcActionCode_3 3L
#define IDERRszNameObject_4 4L
#define IDERRGenericTextKey_5 5L
#define IDERRnMediaObjectSequenceNumber_6 6L
#define IDERRcSuppressErrorMessage_7 7L
#define IDERRszErrorMessageId_8 8L
#define IDERRszLengthOfString_10 10L
#define IDERRmnLengthOfString_11 11L
#endif /* DATASTRUCTURE_D5600165 */
/*****************************************
* TYPEDEF for Data Structure
* Template Name: Retrieve Media Objects from Cache
* Template ID: D5600165A
* Generated: Mon Jun 09 18:53:05 2014
*
* DO NOT EDIT THE FOLLOWING TYPEDEF
* To make modifications, use the OneWorld Data Structure
* Tool to Generate a revised version, and paste from
* the clipboard.
*
**************************************/
#ifndef DATASTRUCTURE_D5600165A
#define DATASTRUCTURE_D5600165A
typedef struct tagDSD5600165A
{
MATH_NUMERIC mnJobnumber;
JCHAR szComputerID[16];
JCHAR cActionCode;
JCHAR szMediaTextOutput[176];
} DSD5600165A, *LPDSD5600165A;
#define IDERRmnJobnumber_1 1L
#define IDERRszComputerID_2 2L
#define IDERRcActionCode_3 3L
#define IDERRszMediaTextOutput_4 4L
#endif
/*****************************************************************************
* Source Preprocessor Definitions
****************************************************************************/
#if defined (JDEBFRTN)
#undef JDEBFRTN
#endif
#if defined (WIN32)
#if defined (WIN32)
#define JDEBFRTN(r) __declspec(dllexport) r
#else
#define JDEBFRTN(r) __declspec(dllimport) r
#endif
#else
#define JDEBFRTN(r) r
#endif
/*****************************************************************************
* Business Function Prototypes
****************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI AddMediaTextToCache (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165 lpDS);
JDEBFRTN (ID) JDEBFWINAPI RetrieveMediaextFromCache (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165A lpDS);
/*****************************************************************************
* Internal Function Prototypes
****************************************************************************/
JDECM_RESULT I5600165_CreateCache ( HUSER hUser, HCACHE *hCache );
#endif /* __B5600165_H */
Cache Business Function Source File:
#include <jde.h>
#define b5600165_c
/*****************************************************************************
* Source File: b5600165
*
* Description: Retrieve Media Object Text from F00165 Source File
*
* History:
* Date Programmer SAR# - Description
* ---------- ---------- -------------------------------------------
* Author 09-06-2014 Unkno Unknown - Created
*
* Copyright (c) J.D. Edwards World Source Company, 1996
*
* This unpublished material is proprietary to J.D. Edwards World Source Company.
* All rights reserved. The methods and techniques described herein are
* considered trade secrets and/or confidential. Reproduction or
* distribution, in whole or in part, is forbidden except by express
* written permission of J.D. Edwards World Source Company.
****************************************************************************/
/**************************************************************************
* Notes:
*
**************************************************************************/
#include <b5600165.h>
/**************************************************************************
* Business Function: AddMediaTextToCache
*
* Description: Add Media Object Text To Cache
*
* Parameters:
* LPBHVRCOM lpBhvrCom Business Function Communications
* LPVOID lpVoid Void Parameter - DO NOT USE!
* LPDSD560 lpDS Parameter Data Structure Pointer
*
*************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI AddMediaTextToCache (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165 lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
HUSER hUser ;
HCACHE hCache = (HCACHE) NULL;
HJDECURSOR hCacheCursor = (HJDECURSOR) NULL;
ID idJDBReturn = JDEDB_PASSED;
long lTotalRec = 0;
int iSequenceNum = 0;
JCHAR szMediaText;
ID idReturnCode = ER_SUCCESS;
int iCounter = 0;
int iLoopIndex = 1;
int iPosition = 0;
int iLength = 0;
MATH_NUMERIC mninsertCounter = {1};
PJSTR pSegment = NULL;
int i = 0, iSegmentNum = 0;
JCHAR token[2] = {0};
/************************************************************************
* Cache Management variables and structures
************************************************************************/
ID JDECMReturn = JDECM_PASSED ;
JCHAR szCacheName[41]= {0};
JCHAR szJobNumberString[MAXLEN_MATH_NUMERIC] = {0};
/************************************************************************
* Declare structures
************************************************************************/
KEY_DS5600165C dsCacheKeys ;
DS5600165C dsCacheData ;
DSD0000564 dsNextNumbers;
/************************************************************************
* Declare pointers
************************************************************************/
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5600165) NULL))
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}
/************************************************************************
* Set pointers
************************************************************************/
idJDBReturn = JDB_InitBhvr((void *) lpBhvrCom, &hUser, (JCHAR *) _J('\0'),JDEDB_COMMIT_AUTO);
if(idJDBReturn==JDEDB_PASSED)
{ /* allocate the cache memory */
JDECMReturn = I5600165_CreateCache ( hUser, &hCache );
jdeCacheOpenCursor(hCache, &hCacheCursor);
}
else
{
jdeSetGBRError(lpBhvrCom, lpVoid, (ID) 0, _J("3143"));
return (ER_ERROR);
}
/************************************************************************
* Main Processing
************************************************************************/
ParseNumericString (&mninsertCounter, _J("1"));
iSequenceNum = 1;
/*Sequence would the ordinal number in MO Texts*/
if (iSequenceNum < 0)
{ jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("164F"), (LPVOID) NULL);
return (ER_ERROR);
}
else
{
idJDBReturn = jdeGTGet_GenericTextKeyStr (lpDS->szNameObject, lpDS->GenericTextKey, iSequenceNum, &pMOData, &lTotalRec);
if (idJDBReturn == JDEDB_PASSED)
{
memset((void *)(&dsCacheData), (int)(_J('\0')), sizeof(DS5600165C));
memset((void *)(&dsCacheKeys), (int)(_J('\0')), sizeof(KEY_DS5600165C));
if(JDECMReturn==JDECM_PASSED)
{
MathCopy(&dsCacheKeys.mnJobnumber,&lpDS->mnJobnumber);
jdeStrncpy((JCHAR *)dsCacheKeys.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
if (hCacheCursor)
{
JDECMReturn = jdeCacheFetchPosition(hCache, hCacheCursor,(void *) &dsCacheKeys,(short int)3,(void *) &dsCacheData,sizeof(DS5600165C));
}
else
{
lpDS->cSuppressErrorMessage=_J('1');
}
/* Get Internal Number */
idReturnCode = jdeCallObject(_J("GetInternalNextNumber"), NULL, lpBhvrCom, (void *)lpVoid, &dsNextNumbers,(CALLMAP *)NULL, (int)0, (JCHAR *)NULL, (JCHAR *)NULL, (int)0);
if (idReturnCode != ER_SUCCESS)
{
jdeErrorSet(lpBhvrCom, lpVoid, (ID)0, _J("3143"), (LPVOID)NULL);
JDB_FreeBhvr(hUser);
return idReturnCode;
}
MathCopy(&lpDS->mnJobnumber,&dsNextNumbers.mnJobnumberA);
MathCopy(&dsCacheData.mnJobnumber,&lpDS->mnJobnumber);
jdeStrcpy((JCHAR *)dsCacheData.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
ZeroMathNumeric(&dsCacheData.mninsertCounter);
iLength = jdeStrlen(pMOData->pData);
jdeStrncpy(pMOData->pData,
pMOData->pData,
DIM(pMOData->pData)-1);
iCounter = 0;
while ( iLoopIndex < iLength )
{
dsCacheData.szMediaText[iCounter++] = pMOData->pData[iPosition++];
if(iLoopIndex%120==0)
{
jdeStrncpy(dsCacheData.szMediaText,
pMOData->pData,
DIM(pMOData->pData)-1);
MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
JDECMReturn = jdeCacheAdd(hCache, (void *) &dsCacheData,(long int) sizeof(DS5600165C));
jdeStrcpy(dsCacheData.szMediaText,dsCacheData.GenericTextKey,DIM(dsCacheData.GenericTextKey)-1);
iCounter=0;
}
iLoopIndex++;
}
lpDS->cActionCode=_J('0');
if (JDECMReturn != JDECM_PASSED)
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("0002"), (LPVOID) NULL);
return (ER_ERROR);
jdeCacheCloseCursor(hCache, hCacheCursor);
}
}
else
{
jdeStrcpy(lpDS->szErrorMessageId,_J("CACHE CURSOR OPEN FAILED"));
}
}
else
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("0002"), (LPVOID) NULL);
return (ER_ERROR);
}
}
/************************************************************************
* Function Clean Up
************************************************************************/
if(hCacheCursor != (HJDECURSOR)NULL)
{
jdeCacheCloseCursor(hCache, hCacheCursor);
}
JDB_FreeBhvr(hUser);
return (ER_SUCCESS);
}
/**************************************************************************
* Function: I5600165_CreateCache
*
* Notes: This function will create the cache.
*
* Returns: Standard ID
*
* Parameters:
* LPBHVRCOM lpBhvrCom Business Function Communications.
* LPVOID lpVoid Void Parameter - DO NOT USE!
*
**************************************************************************/
JDECM_RESULT I5600165_CreateCache ( HUSER hUser, HCACHE *hCache )
{
/************************************************************************
* Variable declarations
************************************************************************/
JDECM_RESULT JDECMReturn = JDECM_PASSED ;
/************************************************************************
* Declare structures
*************************************************************************/
/* create 2 indexes */
JDECMINDEXSTRUCT dsCacheKeys1[1];
DS5600165C dsKeys ;
KEY_DS5600165C dsCacheKeys;
/************************************************************************
* Declare pointers
************************************************************************/
/************************************************************************
* Main Processing
************************************************************************/
memset((void *)(&dsCacheKeys1), (int)(_J('\0')), sizeof(JDECMINDEXSTRUCT));
memset((void *) (&dsKeys), (int)( _J('\0')), sizeof(DS5600165C));
dsCacheKeys1->nNumSegments = (short int)3;
dsCacheKeys1->CacheKey[0].nOffset= (short int)offsetof(DS5600165C, mnJobnumber);
dsCacheKeys1->CacheKey[0].nSize = (short int) sizeof(dsKeys.mnJobnumber);
dsCacheKeys1->CacheKey[0].idDataType = EVDT_MATH_NUMERIC;
dsCacheKeys1->CacheKey[1].nOffset= (short int)offsetof(DS5600165C, szComputerID);
dsCacheKeys1->CacheKey[1].nSize = (short int)DIM(dsKeys.szComputerID);
dsCacheKeys1->CacheKey[1].idDataType = EVDT_STRING;
dsCacheKeys1->CacheKey[2].nOffset= (short int)offsetof(DS5600165C, mninsertCounter);
dsCacheKeys1->CacheKey[2].nSize = (short int) sizeof(dsKeys.mninsertCounter);
dsCacheKeys1->CacheKey[2].idDataType = EVDT_MATH_NUMERIC;
/*FormatMathNumeric(szJobNumberString, &lpDS->mnJobnumber);*/
JDECMReturn = jdeCacheInit(hUser, hCache, _J("B5600165"), dsCacheKeys1);
return (JDECMReturn);
} /* end of I5600165_CreateCache */
/**************************************************************************
* Business Function: RetrieveMediaextFromCache
*
* Description: Retrieve Media Object Text From Cache
*
* Parameters:
* LPBHVRCOM lpBhvrCom Business Function Communications
* LPVOID lpVoid Void Parameter - DO NOT USE!
* LPDSD5600 lpDS Parameter Data Structure Pointer
*
*************************************************************************/
JDEBFRTN (ID) JDEBFWINAPI RetrieveMediaextFromCache (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5600165A lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
JDECM_RESULT JDECMReturn = JDECM_PASSED ;
JCHAR szJobNumberString[MAXLEN_MATH_NUMERIC] = {0};
HCACHE hCache;
HJDECURSOR hCacheCursor;
HUSER hUser;
ID idJDBReturn = JDEDB_PASSED;
MATH_NUMERIC mninsertCounter ;
int iLoopIndex,n=0, numRows=0,nFirsttime;
/************************************************************************
* Declare structures
************************************************************************/
DS5600165C dsCacheData;
JDECMINDEXSTRUCT dsCacheKeys1[1];
KEY_DS5600165C dsCacheKeys;
/************************************************************************
* Declare pointers
************************************************************************/
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5600165A) NULL))
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}
/************************************************************************
* Set pointers
************************************************************************/
idJDBReturn = JDB_InitBhvr((void *) lpBhvrCom, &hUser, (JCHAR *) _J('\0'),JDEDB_COMMIT_AUTO);
if(idJDBReturn!=JDEDB_PASSED)
{
jdeSetGBRError(lpBhvrCom, lpVoid, (ID) 0, _J("3143"));
return (ER_ERROR);
}
/************************************************************************
* Main Processing
************************************************************************/
JDECMReturn = I5600165_CreateCache ( hUser, &hCache );
if(lpDS->cActionCode==_J('0'))
{ nFirsttime=1;
ParseNumericString (&mninsertCounter, _J("1"));
ZeroMathNumeric(&dsCacheData.mninsertCounter);
/*Load Keys */
MathCopy(&dsCacheKeys.mnJobnumber,&lpDS->mnJobnumber);
jdeStrncpy((JCHAR *)dsCacheKeys.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
MathCopy(&dsCacheData.mnJobnumber,&lpDS->mnJobnumber);
jdeStrcpy((JCHAR *)dsCacheData.szComputerID, lpDS->szComputerID,DIM(dsCacheKeys.szComputerID) - 1);
MathCopy(&dsCacheData.mninsertCounter,&mninsertCounter);
JDECMReturn=jdeCacheOpenCursor(hCache,&hCacheCursor);
}
/*MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);*/
if (hCacheCursor==NULL)
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("0002"), (LPVOID) NULL);
return (ER_ERROR);
}
else
{
memset((void *)(&dsCacheData), (int)(_J('\0')), sizeof(DS5600165C));
memset((void *)(&dsCacheKeys), (int)(_J('\0')), sizeof(KEY_DS5600165C));
if(nFirsttime==1)
{
if(hCacheCursor)
{
MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
MathCopy(&dsCacheData.mninsertCounter,&mninsertCounter);
JDECMReturn = jdeCacheFetchPosition(hCache, hCacheCursor,&dsCacheKeys,(short int)0,&dsCacheData,sizeof(dsCacheData));
}
nFirsttime=0;
}
else
{
if(hCacheCursor)
{
MathAdd(&dsCacheData.mninsertCounter, &dsCacheData.mninsertCounter, &mninsertCounter);
MathCopy(&dsCacheKeys.insertCounter,&mninsertCounter);
MathCopy(&dsCacheData.mninsertCounter,&mninsertCounter);
JDECMReturn = jdeCacheFetch(hCache, hCacheCursor, &dsCacheData ,(void *)NULL);
}
}
if (JDECMReturn == JDECM_PASSED)
{
jdeStrcpy((JCHAR *)lpDS->szMediaTextOutput,dsCacheData.szMediaText);
lpDS->cActionCode=_J('1');
}
else
{
JDECMReturn = I5600165_CreateCache (hUser, &hCache);
if (JDECMReturn == JDECM_PASSED)
{
jdeCacheTerminateAll(hUser, hCache);
}
lpDS->cActionCode=_J('0');
}
}
/************************************************************************
* Function Clean Up
************************************************************************/
if(lpDS->cActionCode==_J('0'))
{
if(hCacheCursor!= NULL)
{
jdeCacheCloseCursor (hCache, hCacheCursor);
}
return (ER_SUCCESS);
}
}