How to save an entity in GAE datastore only if it does not exist while preventing race conditions

后端 未结 2 1158
渐次进展
渐次进展 2021-01-27 05:29

I am trying to save an entity to Google App Engine Datastore only if it does not exist, if it does the thread should not continue.

Main issue is: I want to prevent any r

2条回答
  •  时光取名叫无心
    2021-01-27 06:01

    When calling Datastore from App Engine, the api is different. Use a transaction. First try to get() the entity to see if it's there. If not, put() the entity.

    Here's some sample code that demonstrates transactions using the App Engine API: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/appengine/datastore/src/test/java/com/example/appengine/TransactionsTest.java

提交回复
热议问题