Tips_todo   >   Sql   >   Session Pools
At the time of writing this tip, to the best of my knowledge, session pools are only included with the Omnis Web Development license. The pricing structure has been changing so session pools might become standard equipment for the developer version in future.
(The following information has been copied from the F1 Help.)
Pools of session instances can be created when Omnis starts up and made available to any methods running within Omnis. They are designed to be used by the multi-threaded server and allow client methods to quickly obtain SQL sessions without the burden of constructing their own instances.
There is a notation group $root.$sessionpools that contains the current session pools. Normally the session pools are created by the startup task and exist until Omnis is shut down.
When a session is required in order to perform a SQL query, it is obtained from the pool using an object variable and a statement object created in the normal way in order to execute the query and fetch any results. When the session object variable is destroyed the session instance is returned to the pool for later reuse.
SESSION POOL NOTATION
The group $sessionpools has the usual $findname, $first, $next and $makelist notation. The $remove() method is also implemented but not $add() since $makepool() is used to create a session pool.
A pool has the $name, $poolsize and $inuse properties. The $poolsize property is the number of instances stored in the pool and $inuse is the number of these which are currently assigned out. If you increase the value of $poolsize the new session instances are immediately constructed and if the hostname, username and password parameters were specified at $makepool, they are also logged on.
An alternative form of the $new() method is poolone.$new(pWaitSeconds) which is designed to be used in client methods running on the multi-threaded server. If there are no sessions currently available in the pool this waits for the specified number of seconds. Whilst it is waiting other threads are allowed to run and if a session is returned to the pool it will be used by the waiting method. At the end of the time period NULL is returned if no session has become available. Note that this waiting time period should be treated as approximate.Session pools are created using the $makepool() method. The call to $makepool() will only be successful if used with an external object that is a session object or an object class that has a session object as its superclass. The $makepool() method returns a reference to the pool if it is successfully created and the required number of session instances are constructed, otherwise it returns NULL. Once a session pool has been created there is no need to maintain it further during the time that the library is open, however it is possible to change the number of available instances using notation.
NOTE: Pooled sessions do not appear in the SQL Object Browser!
USING $makepool() WITH AN EXTERNAL OBJECT
Create a session pool using an external object with a method call of the form
Do $extobjects.DAMobject.$objects.SessObject.$makepool(pName, pSize,pHostName,pUserName,pPassword) Returns #F
DAMobject is the name of the external component. You can find out what DAM objects are available on your workstation by examining the $root.$extobjects branch of the notation tree using the Notation Inspector. SessObject is the name of the session object. You can find out what session object is available by expanding the $objects group for a particular DAM object using the Notation Inspector. The pName parameter is the name of the pool and must be unique amongst session pools and the pSize parameter is the number of object instances to be initially contained in the pool. The other three parameters are optional and if specified are passed to the $logon() method for the instance, if they are not specified the instance is constructed but not logged on.
USING $makepool() WITH AN OBJECT CLASS
Alternatively $makepool() may be used with an object class with a method call of the form
Do $objects.ObjectClass.$makepool(pName,pSize,pUserName,pPassword) Returns #F
ObjectClass is the name of an object class that must have a session object as its superclass. You can achieve this by selecting the object class in the browser and clicking on the $superclass in the Property Manager, click the arrow and select External Objects and double-click on the required session object.The $new() method is used to assign a session instance from a pool. For example
Calculate SessObj as $sessionpools.poolone.$new()
If $new() is successful the session instance assigned from the pool belongs to SessObj and is normally returned to the pool when SessObj is destroyed (for example, if SessObj is a local variable the session is returned to the pool when the method containing SessObj terminates). Alternatively the session can be manually returned to the pool by assigning some other object or zero to SessObj. The $new method returns NULL if all instances contained in the pool have already been assigned out.
Now you can use the $newstatement() method with the session object to create a statement to execute SQL in the normal way.