[Glass] how to update models properly

James Foster via Glass glass at lists.gemtalksystems.com
Wed Oct 29 09:38:27 PDT 2014

Hi Sebastian,

I’ll describe the general approach I’ve seen and taken. If you are going to have an external reference to any of your objects then you need to give the external system a unique identifier for the object(s). In our bug tracking system we give each one a bug number. When we pass some information to an external system (the user’s client browser), we embed the ID as a hidden field in the HTML form. When the form is submitted we do a lookup based on the unique ID and update the object as requested. The same should apply to JSON or CSV. I would have a class-side method (for example) that could do the lookup of the object (or create a new one if not found) based on the passed-in data and then have an instance-side method that updates the object based on the passed-in data.

One complicating factor relates to a possible race condition between two clients updating the same object. To address this problem you would store a timestamp with each object and pass the timestamp with the object ID to the client. When the client returns the edit/update you check the timestamp to ensure that there has not been another edit.

To avoid unnecessary edits, I typically check for changes in the setter method. That is, if a string is provided that is equivalent to the existing value, then I don’t do the update (since that would unnecessarily change the underlying object). 

So, yes, you are right. You should parse enough of the JSON to find the object (or create it if not present), and then update the original object from the JSON.


> On Oct 29, 2014, at 9:23 AM, Sebastian Heidbrink via Glass <glass at lists.gemtalksystems.com> wrote:
> Hi all,
> I spent quite some time to get used to Gemstone now . Somehow I stumble across some questions and insecurities again and again.
> I wonder if somebody can give me some hints on this.
> I use Gemstone/Web without Seaside but with a ZincREST interface. Some of my data model objects a transfered via JSON or CSV betwenn db and client. Everytime the client wants to modify data on the server he sends a JSON representation of the object to the server and the server parses the json and creates a data model object from it.
> Now I do have a persited version of my model object and the just newly created model object within the DB.
> How would I update now? I can't replace the persisted object by the new one, because I might loose references to/from it... I will need to walk through all attributes compare them and replace just different ones?!
> I feel like the whole approache is wrong and slow, isn't it? Wouldn't it be better to just parse the request's json into a JSONObject and do the synching after I located the persisted Object based on some hash values or id provided?
> How do your strategies look like? I currently feel like producing too many temporary and unneeded objects.
> Creade, Delete and Replace do not really provide such "imagination" issues like the Update... do they?
> Any push into the right direction is highly appreciated!
> Thanks and have fun at FAST if you'll be there!
> Sebastian
> _______________________________________________
> Glass mailing list
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass

More information about the Glass mailing list