Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaDoc not clear as it could be, e.g. Datastore.add vs. Datastore.put #1339

Closed
unitydynamics opened this issue Oct 27, 2016 · 9 comments
Closed
Assignees
Labels
api: datastore Issues related to the Datastore API.

Comments

@unitydynamics
Copy link

What's the difference between Datastore.add and Datastore.put?

Am I right in assuming that "add" will not clobber existing entities?

Maybe a quick update to the javadoc to clarify--would be much appreciated!!!

@mziccard mziccard added the api: datastore Issues related to the Datastore API. label Oct 27, 2016
@mziccard
Copy link
Contributor

Datastore.put performs a Datastore upsert (Update or Insert) operation. I believe this is documented in our javadoc.

@unitydynamics
Copy link
Author

unitydynamics commented Oct 27, 2016

Lol I'm not British but I would say you're being "dodgy". put is clear. Upsert is clear. What does "add" do? You didn't confirm or deny my assumption in the original question. "Add" isn't really documented.

@mziccard
Copy link
Contributor

I have no idea what you mean with "clobber". I thought add behavior was straightforward, it adds an entity, in other words it performs a Datastore insert.

More details on datastore operations can be found at https://cloud.google.com/datastore/docs/concepts/entities.

@unitydynamics
Copy link
Author

unitydynamics commented Oct 27, 2016

A well "clobber" is an old school computer science term. Very technical. It means overwrite existing data. So... will "add" ever overwrite existing data? If not is there a way to know which ones were already present? (let's assume I'm adding 100 entities and half might already in the datastore). Will it throw an exception? Lots of potential questions. I'm just an API user trying to swim. I actually need this functionality of "add" that would add only those things not already present... leave existing datastore items alone. I'm testing. But I just wish I didn't have to.

@sai-pullabhotla
Copy link

@unitydynamics, add() is equivalent to insert. If you try to insert an entity and the same key already exists, you will get an exception stating that fact. Your existing entity with the same key will be unaffected.

@unitydynamics
Copy link
Author

unitydynamics commented Oct 27, 2016

I get that now... I just wish that the "add" documentation had at least a brief statement saying that existing entities were not overwritten and explained what happens if it does already exist. Moreover I wish the documentation defined the behavior for multiple entities being inserted at the same time, some of which are not in the data store yet and some of which already are. If you don't document the basic behaviors (preferably in JavaDoc) then you'll get clueless people like me asking questions like this. Let's close this issue. Thank you for your time and hard work on this API.

@unitydynamics unitydynamics changed the title Datastore.add vs. Datastore.put JavaDoc not clear as it could be, e.g. Datastore.add vs. Datastore.put Oct 27, 2016
@mziccard
Copy link
Contributor

@unitydynamics Here are some more details:

  1. add(Entity entity)
    • if entity.key() does not exist entity is inserted
    • if entity.key() already exists the method throws a DatastoreException ex such that ex.reason() == "ALREADY_EXISTS" and the entity is not inserted
  2. add(Entity... entities) - this is syntactic on top of a batch operation (i.e. is not transactional)
    • if none of entities' keys exist, all entities are inserted
    • if any of entities' keys already exists the method throws a DatastoreException ex such that ex.reason() == "ALREADY_EXISTS". All entities in entities whose key did not exist are inserted.

You might find strange that add(Entity... entities) throws an exception while still inserting non-existing entities. You might also be wondering which entities have been inserted, and which already existed. Unfortunately, the service does not provide us with that information (it just returns an ALREADY_EXISTS error) so there's nothing more that we can do with the information we have.

BTW, you are totally right when saying that this must be added to our javadoc. Please keep this issue open until I add more docs.

@lesv
Copy link
Contributor

lesv commented Oct 27, 2016

@unitydynamics
Copy link
Author

Wow. Above and beyond! Good clarifications all around, updated Datastore interface, added some good tests. I like that you can get whatever behavior you want using transactions. Thanks Marco!

github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this issue Jun 29, 2022
github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this issue Jun 29, 2022
🤖 I have created a release *beep* *boop*
---


### [1.2.2](googleapis/java-resourcemanager@v1.2.1...v1.2.2) (2022-02-03)


### Dependencies

* **java:** update actions/github-script action to v5 ([googleapis#1339](https://github.com/googleapis/java-resourcemanager/issues/1339)) ([googleapis#705](googleapis/java-resourcemanager#705)) ([1be3785](googleapis/java-resourcemanager@1be3785))
* update dependency com.google.apis:google-api-services-cloudresourcemanager to v1-rev20220109-1.32.1 ([googleapis#702](googleapis/java-resourcemanager#702)) ([ef26145](googleapis/java-resourcemanager@ef26145))
* update dependency com.google.apis:google-api-services-cloudresourcemanager to v3 ([googleapis#692](googleapis/java-resourcemanager#692)) ([9428988](googleapis/java-resourcemanager@9428988))
* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.7.0 ([googleapis#707](googleapis/java-resourcemanager#707)) ([1657de3](googleapis/java-resourcemanager@1657de3))
* update dependency com.google.errorprone:error_prone_annotations to v2.11.0 ([googleapis#704](googleapis/java-resourcemanager#704)) ([774890a](googleapis/java-resourcemanager@774890a))
* update dependency org.easymock:easymock to v4 ([googleapis#693](googleapis/java-resourcemanager#693)) ([a57f241](googleapis/java-resourcemanager@a57f241))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
github-actions bot pushed a commit that referenced this issue Jul 1, 2022
Source-Link: googleapis/synthtool@466412a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:7062473f423f339256346ddbee3d81fb1de6b784fabc2a4d959d7df2c720e375

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
github-actions bot pushed a commit that referenced this issue Jul 1, 2022
🤖 I have created a release *beep* *boop*
---


### [2.1.6](googleapis/java-workflows@v2.1.5...v2.1.6) (2022-02-03)


### Dependencies

* **java:** update actions/github-script action to v5 ([#1339](https://github.com/googleapis/java-workflows/issues/1339)) ([#403](googleapis/java-workflows#403)) ([f2a7001](googleapis/java-workflows@f2a7001))
* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.7.0 ([#406](googleapis/java-workflows#406)) ([75a6ecd](googleapis/java-workflows@75a6ecd))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API.
Projects
None yet
Development

No branches or pull requests

4 participants