google-code-export / slim3

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

Entity updates should increment version for optimistic locking #67

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

Should't this method increment the version so if two users edit the same
object the last one updating will know the record changed and the first
user won't loose their updates?

http://code.google.com/p/slim3/source/browse/trunk/slim3demo/src/slim3/demo/serv
ice/BlogService.java

public Blog update(Key key, Long version, Map<String, Object> input) {
        Transaction tx = Datastore.beginTransaction();
        Blog blog = Datastore.get(tx, b, key, version);
        BeanUtil.copy(input, blog);

// >>>>
     blog.setVersion(blog.getVersion() + 1);

        Datastore.put(tx, blog);
        tx.commit();
        return blog;
    }

Original issue reported on code.google.com by m...@systemsplanet.com on 22 Jan 2011 at 6:56

GoogleCodeExporter commented 9 years ago
Slim3 increments version automatically.
See line 938 of DatastoreUtil.java:
http://code.google.com/p/slim3/source/browse/trunk/slim3/src/main/java/org/slim3
/datastore/DatastoreUtil.java

Original comment by higaya...@gmail.com on 23 Jan 2011 at 1:36

GoogleCodeExporter commented 9 years ago
why would converting a model to an entity increment the version?
Is the version the optimistic locking version of the data or the
version of the schema data model for migration?
I'm confused. If it's the schema, then we should add a version number of the 
actual
data to prevent two users from overwriting each other.
http://forum.springsource.org/showthread.php?t=17925

Original comment by m...@systemsplanet.com on 23 Jan 2011 at 4:34

GoogleCodeExporter commented 9 years ago
A version property is for optimistic locking, not for schema.
"modelToEntity" method is called before Datastore#put().

Original comment by higaya...@gmail.com on 23 Jan 2011 at 5:12

GoogleCodeExporter commented 9 years ago
so if the write fails, an app retry will increment
the version again?

Original comment by m...@systemsplanet.com on 23 Jan 2011 at 2:44

GoogleCodeExporter commented 9 years ago
If the write fails, an app does not need to increment the version again.
Because slim3 increments the version automatically when putting the entity.

Original comment by higaya...@gmail.com on 23 Jan 2011 at 3:27

GoogleCodeExporter commented 9 years ago

Original comment by higaya...@gmail.com on 28 Feb 2011 at 3:35