List WebSession ID's

For questions and postings not covered by the other forums
Rich Cassell
Posts: 77
Joined: Mon Aug 24, 2009 11:22 pm
Location: Nottinghamshire, UK

List WebSession ID's

Postby Rich Cassell » Wed Jul 07, 2010 11:38 pm

Hi,

As part of our ongoing advancements to our web applications, i am looking at using the websession ID to determine which users are using which parts of the system. We are having a few issues where two users are accessing the same data simultaneously and data is being lost. A 'soft-lock' procedure is needed but it isn't simple to do at this particular part of the system (and to hard to describe on here). My thought, was if i could get each users sessionID and use that to 'soft-lock' the data on the screen, then do periodic checks on the currently active sessionID's to see if that user is still there (We can't use the username as if somebody just closes the browser, we don't know!). This will ensure that no data is locked with the user who locked it disconnected.

What is the best way of getting a list of the currently active sessionID's on a web application? Is there also, an easy way to get the currentSessions' sessionID?

If anybody has any suggestions on a better way of soft locking data on a web application then that would be useful too - i'm very open to better suggestions!

Cheers,

Rich

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: List WebSession ID's

Postby ghosttie » Thu Jul 08, 2010 1:45 am

First of all, sessionId is a protected property of WebSession, so make an accessor method for it on your subclass of WebSession:

Code: Select all

getSessionId() : Integer; vars begin return sessionId; end;
You can then get the current session's sessionId by calling:

Code: Select all

currentSession.getSessionId
To get a list of all sessionIds for active sessions you would do something like this:

Code: Select all

vars oa : ObjectArray; obj : Object; sess : MySchemaSession; begin create oa transient; MySchemaSession.allInstances(oa, 0, true); foreach obj in oa do sess := obj.MySchemaSession; //do something with sess.getSessionId; endforeach; epilog delete oa; end;
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

bdoolan
Posts: 19
Joined: Fri Aug 14, 2009 7:26 pm

Re: List WebSession ID's

Postby bdoolan » Fri Jul 09, 2010 4:01 am

Hi Rich,
One way to softlock is to use the edition of the Jade objects. For example, consider the simple case where the webform doing the update displays the property values for just one Jade object. When the data is sent to the browser, the edition of that object can be sent in a hidden field along with the visible data. Make sure the hidden field is setup so that, when the user transmits the data back, the value of the hidden field is also sent along with the data. If the user updates the object, then before updating, compare the edition of the object now to the value when it was saved in the hidden fields. If the value of the edition has changed, you know the object has been changed by another user in the meantime and take appropriate action. Otherwise you can update with confidence that you won't have a lost update.

Remember when filling in the value of the fields on the form, ideally you should shareLock the object first and unlock at the end. So something like

sharedLock(obj); // lock object
hiddenEditionField := obj.edition; // deliberately AFTER the sharedLock, guaranteeing edition is up to date
webFormProperty1 := obj.property1; // assign webform property values
webFormProperty2 := obj.property2;

epilog
unlock(obj);

Later, on the update of the object, do
beginTransaction;
exclusiveLock(obj); // exclusive lock since it's going to be updated anyway and it will be exclusively locked shortly
if obj.edition <> webForm.savedEdition then
// object has been changed in the meantime
// handle error and return or raise exception to handle situation
// abortTransaction somewhere. This will unlock obj
endif;
// proceed with the update
obj.property1 := webFormProperty1;
obj.property2 := webFormProperty2;
commitTransaction; // this will release the exclusive lock above so no need to do this in the epilog

If the webform is more complex and you are updating multiple objects, all of which you want to guarantee haven't changed in the meantime, you can construct a string of the format <oid>-<edition>,<oid>-<edition> etc with one <oid>-<edition> pair for each object you want to protect. Send that string in the hidden data and then use the same technique as above after exclusive locking each object.

Cheers, Brendan

Rich Cassell
Posts: 77
Joined: Mon Aug 24, 2009 11:22 pm
Location: Nottinghamshire, UK

Re: List WebSession ID's

Postby Rich Cassell » Thu Jul 22, 2010 8:39 pm

Cheers guys, that's great!

Thanks!

Rich


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 26 guests