Reputation: 65
When I read an entity from Google Datastore using the Java library (com.google.cloud.datastore.Datastore
), is the entire entity and all of its properties pulled from the database when the get(key)
method is called, is each individual property of the entity loaded separately at the time of reference, or is the entire entity pulled when I first access an entity property?
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Entity entity = datastore.get(key); //Is the entire entity and its properties loaded here?
entity.getString("name"); //or is the entity/property loaded upon access?
Also, if the entity is being updated at the same time that I get the entity, is the entity that I receive guaranteed to be consistent. (i.e. Is it possible to receive a partially written entity, where some of the properties are the updated values from the write and some are old values that do not reflect the update yet?)
Upvotes: 0
Views: 316
Reputation: 742
Let's inspect the official library documentation Datastore.get(key) method inherited from interface com.google.cloud.datastore.DatastoreReader and return Entity for the given key. An entity is a persistent data object and you have here method getString(String name) inherited from class com.google.cloud.datastore.BaseEntity which returns the property value as a string, like filter what properties you need. According to the foregoing and OOP concepts 'Entity entity = datastore.get(key);' returns you whole entity with all properties and saves it in 'entity' variable.
Regarding the data consistency Datastore queries can deliver their results at either of two consistency levels strong and eventually and you need to balance between consistency and speed what depending your app needs. I kindly recommend reading 1,2 documentation to get more clarification on how it works in Datastore.
Upvotes: 1