Session Object Details
Some people consider having the session object as a global variable
(which a task variable basically is) as something that goes against
programming best practices, then jump through major hoops to create a
global resource the “OO way”.
Personally IMHO, for 99% of client-server applications there is no
benefit to jumping through these hoops and a task variable for your
session object that you then use for all your table classes will do just
fine so why make your life hard?
Omnis is a single threaded application and won’t be able to use any
perceived parallelism that having multiple session objects give you.
Each client will have multiple connections open taking up vital
resources on your server while only one of those connections is ever
doing something while the other ones are just sitting idle.
Pragmatism trumps theory here in my humble opinion.
Those cases where real parallelism is important because you want to
offload a large process to something running in the background worker
objects are your friends but that is a different style of programming
Obviously if you’re writing a server solution using remote tasks there
is a lot of benefit in not going down the task variable path as there is
some cooperative multi tasking magic going on.
What path that is solely depends on the type of load your are expecting.
Session pools are the right choice 99% of the time, basically you have a
pool of connections to your database ready for you to pick, use, and
give back to the pool. There are some scenarios where you can put
yourself in a jam especially in fault situations, the last thing you
want is to give a connection back to the pool that is in a failed
transaction state. Gives some really funky hard to find bugs to fix as
the action that runs into trouble is the innocent one that is unlucky
enough to pick the dirty session out of the pool.
There are still use cases where a task variable in the remote task which
gets connected when the remote tasks is instantiated is the right way
forward but I’d say those are edge cases.
Another scenario where using a global task variable is not a good idea
is if you’re likely to connect to multiple databases. While there is a
design pattern where you would use Omnis’ multiple task instancing as
the solution here the more likely approach here is to go for a different
approach to handle the different session objects. This however is also
very edge case.
But all in all, unless you have a specific need to go down a different
route, if you’re building a run of the mill client-server application,
there really is nothing wrong with using a task variable IMHO. The
database session for all intent and purposes is a global resource to
Case in point, we use a task variable for our session object and I even
go as far as assigning it to my table class within the $construct of my
base class. So whenever I instantiate a row or list bound to a table
class, my session is all setup and ready to go.
There are a few scenarios where I need to use a different session object
but in those I simply assign that session object after the list or row
is defined. That in those cases my list or row is briefly assigned to
the wrong session object, whooptydo, don’t really care.
On 7/3/18 12:01 pm, Das Goravani wrote:
> Does the session object you “bless” your rows and lists with have to be the same one you do other session object things with?
> Said another way, can you bless your rows with one, and be using another one in your code that works with those lists?
> Another way: What’s wrong with using a Task Variable session object throughout?
> How this happened: I got wind that a universal task variable session object was somehow second class. I don’t remember there being any specifics, but I got that it was frowned on. So I labored to be hip and I made a session pool and in my main object that holds my windows code I labored and made an Instance Variable session object and statement object. Now those two are used in my code, while the universal one isn’t used much except during logon where I create it. Now I’m thinking of ‘blessing’ all my lists and rows in one method during startup, and using the universal one to bless them, but they might be used with other session objects such as in my object where most of the code is. I could easily use search and replace and use only the universal one. The only things I see the session object being used for is things like Commit and Rollback… in constant use…it seems you rarely invoke it’s name. Does it matter if commit and rollback are done with a different session object than the one you blessed your rows with?
> If you’re wondering about the universal up front blessing of rows verse how do I get those into instance variables, the answer is through Calculate iRow as tRow. Simple calculate as”” statement. It’s easier than typing the two lines of code all the time the first being define from sql class to define the row the second being assigning the session object to the row. I will have that code only once with my new idea, and otherwise just copy the universal ones made up front into the local ones used on the ground.
> If I can bless with one and use any other I’ll be a happy camper. I don’t really “get” session objects yet, therein lay the problem.
> Manage your list subscriptions at lists.omnis-dev.com
> Start a new message -> mailto:firstname.lastname@example.org