Database Reference
In-Depth Information
Now let's say that a program (a general one) reads this item in line 20 (we are not talking
about any program written here. The line number used is only for illustration purposes),
creates another table named Tbl_Library , and waits until the table becomes active.
Meanwhile another client has updated the Language attribute of the item from ["Eng-
lish"] to ["English","German"] . So this operation will increment the version
attribute.
Now let's say that in line 40 (we are not talking about any program written here; the line
number used here is only for illustration purposes), we are trying to delete the read item.
What will happen? It will not delete the item. The reason is simple: now the server will
have the version attribute (of this item) as 2 (because of the update operation, which
incremented the version value), and the client will have the version attribute value as 1
(because it doesn't know that an update operation has been performed on the item). Be-
cause of the mismatch with the server-side and the client-side version attribute values, this
operation will fail. This is called optimistic locking. Optimistic locking will happen auto-
matically (provided the class has an attribute with the @DynamoDBVersionAttrib-
ute annotation) and it is enabled by default.
Tip
If an instance variable of the mapped class ( BookTitle ) has @DynamoDBVer-
sionAttribute , this attribute will also be inserted into the table along with the other
attributes of the item. Therefore, the size of the item will become bigger. So, the version
attribute name must be as small as possible.
Try to run the following code to check whether it is gives any error:
try {
BookEntity book = dynamoDBMapper.load(
BookEntity.class, "Hadoop","2012-12-28");
if(book!=null)
System.out.println(book.getBookTitle()
+ "\t" + book.getEdition() + "\t" + book.getLanguage());
book.setLanguage(new
HashSet<String>(Arrays.asList("English", "German")));
dynamoDBMapper.save(book);
BookEntity book1 = dynamoDBMapper.load(
BookEntity.class, "Hadoop","2012-12-28");
Search WWH ::




Custom Search