/** * * * <pre> * The entity's key. * An entity must have a key, unless otherwise documented (for example, * an entity in `Value.entity_value` may have no key). * An entity's kind is its key path's last element's kind, * or null if it has no key. * </pre> * * <code>.google.datastore.v1.Key key = 1;</code> */ public com.google.datastore.v1.KeyOrBuilder getKeyOrBuilder() { return getKey(); }
@Override Key convert(com.google.datastore.v1.Entity entityPb) { return Key.fromPb(entityPb.getKey()); } };
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (key_ != null) { output.writeMessage(1, getKey()); } com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( output, internalGetProperties(), PropertiesDefaultEntryHolder.defaultEntry, 3); unknownFields.writeTo(output); }
@SuppressWarnings("unchecked") B fill(com.google.datastore.v1.Entity entityPb) { Map<String, Value<?>> copiedProperties = Maps.newHashMap(); for (Map.Entry<String, com.google.datastore.v1.Value> entry : entityPb.getPropertiesMap().entrySet()) { copiedProperties.put(entry.getKey(), Value.fromPb(entry.getValue())); } setProperties(copiedProperties); if (entityPb.hasKey()) { setKey((K) IncompleteKey.fromPb(entityPb.getKey())); } return self(); }
@Override Object convert(com.google.datastore.v1.Entity entityPb) { if (entityPb.getPropertiesMap().isEmpty()) { if (!entityPb.hasKey()) { return null; } return Key.fromPb(entityPb.getKey()); } return ProjectionEntity.fromPb(entityPb); } };
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (key_ != null) { size += com.google.protobuf.CodedOutputStream.computeMessageSize(1, getKey()); } for (java.util.Map.Entry<java.lang.String, com.google.datastore.v1.Value> entry : internalGetProperties().getMap().entrySet()) { com.google.protobuf.MapEntry<java.lang.String, com.google.datastore.v1.Value> properties__ = PropertiesDefaultEntryHolder.defaultEntry .newBuilderForType() .setKey(entry.getKey()) .setValue(entry.getValue()) .build(); size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, properties__); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.datastore.v1.Entity)) { return super.equals(obj); } com.google.datastore.v1.Entity other = (com.google.datastore.v1.Entity) obj; boolean result = true; result = result && (hasKey() == other.hasKey()); if (hasKey()) { result = result && getKey().equals(other.getKey()); } result = result && internalGetProperties().equals(other.internalGetProperties()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasKey()) { hash = (37 * hash) + KEY_FIELD_NUMBER; hash = (53 * hash) + getKey().hashCode(); } if (!internalGetProperties().getMap().isEmpty()) { hash = (37 * hash) + PROPERTIES_FIELD_NUMBER; hash = (53 * hash) + internalGetProperties().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public Builder mergeFrom(com.google.datastore.v1.Entity other) { if (other == com.google.datastore.v1.Entity.getDefaultInstance()) return this; if (other.hasKey()) { mergeKey(other.getKey()); } internalGetMutableProperties().mergeFrom(other.internalGetProperties()); this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@Override Key convert(com.google.datastore.v1.Entity entityPb) { return Key.fromPb(entityPb.getKey()); } };
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (key_ != null) { output.writeMessage(1, getKey()); } com.google.protobuf.GeneratedMessageV3.serializeStringMapTo( output, internalGetProperties(), PropertiesDefaultEntryHolder.defaultEntry, 3); unknownFields.writeTo(output); }
/** * Return the key for this entity. * * @return a {@code Key}. */ public Key getKey() { return Key.builder(entity.getKey()).build(); }
@Override public Mutation apply(Entity entity) { // Verify that the entity to write has a complete key. checkArgument( isValidKey(entity.getKey()), "Entities to be written to the Cloud Datastore must have complete keys:\n%s", entity); return makeUpsert(entity).build(); }
@Override Object convert(com.google.datastore.v1.Entity entityPb) { if (entityPb.getPropertiesMap().isEmpty()) { if (!entityPb.hasKey()) { return null; } return Key.fromPb(entityPb.getKey()); } return ProjectionEntity.fromPb(entityPb); } };
@Override public Mutation.Builder apply(Entity entity) { return makeDelete(entity.getKey()); } }
void write(Entity value) throws Exception { // Verify that the entity to write has a complete key. if (!isValidKey(value.getKey())) { throw new IllegalArgumentException( "Entities to be written to the Datastore must have complete keys"); } entities.add(value); if (entities.size() >= DATASTORE_BATCH_UPDATE_LIMIT) { flushBatch(); } }
@ProcessElement public void processElement(ProcessContext c) throws IOException { Entity e = c.element(); // Serialize Key deterministically ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); CodedOutputStream output = CodedOutputStream.newInstance(byteOutputStream); output.useDeterministicSerialization(); c.element().getKey().writeTo(output); output.flush(); c.output(KV.of(byteOutputStream.toByteArray(), e)); } }))
public Builder mergeFrom(com.google.datastore.v1.Entity other) { if (other == com.google.datastore.v1.Entity.getDefaultInstance()) return this; if (other.hasKey()) { mergeKey(other.getKey()); } internalGetMutableProperties().mergeFrom(other.internalGetProperties()); this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** Test that entities with valid keys are transformed to delete mutations. */ @Test public void testDeleteEntities() throws Exception { Key key = makeKey("bird", "finch").build(); Entity entity = Entity.newBuilder().setKey(key).build(); DeleteEntityFn deleteEntityFn = new DeleteEntityFn(); Mutation exceptedMutation = makeDelete(entity.getKey()).build(); assertEquals(deleteEntityFn.apply(entity), exceptedMutation); }