Skip to content

Instantly share code, notes, and snippets.

@FoxInCloud
Forked from StevenBlack/sessionfactory.prg
Last active June 22, 2016 10:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FoxInCloud/9ecd988ed4c56cf44d69e98c3c6aab84 to your computer and use it in GitHub Desktop.
Save FoxInCloud/9ecd988ed4c56cf44d69e98c3c6aab84 to your computer and use it in GitHub Desktop.
SessionFactory creates objects that are wrapped in a private data session. Note that the factory can die but its private datasession lives until all its products are out of scope.
*=======================================
DEFINE CLASS SessionFactory AS Session
*=======================================
DataSession = 2 && private
*==========================
FUNCTION Init()
SET CENTURY TO 20 ROLLOVER 50
SET CENTURY ON
SET DELETED ON
SET EXACT OFF
SET EXCLUSIVE OFF
SET MEMOWIDTH TO 8000
SET MULTILOCKS ON
SET NEAR OFF
SET NULL OFF
SET SAFETY OFF
SET TALK OFF
SET SECONDS OFF
SET STRICTDATE TO 0
RETURN
*==========================
FUNCTION Execute( tcCommand )
*==========================
&tcCommand
RETURN
*==========================
FUNCTION CreateObject(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26 )
*==========================
LOCAL cParm, iParm
cParm = ''
for iParm = 1 to PCOUNT()
cParm = m.cParm;
+ ',';
+ iif(iParm > 1;
, '@'; && pass parameters by reference in case .init() needs it (e.g. arrays) ...
, ''; && ... except class name (parameter #1)
);
+ 'm.p'; && use 'm.' for safety
+ cast(m.iParm as I)
endfor
cParm = substr(m.cParm, 2)
return CREATEOBJECT(&cParm)
ENDDEFINE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment