Search code examples
javahibernatejbossseam

multi-user web app with regular DB manipulation


A general question, to get me started how to solve this thing:

How do I make sure, that once a DB record has been changed the other users see this in their browsers as well? Or at least upon a browser refresh?

The framework: java, jsf facelets, seam, richfaces, EJB, hibernate, maven within jboss.

A bit of description:

I have a web application which will be used by a couple of users (2-10). They manage repair and maintenance records of medical devices, i.e. there are new DB entries or updates of DB content.

I tested with a few browsers parallel, and so far, without investigation, I see changes after some time when I refresh the browser (not reliable), but certainly when I log out and in again. This is not a behaviour I want to offer. And the users wish to log in max once per day.

Thank you very much for your hints!


Solution

  • One important point before the refresh of new data is to have guaranteed your users are working in some sort of transactional context so user A will not mutate a row on your DB while user B is just about to delete this row.

    Once it is ensured your users can CRUD (create, read, update, delete) shared data without negative sideeffects as a result of a missing transactional context i see two basic possibilities to update your data:

    PULL

    On refresh of a page by pressing F5 or a link like 'refresh', 'search' etc. (e.g. any request to your server) your server should always have the most updated data in its context (in case of caches and so on you want to guarantee your server context is aware of updated data). Once such a request reaches your server it should return the currently "newest" state according to its session context and/ or database (maybe there is a user in Step 4 of 5 needet to modify a record but will abort in step 5 of 5 while in this context the data may already be modified on the database inside a transaction in a way other users should see this "temporarely" modified data).

    So to refresh you have your users pulling new data by using your frontend (and fire requests to you).

    Note: Any Request can be used to update any session stored data of the according session. You wouldnt be the first one to have for example all of your Servlets subclassing a MainServlet that guarantees updates to the sessioncontext on any request.

    PUSH

    If your users just stare at the screen without any interaction on the UI you want to "push" updated information to them. As faar as i know using HTTP(S) you will only be able to do so using client side scripts that "simulate" a users input and fire some sort of "deliver me newest data" request.

    Hope i could gave some first hints ;)