@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.datastore.v1.Key)) { return super.equals(obj); } com.google.datastore.v1.Key other = (com.google.datastore.v1.Key) obj; boolean result = true; result = result && (hasPartitionId() == other.hasPartitionId()); if (hasPartitionId()) { result = result && getPartitionId().equals(other.getPartitionId()); } result = result && getPathList().equals(other.getPathList()); 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 (hasPartitionId()) { hash = (37 * hash) + PARTITION_ID_FIELD_NUMBER; hash = (53 * hash) + getPartitionId().hashCode(); } if (getPathCount() > 0) { hash = (37 * hash) + PATH_FIELD_NUMBER; hash = (53 * hash) + getPathList().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
static IncompleteKey fromPb(com.google.datastore.v1.Key keyPb) { String projectId = ""; String namespace = ""; if (keyPb.hasPartitionId()) { com.google.datastore.v1.PartitionId partitionIdPb = keyPb.getPartitionId(); projectId = partitionIdPb.getProjectId(); namespace = partitionIdPb.getNamespaceId(); } List<com.google.datastore.v1.Key.PathElement> pathElementsPb = keyPb.getPathList(); Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty"); ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.builder(); for (com.google.datastore.v1.Key.PathElement pathElementPb : pathElementsPb) { pathBuilder.add(PathElement.fromPb(pathElementPb)); } ImmutableList<PathElement> path = pathBuilder.build(); PathElement leaf = path.get(path.size() - 1); if (leaf.getNameOrId() != null) { return new Key(projectId, namespace, path); } return new IncompleteKey(projectId, namespace, path); }
/** * Return element path that represents this key. * * @return a list of path elements that make up this key. */ public List<Element> getPath() { return ImmutableList.copyOf(key.getPathList().stream() .map(Element::new) .collect(Collectors.toList())); }
/** * Return element kind of key, or null if not set. * * This is a shortcut for {@code Key.getPath().get(Key.getPath().size() - 1).getKind()} * * @return the element kind. */ public String getKind() { final com.google.datastore.v1.Key.PathElement element = Iterables.getLast(key.getPathList(), null); if (element == null) { return null; } return element.getKind(); }
/** * Returns true if a Cloud Datastore key is complete. A key is complete if its last element has * either an id or a name. */ static boolean isValidKey(Key key) { List<PathElement> elementList = key.getPathList(); if (elementList.isEmpty()) { return false; } PathElement lastElement = elementList.get(elementList.size() - 1); return (lastElement.getId() != 0 || !lastElement.getName().isEmpty()); }
@Override public int compare(Key thisKey, Key otherKey) { if (!thisKey.getPartitionId().equals(otherKey.getPartitionId())) { throw new IllegalArgumentException("Cannot compare keys with different partition ids."); } Iterator<PathElement> thisPath = thisKey.getPathList().iterator(); Iterator<PathElement> otherPath = otherKey.getPathList().iterator(); while (thisPath.hasNext()) { if (!otherPath.hasNext()) { return 1; } int result = comparePathElement(thisPath.next(), otherPath.next()); if (result != 0) { return result; } } return otherPath.hasNext() ? -1 : 0; } }
@Override public int compare(Key thisKey, Key otherKey) { if (!thisKey.getPartitionId().equals(otherKey.getPartitionId())) { throw new IllegalArgumentException("Cannot compare keys with different partition ids."); } Iterator<PathElement> thisPath = thisKey.getPathList().iterator(); Iterator<PathElement> otherPath = otherKey.getPathList().iterator(); while (thisPath.hasNext()) { if (!otherPath.hasNext()) { return 1; } int result = comparePathElement(thisPath.next(), otherPath.next()); if (result != 0) { return result; } } return otherPath.hasNext() ? -1 : 0; } }
/** * Return element key id, or null if not set. * * This is a shortcut for {@code Key.getPath().get(Key.getPath().size() - 1).getId()} * * @return the key id. */ public Long getId() { final com.google.datastore.v1.Key.PathElement element = Iterables.getLast(key.getPathList(), null); if (element == null) { return null; } return isId(element) ? element.getId() : null; }
/** * Return element key name, or null if not set. * * This is a shortcut for {@code Key.getPath().get(Key.getPath().size() - 1).getName()} * * @return the key name. */ public String getName() { final com.google.datastore.v1.Key.PathElement element = Iterables.getLast(key.getPathList(), null); if (element == null) { return null; } return isName(element) ? element.getName() : null; }
/** * Return whether this key is complete or not. * * A complete key is a key that includes a "kind" and ("id" or "name"). * * @return true if the key is complete. */ public boolean isComplete() { if (key.getPathCount() == 0) { return false; } return key.getPathList().stream().allMatch(e -> isId(e) || isName(e)); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.datastore.v1.Key)) { return super.equals(obj); } com.google.datastore.v1.Key other = (com.google.datastore.v1.Key) obj; boolean result = true; result = result && (hasPartitionId() == other.hasPartitionId()); if (hasPartitionId()) { result = result && getPartitionId().equals(other.getPartitionId()); } result = result && getPathList().equals(other.getPathList()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.datastore.v1.Key)) { return super.equals(obj); } com.google.datastore.v1.Key other = (com.google.datastore.v1.Key) obj; boolean result = true; result = result && (hasPartitionId() == other.hasPartitionId()); if (hasPartitionId()) { result = result && getPartitionId() .equals(other.getPartitionId()); } result = result && getPathList() .equals(other.getPathList()); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasPartitionId()) { hash = (37 * hash) + PARTITION_ID_FIELD_NUMBER; hash = (53 * hash) + getPartitionId().hashCode(); } if (getPathCount() > 0) { hash = (37 * hash) + PATH_FIELD_NUMBER; hash = (53 * hash) + getPathList().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); if (hasPartitionId()) { hash = (37 * hash) + PARTITION_ID_FIELD_NUMBER; hash = (53 * hash) + getPartitionId().hashCode(); } if (getPathCount() > 0) { hash = (37 * hash) + PATH_FIELD_NUMBER; hash = (53 * hash) + getPathList().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
static IncompleteKey fromPb(com.google.datastore.v1.Key keyPb) { String projectId = ""; String namespace = ""; if (keyPb.hasPartitionId()) { com.google.datastore.v1.PartitionId partitionIdPb = keyPb.getPartitionId(); projectId = partitionIdPb.getProjectId(); namespace = partitionIdPb.getNamespaceId(); } List<com.google.datastore.v1.Key.PathElement> pathElementsPb = keyPb.getPathList(); Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty"); ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.builder(); for (com.google.datastore.v1.Key.PathElement pathElementPb : pathElementsPb) { pathBuilder.add(PathElement.fromPb(pathElementPb)); } ImmutableList<PathElement> path = pathBuilder.build(); PathElement leaf = path.get(path.size() - 1); if (leaf.getNameOrId() != null) { return new Key(projectId, namespace, path); } return new IncompleteKey(projectId, namespace, path); }
static boolean isValidKey(Key key) { List<PathElement> elementList = key.getPathList(); if (elementList.isEmpty()) { return false; } PathElement lastElement = elementList.get(elementList.size() - 1); return (lastElement.getId() != 0 || !lastElement.getName().isEmpty()); }
+ partitionId + " and " + subKey.getPartitionId()); key.addAllPath(((Key) element).getPathList());
+ partitionId + " and " + subKey.getPartitionId()); key.addAllPath(((Key) element).getPathList());
@ProcessElement public void processElement(ProcessContext c) throws InvalidProtocolBufferException { String entityJson = c.element(); Entity.Builder entityBuilder = Entity.newBuilder(); entityJsonParser.merge(entityJson, entityBuilder); // Build entity who's key has an empty project Id. // This allows DatastoreIO to handle what project Entities are loaded into Key k = entityBuilder.build().getKey(); entityBuilder.setKey(Key.newBuilder() .addAllPath(k.getPathList()) .setPartitionId(PartitionId.newBuilder() .setProjectId("") .setNamespaceId(k.getPartitionId().getNamespaceId()))); c.output(entityBuilder.build()); } }