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

Datastore cleanup #862

Merged
merged 1 commit into from
Apr 7, 2016
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 @@ -108,7 +108,6 @@ public List<? extends Value<?>> get() {

@Override
public ListValue build() {
Preconditions.checkState(!get().isEmpty(), "value list could not be empty");
return new ListValue(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public abstract class Value<V> extends Serializable<com.google.datastore.v1beta3

private static final long serialVersionUID = -1899638277588872742L;


private final transient ValueType valueType;
private final transient boolean excludeFromIndexes;
private final transient int meaning;
Expand Down Expand Up @@ -76,7 +75,6 @@ public final com.google.datastore.v1beta3.Value toProto(P value) {
protected abstract void setValue(P from, com.google.datastore.v1beta3.Value.Builder to);
}

@SuppressWarnings("deprecation")
abstract static class BaseBuilder<V, P extends Value<V>, B extends BaseBuilder<V, P, B>>
implements ValueBuilder<V, P, B> {

Expand Down Expand Up @@ -113,11 +111,13 @@ public B excludeFromIndexes(boolean excludeFromIndexes) {
return self();
}

@Deprecated
@Override
public int getMeaning() {
return meaning;
}

@Deprecated
@Override
public B meaning(int meaning) {
this.meaning = meaning;
Expand All @@ -144,6 +144,7 @@ private B self() {
public abstract P build();
}

@SuppressWarnings("deprecation")
<P extends Value<V>, B extends BaseBuilder<V, P, B>> Value(ValueBuilder<V, P, B> builder) {
valueType = builder.getValueType();
excludeFromIndexes = builder.getExcludeFromIndexes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface ValueBuilder<V, P extends Value<V>, B extends ValueBuilder<V, P

B excludeFromIndexes(boolean excludeFromIndexes);

@Deprecated
int getMeaning();

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class DatastoreTest {
.addValue(STR_VALUE, BOOL_VALUE)
.build();
private static final ListValue LIST_VALUE2 = ListValue.of(Collections.singletonList(KEY_VALUE));
private static final ListValue EMPTY_LIST_VALUE = ListValue.of(Collections.<Value<?>>emptyList());
private static final DateTimeValue DATE_TIME_VALUE = new DateTimeValue(DateTime.now());
private static final LatLngValue LAT_LNG_VALUE =
new LatLngValue(new LatLng(37.422035, -122.084124));
Expand All @@ -110,6 +111,7 @@ public class DatastoreTest {
.set("bool", BOOL_VALUE)
.set("partial1", EntityValue.of(PARTIAL_ENTITY1))
.set("list", LIST_VALUE2)
.set("emptyList", EMPTY_LIST_VALUE)
.build();
private static final Entity ENTITY2 = Entity.builder(ENTITY1).key(KEY2).remove("str")
.set("name", "Dan").setNull("null").set("age", 20).build();
Expand Down Expand Up @@ -738,7 +740,9 @@ public void testGet() {
assertEquals(LAT_LNG_VALUE, value5);
FullEntity<IncompleteKey> value6 = entity.getEntity("partial1");
assertEquals(PARTIAL_ENTITY1, value6);
assertEquals(6, entity.names().size());
ListValue value7 = entity.getValue("emptyList");
assertEquals(EMPTY_LIST_VALUE, value7);
assertEquals(7, entity.names().size());
assertFalse(entity.contains("bla"));
}

Expand Down Expand Up @@ -783,7 +787,8 @@ public void testGetArrayNoDeferredResults() {
assertEquals(ENTITY2, partial2);
assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").type());
assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng"));
assertEquals(7, entity3.names().size());
assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList"));
assertEquals(8, entity3.names().size());
assertFalse(entity3.contains("bla"));
try {
entity3.getString("str");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.junit.Test;

import java.util.Collections;
import java.util.List;

public class ListValueTest {
Expand All @@ -37,12 +38,14 @@ public void testToBuilder() throws Exception {
assertEquals(value, value.toBuilder().build());
}

@SuppressWarnings("deprecation")
@Test
public void testOf() throws Exception {
ListValue value = ListValue.of(CONTENT);
assertEquals(CONTENT, value.get());
assertFalse(value.excludeFromIndexes());
value = ListValue.of(Collections.<Value<?>>emptyList());
assertEquals(Collections.<Value<?>>emptyList(), value.get());
assertFalse(value.excludeFromIndexes());
}

@SuppressWarnings("deprecation")
Expand All @@ -59,5 +62,8 @@ public void testBuilder() throws Exception {
builder.addValue(v);
}
assertEquals(CONTENT, builder.build().get());

builder = builder.set(Collections.<Value<?>>emptyList());
assertEquals(Collections.<Value<?>>emptyList(), builder.build().get());
}
}