Lock some document for other users of app and other question

Hello!

Q1:
My Vaadin app work with some records (documents) in MSSQL database.
I need to open document only for one user for edit in same moment in Vaadin windows.

Sample:
User1 open doc.
User2 and User3 try to open and see Warning(“This document is locked by User1”)

How to realize this in Vaadin app? Any ideas?
AppServer: WebSphere 7.0
I’m realize similar algorithm in Win32 GUI app with creating temporary flag ##table in MSSQL - if connect closed - ##tablle dropped and lock deleted. But in webapp connect always on through app server JNDI.

Q2: My Vaadin app launch Java Web Start (JWS) app (for sample with 2 button: Ok and Cancel).
How to get in Vaadin app execution result of this JWS app? For sample, OK click?
I know about AppletIntegration addon, but using applet technology is not applicable for my app.

Q1: Lots of approaches, depending on how much control you have, and how visible you want the lock to be.

  • Create a normal table, insert a row when a document is “locked” (along with timestamp), remove row when document is “unlocked”. When opening a document check that it isn’t locked before opening. Remember to unlock after saving/closing. Add in unlock in a session timeout. Depending on your transactional integrity, you could ensure that the contents of the document is not returned by doing a subselect

e.g. Open and lock
BEGIN TRANSACTION
SELECT CONTENT FROM DOCUMENT WHERE DOCUMENT.KEY = 234 AND NOT EXISTS (SELECTED KEY FROM LOCKTABLE)
INSERT INTO LOCKTABLE(KEY) VALUES(234)
COMMIT TRANSACTION

Save and unlock
BEGIN TRANSACTION
UPDATE DOCUMENT SET CONTENT = ‘blah’ WHERE DOCUMENT.KEY = 234 AND EXISTS (SELECTED KEY FROM LOCKTABLE)
DELETE FROM LOCKTABLE WHERE KEY = 234
COMMIT TRANSACTION

  • If you don’t want to use a DB table, then you’ll need some shared state in the Vaadin application. If you don’t have to cope with clustering, a singleton java.util.HashSet containing the locked keys suffice. If you do have to cope with clustering, may I point you towards
    Hazelcast
    , an Apache 2 library that’s really rather good at this sort of stuff. (It has locking semativs)

Q2: I’ve not done this - but, I imagine, you’d need to do some kind of HTTP Post - but I’m not sure you could do it directly into the Vaadin servlet.

HTH a little,

Cheers,

Charles.