google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

[Enhancement] Support partial updates #403

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It’s nice that in SQL we can do things like
UPDATE PERSONS SET X = X + 1

This is called a partial object update: 
- We updated the value of X without sending a full row update to the server, 
giving us better performance.
- We also didn't update fields that were unchanged, and possibly already 
changed by someone else. This gives us better concurrency.

In NoSQL systems, and also MongoDB, this is possible using modifier operations: 
http://www.mongodb.org/display/DOCS/Updating#Updating-ModifierOperations.

Morhpia of course has corresponding methods for these operations, and explains 
their API here: http://code.google.com/p/morphia/wiki/Updating

So we can already do stuff like:
ops = datastore.createUpdateOperations(Hotel.class).set("address.city", 
"Ottawa");

But, wouldn't it be nice if we could just save objects and let Morphia 
determine what is updated, and what is not without programming it out ourselves?

So instead of dao.save(...) updating all fields of the passed object, it should 
do a partial update on the changed fields.

Now this would require keeping track of what is changed in our objects, either 
by creating a copy, or using some bytecode weaver to keep track of calls to 
getters and setters (this is how other ORMs do it usually).

What is your (Scott) take on this? Nice to have, easy to implement, or not that 
interesting?

Original issue reported on code.google.com by wouter...@gmail.com on 6 Apr 2012 at 8:40

GoogleCodeExporter commented 9 years ago
BTW, I know about the merge() method. Keeping track of calls to setters will 
also solve the erased/unchanged issue addressed by this thread: 
http://groups.google.com/group/morphia/browse_thread/thread/1636dca2aaaa51b8

Original comment by wouter...@gmail.com on 6 Apr 2012 at 10:07