Description
This method can be extended with code to execute when an instance of a business class is started.
PreCondition
This method is executed when a new instance of the business class is started, or when a draft instance is opened (in that case a new instance is started which is a copy of the draft instance).
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program1/business.p)
<M-8 run LoadSystemSettings (output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
if viTransactionID <> 0
and vcFcComponentName <> "session":U
then do:
assign vlTransaction = yes
viFcCount1 = 1.
do while program-name(viFcCount1) <> ?:
if program-name(viFcCount1) = "InitInstance program/transaction.p":U
then vlTransaction = no.
viFcCount1 = viFcCount1 + 1.
end.
end.
if vlTransaction
then do:
assign vcShortList = dynamic-function("gipr_GetShortList" in {&TARGETPROCEDURE}).
if entry(1, vcShortList) = "BCustom"
then do:
<M-38 run GetPublicData
(input 'vcCustomComponent' (icDataList),
output vcCustComp (ocValues),
output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
assign entry(1, vcShortList) = "BCustom[" + vcCustComp + "]".
end.
/*
The transaction class is not closed here. It should stay in memory so other instances can be added.
It will be closed either in de appserver deactivate procedure or when the transaction is stopped.
*/
<I-1 {bFcOpenInstance
&CLASS = "Transaction"}>
<M-3 run AddInstance
(input viFcCurrentInstanceId (iiInstanceNr),
input vcShortList (icClass),
input ? (iiCompVersion),
output vlTransactionMainInstance (olFirst),
output viLocalReturn (oiReturnStatus)) in Transaction>
if viLocalReturn <> 0
then oiReturnStatus = viLocalReturn.
if viLocalReturn < 0
then return.
end.
if viSessionID <> 0
and vcFcComponentName <> "session":U
then do:
<M-4 run StartCacher (output vhFcComponent (ohCacher),
output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<M-5 run ReadSessionValues (output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
if viSessionID <> 0 and
vcFcComponentName <> "session":U
then do:
<M-96 run StartCacher (output vhFcComponent (ohCacher),
output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
<M-76 run GetSessionTimeout
(input viSessionID (iiSessionId),
output vcThisGlobalSessionId (ocGlobalSessionId),
output vtThisGlobalLastCheckDate (otGlobalLastCheckDate),
output viThisGlobalLastCheckTime (oiGlobalLastCheckTime),
output vtThisLastCheckDate (otLastCheckDate),
output viThisLastCheckTime (oiLastCheckTime),
output viThisTimeout (oiTimeout),
output viSessionDebugLevel (oiGlobalSessionDebugLevel)) in Cacher>
If vcThisGlobalSessionId = ?
Then Do:
vcMsg = Trim(#T-15'No fcSession record is found for this Session ID ($1).':100(9390)T-15#).
assign oiReturnStatus = -10. /*Time Out*/
<M-16 run SetMessage
(input vcMsg (icMessage),
input viSessionID (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'S':U (icType),
input 1 (iiSeverity),
input '' (icRowid),
input 'BLF-263':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in business>
Return.
End.
if viSessionDebugLevel > 0
then run SetDebugLevelInPool (viSessionDebugLevel, viSessionId, no).
/*skip check if SessionTiomeOut = 0*/
If viThisTimeout <> 0
Then Do:
<Q-86 assign vlFcQueryRecordsAvailable = DaemonInfo (NoCache)
(input 0, (DaemonId)
input {&TIMEOUTDAEMON}, (DaemonName)
input {&DAEMONSTATUS-RUNNING}, (DaemonStatus)
input '', (DaemonStatusDiffersFrom)) in BBaseDaemon>
/* Use date and time in UTC */
session:timezone = 0.
/* ================================================================== */
/* The Daemon is not running, we call the service to update sess_mstr */
/* ================================================================== */
If vlFcQueryRecordsAvailable = no
then do :
/* run the update when the timeout is passed more than half */
if ((Today - vtThisGlobalLastCheckDate) * 24 * 60) + ((Time - viThisGlobalLastCheckTime) / 60) > (viThisTimeout / 2)
then Do:
/* Timeout daemon is not active */
if com.qad.qra.config.QraConfig:IsEnabled
then do:
<I-78 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "False"
&CLASS = "PAuthenticationQRA"}>
<M-79 run KeepAlive
(input vcThisGlobalSessionId (icGlobalSessionId),
input yes (ilUpdateSession),
output vlIsAlive (olIsActive),
output viFcReturnSuper (oiReturnStatus)) in PAuthenticationQRA>
<I-48 {bFcCloseAndStopInstance
&CLASS = "PAuthenticationQRA"}>
end.
else do:
<I-17 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "False"
&CLASS = "PAuthentication"}>
<M-18 run KeepAlive
(input vcThisGlobalSessionId (icGlobalSessionId),
input yes (ilUpdateSession),
output vlIsAlive (olIsActive),
output viFcReturnSuper (oiReturnStatus)) in PAuthentication>
<I-19 {bFcCloseAndStopInstance
&CLASS = "PAuthentication"}>
end.
If viFcReturnSuper <> 0
Then Assign oiReturnStatus = viFcReturnSuper.
If viFcReturnSuper < 0
Then Return.
If vlIsAlive
Then Do:
/* if the session is still valid, we update the FIN session (fcSession) */
<M-32 run StartPersistence
(output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
Assign vcQuery = "for each fcSession where fcSession.SessionInstance_ID = ":U + String(viSessionID).
<M-33 run WriteDirect
(input 'fcSession':U (icTableName),
input vcQuery (icPrepare),
input 'GlobalSessionNeedsUpdate,SessionLastCheckTime,SessionLastCheckDate,GlobalSessionLastCheckTime,GlobalSessionLastCheckDate':U (icFieldList),
input 'l,i,t,i,t':U (icFieldListDataTypes),
input 'false' + chr(2) + string(Time) + chr(2) + string(Today) + chr(2) + string(Time) + chr(2) + string(Today) (icAbsolute),
input '' (icIncremental),
input {&TARGETPROCEDURE} (ihClass),
input vcUserLogin (icUserLogin),
output viFcReturnSuper (oiReturnStatus)) in persistence>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
End. /* If vlIsAlive */
Else Do:
/* if the session is not valid anymore, we remove the FIN session (fcSession) */
<M-34 run StartPersistence
(output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
/*delete the record*/
Assign vcQuery = "for each fcSession where fcSession.SessionInstance_ID = ":U + String(viSessionID).
<M-35 run WriteDirect
(input 'fcSession':U (icTableName),
input vcQuery (icPrepare),
input '' (icFieldList),
input '' (icFieldListDataTypes),
input '' (icAbsolute),
input '' (icIncremental),
input {&TARGETPROCEDURE} (ihClass),
input vcUserLogin (icUserLogin),
output viFcReturnSuper (oiReturnStatus)) in persistence>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
Assign oiReturnStatus = -10. /*Time Out*/
Return.
End. /* else vlIsAlive */
end. /* ((Today - vtThisLastCheckDate) * 24 * 60) + ((Time - viThisLastCheckTime) / 60) > (viThisTimeout / 2) */
End. /* if vlFcQueryRecordsAvailable */
Else do:
/* If Daemon is running, we update the FIN session only. The update of sess_mstr is done by the daemon */
If Today <> vtThisLastCheckDate Or (Time - viThisLastCheckTime) > 60
Then Do:
Assign vlGlobalSessionNeedsUpdate = ((Today - vtThisGlobalLastCheckDate) * 24 * 60) + ((Time - viThisGlobalLastCheckTime) / 60) > (viThisTimeout / 2).
<M-30 run StartPersistence
(output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in business>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
Assign vcQuery = "for each fcSession where fcSession.SessionInstance_ID = ":U + String(viSessionID).
<M-31 run WriteDirect
(input 'fcSession':U (icTableName),
input vcQuery (icPrepare),
input 'GlobalSessionNeedsUpdate,SessionLastCheckTime,SessionLastCheckDate':U (icFieldList),
input 'l,i,t':U (icFieldListDataTypes),
input (if vlGlobalSessionNeedsUpdate then 'true' else 'false') + chr(2) + string(Time) + chr(2) + string(Today) (icAbsolute),
input '' (icIncremental),
input {&TARGETPROCEDURE} (ihClass),
input vcUserLogin (icUserLogin),
output viFcReturnSuper (oiReturnStatus)) in persistence>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
End.
end. /* else vlFcQueryRecordsAvailable */
End. /* If viThisTimeout <> 0 */
End. /* if */
finally:
session:timezone = viTimeOffset.
end finally.