Datastore get_or_insert in Java

28 views
Skip to first unread message

Andrew Buck

unread,
Dec 4, 2016, 6:55:04 PM12/4/16
to Google App Engine
The Datastore Python API has a get_or_insert() method that will atomically insert an entity if it doesn't exist or return the existing one if it does. I can't find the equivalent in Java. Does the Java API have a way of accomplishing this same functionality atomically?

Jordan (Cloud Platform Support)

unread,
Dec 5, 2016, 11:50:26 AM12/5/16
to Google App Engine
You can achieve the same 'fetch or create' entity functionality in Java using a simple 'try/catch' block. This is essentially the same way the Python 'get_or_insert()' method works, and you can therefore simply add this in your code manually. You can find our Java documentation explaining this specific use of transactions, as seen in the second provided example.
Reply all
Reply to author
Forward
0 new messages