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

Make protobuf methods package protected #498

Merged
merged 2 commits into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected DatastoreException newInvalidRequest(String msg, Object... params) {
return DatastoreException.throwInvalidRequest(String.format(msg, params));
}

protected DatastoreV1.Mutation.Builder toMutationPb() {
DatastoreV1.Mutation.Builder toMutationPb() {
DatastoreV1.Mutation.Builder mutationPb = DatastoreV1.Mutation.newBuilder();
for (FullEntity<IncompleteKey> entity : toAddAutoId()) {
mutationPb.addInsertAutoId(entity.toPb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private B self() {
}

@SuppressWarnings("unchecked")
protected B fill(DatastoreV1.Entity entityPb) {
B fill(DatastoreV1.Entity entityPb) {
Map<String, Value<?>> copiedProperties = Maps.newHashMap();
for (DatastoreV1.Property property : entityPb.getPropertyList()) {
copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
Expand Down Expand Up @@ -375,7 +375,7 @@ ImmutableSortedMap<String, Value<?>> properties() {
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Builder<?, ?> builder = emptyBuilder();
builder.fill(DatastoreV1.Entity.parseFrom(bytesPb));
return builder.build();
Expand All @@ -384,7 +384,7 @@ protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
protected abstract Builder<?, ?> emptyBuilder();

@Override
protected final DatastoreV1.Entity toPb() {
final DatastoreV1.Entity toPb() {
DatastoreV1.Entity.Builder entityPb = DatastoreV1.Entity.newBuilder();
for (Map.Entry<String, Value<?>> entry : properties.entrySet()) {
DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public boolean equals(Object obj) {
}

@Override
protected DatastoreV1.Key toPb() {
DatastoreV1.Key toPb() {
DatastoreV1.Key.Builder keyPb = DatastoreV1.Key.newBuilder();
DatastoreV1.PartitionId.Builder partitionIdPb = DatastoreV1.PartitionId.newBuilder();
if (projectId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ public static Blob copyFrom(InputStream input) throws IOException {
}

@Override
protected Value toPb() {
Value toPb() {
return DatastoreV1.Value.newBuilder().setBlobValue(byteString).build();
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return new Blob(DatastoreV1.Value.parseFrom(bytesPb).getBlobValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public static Cursor copyFrom(byte[] bytes) {
}

@Override
protected Value toPb() {
Value toPb() {
return DatastoreV1.Value.newBuilder().setBlobValue(byteString).build();
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(DatastoreV1.Value.parseFrom(bytesPb));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public static DateTime copyFrom(Calendar calendar) {
}

@Override
protected Value toPb() {
Value toPb() {
return DatastoreV1.Value.newBuilder().setIntegerValue(timestampMicroseconds).build();
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return new DateTime(DatastoreV1.Value.parseFrom(bytesPb).getIntegerValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public boolean equals(Object obj) {
}

@Override
protected DatastoreV1.GqlQueryArg toPb() {
DatastoreV1.GqlQueryArg toPb() {
DatastoreV1.GqlQueryArg.Builder argPb = DatastoreV1.GqlQueryArg.newBuilder();
if (name != null) {
argPb.setName(name);
Expand All @@ -141,7 +141,7 @@ protected DatastoreV1.GqlQueryArg toPb() {
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(DatastoreV1.GqlQueryArg.parseFrom(bytesPb));
}

Expand Down Expand Up @@ -370,7 +370,7 @@ public boolean equals(Object obj) {
}

@Override
protected DatastoreV1.GqlQuery toPb() {
DatastoreV1.GqlQuery toPb() {
DatastoreV1.GqlQuery.Builder queryPb = DatastoreV1.GqlQuery.newBuilder();
queryPb.setQueryString(queryString);
queryPb.setAllowLiteral(allowLiteral);
Expand All @@ -384,18 +384,18 @@ protected DatastoreV1.GqlQuery toPb() {
}

@Override
protected void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb) {
void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb) {
requestPb.setGqlQuery(toPb());
}

@Override
protected GqlQuery<V> nextQuery(DatastoreV1.QueryResultBatch responsePb) {
GqlQuery<V> nextQuery(DatastoreV1.QueryResultBatch responsePb) {
// See issue #17
throw new UnsupportedOperationException("paging for this query is not implemented yet");
}

@Override
protected Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
throws InvalidProtocolBufferException {
return fromPb(resultType, namespace, DatastoreV1.GqlQuery.parseFrom(bytesPb));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public IncompleteKey build() {
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(DatastoreV1.Key.parseFrom(bytesPb));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static Key fromUrlSafe(String urlSafe) {
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(DatastoreV1.Key.parseFrom(bytesPb));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean equals(Object obj) {
}

@Override
protected DatastoreV1.Key.PathElement toPb() {
DatastoreV1.Key.PathElement toPb() {
DatastoreV1.Key.PathElement.Builder pathElementPb = DatastoreV1.Key.PathElement.newBuilder();
pathElementPb.setKind(kind);
if (id != null) {
Expand All @@ -98,7 +98,7 @@ protected DatastoreV1.Key.PathElement toPb() {
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(DatastoreV1.Key.PathElement.parseFrom(bytesPb));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public abstract static class ResultType<V> implements java.io.Serializable {

private static final long serialVersionUID = 1602329532153860907L;

@Override protected Object convert(DatastoreV1.Entity entityPb) {
@Override
Object convert(DatastoreV1.Entity entityPb) {
if (entityPb.getPropertyCount() == 0) {
if (!entityPb.hasKey()) {
return null;
Expand All @@ -81,7 +82,8 @@ public abstract static class ResultType<V> implements java.io.Serializable {

private static final long serialVersionUID = 7712959777507168274L;

@Override protected Entity convert(DatastoreV1.Entity entityPb) {
@Override
Entity convert(DatastoreV1.Entity entityPb) {
return Entity.fromPb(entityPb);
}
};
Expand All @@ -91,7 +93,8 @@ public abstract static class ResultType<V> implements java.io.Serializable {

private static final long serialVersionUID = -8514289244104446252L;

@Override protected Key convert(DatastoreV1.Entity entityPb) {
@Override
Key convert(DatastoreV1.Entity entityPb) {
return Key.fromPb(entityPb.getKey());
}
};
Expand All @@ -102,7 +105,8 @@ public abstract static class ResultType<V> implements java.io.Serializable {

private static final long serialVersionUID = -7591409419690650246L;

@Override protected ProjectionEntity convert(DatastoreV1.Entity entityPb) {
@Override
ProjectionEntity convert(DatastoreV1.Entity entityPb) {
return ProjectionEntity.fromPb(entityPb);
}
};
Expand Down Expand Up @@ -151,7 +155,7 @@ boolean isAssignableFrom(ResultType<?> otherResultType) {
return resultClass.isAssignableFrom(otherResultType.resultClass);
}

protected abstract V convert(DatastoreV1.Entity entityPb);
abstract V convert(DatastoreV1.Entity entityPb);

static ResultType<?> fromPb(DatastoreV1.EntityResult.ResultType typePb) {
return MoreObjects.firstNonNull(PB_TO_INSTANCE.get(typePb), UNKNOWN);
Expand Down Expand Up @@ -181,16 +185,16 @@ public String toString() {
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(resultType, namespace, bytesPb);
}

protected abstract Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
abstract Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
throws InvalidProtocolBufferException;

protected abstract void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb);
abstract void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb);

protected abstract Query<V> nextQuery(DatastoreV1.QueryResultBatch responsePb);
abstract Query<V> nextQuery(DatastoreV1.QueryResultBatch responsePb);

/**
* Returns a new {@link GqlQuery} builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou
bytesPb = (byte[]) input.readObject();
}

protected Object readResolve() throws ObjectStreamException {
Object readResolve() throws ObjectStreamException {
try {
return fromPb(bytesPb);
} catch (InvalidProtocolBufferException ex) {
Expand All @@ -58,7 +58,7 @@ protected Object readResolve() throws ObjectStreamException {
}
}

protected abstract M toPb();
abstract M toPb();

protected abstract Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException;
abstract Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public abstract static class Filter implements Serializable {
Filter() {
}

protected abstract DatastoreV1.Filter toPb();
abstract DatastoreV1.Filter toPb();

static Filter fromPb(DatastoreV1.Filter filterPb) {
if (filterPb.hasCompositeFilter()) {
Expand Down Expand Up @@ -186,7 +186,7 @@ public static CompositeFilter and(Filter first, Filter... other) {
}

@Override
protected DatastoreV1.Filter toPb() {
DatastoreV1.Filter toPb() {
DatastoreV1.Filter.Builder filterPb = DatastoreV1.Filter.newBuilder();
DatastoreV1.CompositeFilter.Builder compositeFilterPb = filterPb.getCompositeFilterBuilder();
compositeFilterPb.setOperator(operator.toPb());
Expand Down Expand Up @@ -231,7 +231,7 @@ private PropertyFilter(String property, Operator operator, Value<?> value) {
this.value = checkNotNull(value);
}

public static PropertyFilter fromPb(DatastoreV1.PropertyFilter propertyFilterPb) {
static PropertyFilter fromPb(DatastoreV1.PropertyFilter propertyFilterPb) {
String property = propertyFilterPb.getProperty().getName();
Operator operator = Operator.fromPb(propertyFilterPb.getOperator());
Value<?> value = Value.fromPb(propertyFilterPb.getValue());
Expand Down Expand Up @@ -435,7 +435,7 @@ public static PropertyFilter isNull(String property) {
}

@Override
protected DatastoreV1.Filter toPb() {
DatastoreV1.Filter toPb() {
DatastoreV1.Filter.Builder filterPb = DatastoreV1.Filter.newBuilder();
DatastoreV1.PropertyFilter.Builder propertyFilterPb = filterPb.getPropertyFilterBuilder();
propertyFilterPb.getPropertyBuilder().setName(property);
Expand Down Expand Up @@ -587,7 +587,7 @@ DatastoreV1.PropertyExpression toPb() {
return expressionPb.build();
}

public static Projection fromPb(DatastoreV1.PropertyExpression propertyExpressionPb) {
static Projection fromPb(DatastoreV1.PropertyExpression propertyExpressionPb) {
String property = propertyExpressionPb.getProperty().getName();
Aggregate aggregate = null;
if (propertyExpressionPb.hasAggregationFunction()) {
Expand Down Expand Up @@ -795,7 +795,7 @@ public static final class KeyQueryBuilder extends BaseBuilder<Key, KeyQueryBuild
}

@Override
protected KeyQueryBuilder mergeFrom(DatastoreV1.Query queryPb) {
KeyQueryBuilder mergeFrom(DatastoreV1.Query queryPb) {
super.mergeFrom(queryPb);
projection(Projection.property(KEY_PROPERTY_NAME));
clearGroupBy();
Expand Down Expand Up @@ -948,12 +948,12 @@ public Integer limit() {
}

@Override
protected void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb) {
void populatePb(DatastoreV1.RunQueryRequest.Builder requestPb) {
requestPb.setQuery(toPb());
}

@Override
protected StructuredQuery<V> nextQuery(DatastoreV1.QueryResultBatch responsePb) {
StructuredQuery<V> nextQuery(DatastoreV1.QueryResultBatch responsePb) {
Builder<V> builder = new Builder<>(type());
builder.mergeFrom(toPb());
builder.startCursor(new Cursor(responsePb.getEndCursor()));
Expand All @@ -969,7 +969,7 @@ protected StructuredQuery<V> nextQuery(DatastoreV1.QueryResultBatch responsePb)
}

@Override
protected DatastoreV1.Query toPb() {
DatastoreV1.Query toPb() {
DatastoreV1.Query.Builder queryPb = DatastoreV1.Query.newBuilder();
if (kind != null) {
queryPb.addKindBuilder().setName(kind);
Expand Down Expand Up @@ -1002,7 +1002,7 @@ protected DatastoreV1.Query toPb() {
}

@Override
protected Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
Object fromPb(ResultType<V> resultType, String namespace, byte[] bytesPb)
throws InvalidProtocolBufferException {
return fromPb(resultType, namespace, DatastoreV1.Query.parseFrom(bytesPb));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public boolean equals(Object obj) {

@Override
@SuppressWarnings("unchecked")
protected DatastoreV1.Value toPb() {
DatastoreV1.Value toPb() {
return type().getMarshaller().toProto(this);
}

Expand All @@ -231,7 +231,7 @@ static Value<?> fromPb(DatastoreV1.Value proto) {
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(DatastoreV1.Value.parseFrom(bytesPb));
}
}