I was experimenting with transactions and asked myself if it's
possible to create an entity "safely".
I didn't think that the following code would work ... but it does and
now I'm puzzled.
Please note: Tests were done on the development server of Google App
Engine SDK 1.4.2 running inside Eclipse with an empty datastore.
The following code throws a ConcurrentModificationException:
01 DatastoreService ds =
DatastoreServiceFactory.getDatastoreService();
02
03 Transaction txn1 = ds.beginTransaction();
04
05 try {
06 ds.get(txn1, KeyFactory.createKey("MyObject", "1"));
07 } catch (EntityNotFoundException e) {
08 System.out.println("MyObject 1 doesn't exist yet.");
09 }
10
11 Transaction txn2 = ds.beginTransaction();
12 Entity e2 = new Entity("MyObject", "1");
13 e2.setProperty("txn", "2");
14 ds.put(txn2, e2);
15 txn2.commit();
16
17 Entity e1 = new Entity("MyObject", "1");
18 e1.setProperty("txn", "1");
19 ds.put(txn1, e1);
20 txn1.commit();
How does a read operation on the not yet existent entity make the
first transaction aware of the put operation of the second
transaction?
Does the datastore register get operations for specific entities even
if they don't exist?
If the get operation (line 6) is missing, no exception is thrown and
both transactions commit successfully.
Result with get:
java.util.ConcurrentModificationException: too much contention on
these datastore entities. please try again.
Datastore: Entity Kind: MyObject, ID/Name: 1, txn: 2
Result without get:
DataStore: Entity Kind: MyObject, ID/Name: 1, txn: 1
P.S.: I don't want to make this any more confusing but there is also
no exception thrown if the put operation on line 14 isn't made within
a transaction. I don't understand that either.
Bernhard
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.