Tocchetto
Tocchetto

Reputation: 176

GCP Datastore Java API, build an entity with null value

So this is not much of a "I have a bug how to fix it" question as much as "Is this really how this works?" question.

So, I am looking over my code to persist an entity into datastore, and if I try to set an attribute that is null, all hell breaks lose. I noticed that there's a setNull but is that it? I have to manually check every attribute before building it in order to call the appropriate set? Shouldn't the standard set, which is overloaded for a plethora of datatypes handle null on itself?

Here is a code piece

public void put(BatchExecution obj) {
    Key key = keyFactory.newKey(obj.getId());           
    FullEntity<Key> incBEEntity = Entity.newBuilder(key)  
        .set(BatchExecution.ID, obj.getId())
        .set(BatchExecution.NAME, obj.getName())
        .set(BatchExecution.CREATETIME, obj.getCreateTime())
        .set(BatchExecution.ELAPSEDTIME, obj.getElapsedTime()) //I break the code because elapesedTime was never set in the object
        .set(BatchExecution.STATUS, obj.getStatus().name())
        .build();
    datastore.put(incBEEntity);
  }

Am I missing something here or is this really how the API works?

Upvotes: 2

Views: 593

Answers (1)

Tocchetto
Tocchetto

Reputation: 176

Concern raised on github https://github.com/GoogleCloudPlatform/google-cloud-java/issues/3583

Question has been closed.

Upvotes: 1

Related Questions