简体   繁体   中英

Java web application MVC2 “lock” data if someone is editing it

I am creating Java JSP and Servleta ( MVC Model 2) web application for my exam project. Project is a WEB store for selling and buying computers, laptops, and things like that. My data is in XML files. I load and save data using mechanisms for reading and writing XML files. That is not realy important, but, I am telling this because I am not using database.

So, I have a class named " Model " that is going to be singletone. In that class I will instanciate all objects and all model methods and stuff.

My users can edit editable atributes of web shop items and can save it. Problem is when two users edit the same item. The last changes are saved, and user have no idea that someone is changed data while he was not finished. Bigger problem is when one user edit item, other can delete it and my application fail because item that is not in "database" can not be saved - it is deleted.

Users can log in in different browsers on the same computer and that is how i tested it.

Is there any mechanism to prevent that? Any api?

I can implement my project using jQuery and AJAX , so server, which is TOMCAT and my application can comunicate by JSON objects.

Is it bad idea to use a lot of AJAX calls? Are they best practise?

Thanks in advance!

Use the Observer Design Pattern

It contains creating two interfaces one in observer interface that contaings the method update for updating all the clients registered with observer and other interface that contains method to add clents to observer.Here clients are those who are required to be updated when an update occours see this example it will help u

http://www.journaldev.com/1739/observer-design-pattern-in-java-example-tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM