public Key newKey(String name) { ImmutableList<PathElement> path = ImmutableList.<PathElement>builder() .addAll(ancestors) .add(PathElement.of(kind, name)) .build(); return new Key(projectId, namespace, path); }
public Key newKey(long id) { ImmutableList<PathElement> path = ImmutableList.<PathElement>builder() .addAll(ancestors) .add(PathElement.of(kind, id)) .build(); return new Key(projectId, namespace, path); }
@Override public Key build() { ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.<PathElement>builder().addAll(ancestors); if (id == null) { pathBuilder.add(PathElement.of(kind, name)); } else { pathBuilder.add(PathElement.of(kind, id)); } return new Key(projectId, namespace, pathBuilder.build()); } }
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); }
public Key newKey(String name) { ImmutableList<PathElement> path = ImmutableList.<PathElement>builder() .addAll(ancestors) .add(PathElement.of(kind, name)) .build(); return new Key(projectId, namespace, path); }
public Key newKey(long id) { ImmutableList<PathElement> path = ImmutableList.<PathElement>builder() .addAll(ancestors) .add(PathElement.of(kind, id)) .build(); return new Key(projectId, namespace, path); }
@Override public Key build() { ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.<PathElement>builder().addAll(ancestors); if (id == null) { pathBuilder.add(PathElement.of(kind, name)); } else { pathBuilder.add(PathElement.of(kind, id)); } return new Key(projectId, namespace, pathBuilder.build()); } }
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); }