use of com.google.storage.onestore.v3.OnestoreEntity.PropertyValue in project appengine-java-standard by GoogleCloudPlatform.
the class QueryTranslatorTest method testFilter.
@SuppressWarnings("deprecation")
@Test
public void testFilter() {
Query query = new Query("foo");
query.addFilter("stringProp", Query.FilterOperator.EQUAL, "stringValue");
query.addFilter("doubleProp", Query.FilterOperator.GREATER_THAN, 42.0);
query.addFilter("nullProp", Query.FilterOperator.EQUAL, null);
query.addFilter("multiValuedProp1", Query.FilterOperator.IN, Lists.newArrayList(31));
query.addFilter("multiValuedProp2", Query.FilterOperator.IN, Lists.newArrayList(31, 32));
DatastoreV3Pb.Query proto = QueryTranslator.convertToPb(query, withDefaults());
assertThat(proto.filterSize()).isEqualTo(5);
Filter filter1 = proto.getFilter(0);
assertThat(filter1.getProperty(0).getName()).isEqualTo("stringProp");
assertThat(filter1.getProperty(0).getValue().getStringValue()).isEqualTo("stringValue");
assertThat(filter1.getOpEnum()).isEqualTo(Operator.EQUAL);
Filter filter2 = proto.getFilter(1);
assertThat(filter2.getProperty(0).getName()).isEqualTo("doubleProp");
assertThat(filter2.getProperty(0).getValue().getDoubleValue()).isWithin(0.00001).of(42.0);
assertThat(filter2.getOpEnum()).isEqualTo(Operator.GREATER_THAN);
Filter filter3 = proto.getFilter(2);
assertThat(filter3.getProperty(0).getName()).isEqualTo("nullProp");
assertThat(filter3.getProperty(0).getValue()).isEqualTo(new PropertyValue());
assertThat(filter3.getOpEnum()).isEqualTo(Operator.EQUAL);
Filter filter4 = proto.getFilter(3);
assertThat(filter4.getProperty(0).getName()).isEqualTo("multiValuedProp1");
assertThat(filter4.getProperty(0).getValue().getInt64Value()).isEqualTo(31L);
assertThat(filter4.getOpEnum()).isEqualTo(Operator.IN);
Filter filter5 = proto.getFilter(4);
assertThat(filter5.getProperty(0).getName()).isEqualTo("multiValuedProp2");
assertThat(filter5.getProperty(0).getValue().getInt64Value()).isEqualTo(31L);
assertThat(filter5.getProperty(1).getValue().getInt64Value()).isEqualTo(32L);
assertThat(filter5.getOpEnum()).isEqualTo(Operator.IN);
}
use of com.google.storage.onestore.v3.OnestoreEntity.PropertyValue in project appengine-java-standard by GoogleCloudPlatform.
the class RawValueTest method testInt64.
@Test
public void testInt64() {
RawValue value = new RawValue(new PropertyValue().setInt64Value(1L));
assertTypeMatch(value, Long.class);
assertThat(value.getValue()).isEqualTo(1L);
assertValue(1L, value, Byte.class, Short.class, Integer.class);
assertValue(new Rating(1), value);
assertValue(new Date(0), value);
}
use of com.google.storage.onestore.v3.OnestoreEntity.PropertyValue in project appengine-java-standard by GoogleCloudPlatform.
the class RawValueTest method testString.
@Test
public void testString() {
RawValue value = new RawValue(new PropertyValue().setStringValue("xmpp hi"));
assertTypeMatch(value, String.class);
assertThat((byte[]) value.getValue()).isEqualTo("xmpp hi".getBytes(UTF_8));
assertValue("xmpp hi", value);
assertValue(new ShortBlob("xmpp hi".getBytes(UTF_8)), value);
assertValue(new Link("xmpp hi"), value);
assertValue(new Category("xmpp hi"), value);
assertValue(new PhoneNumber("xmpp hi"), value);
assertValue(new PostalAddress("xmpp hi"), value);
assertValue(new Link("xmpp hi"), value);
assertValue(new Email("xmpp hi"), value);
assertValue(new IMHandle(Scheme.xmpp, "hi"), value);
assertValue(new BlobKey("xmpp hi"), value);
assertValue(new Blob("xmpp hi".getBytes(UTF_8)), value);
assertValue(new Text("xmpp hi"), value);
}
use of com.google.storage.onestore.v3.OnestoreEntity.PropertyValue in project appengine-java-standard by GoogleCloudPlatform.
the class RawValueTest method testNull.
@Test
public void testNull() {
RawValue value = new RawValue(new PropertyValue());
assertThat(value.getValue()).isNull();
assertThat(value.asType(String.class)).isNull();
assertThat(value.asStrictType(String.class)).isNull();
}
use of com.google.storage.onestore.v3.OnestoreEntity.PropertyValue in project appengine-java-standard by GoogleCloudPlatform.
the class DataTypeTranslator method addPropertyToPb.
/**
* Adds a property to {@code entity}.
*
* @param name the property name
* @param value the property value
* @param indexed whether this property should be indexed. This may be overridden by property
* types like Blob and Text that are never indexed.
* @param forceIndexedEmbeddedEntity whether indexed embedded entities should actually be indexed,
* as opposed to silently moved to unindexed properties (legacy behavior)
* @param multiple whether this property has multiple values
* @param entity the entity to populate
*/
private static void addPropertyToPb(String name, @Nullable Object value, boolean indexed, boolean forceIndexedEmbeddedEntity, boolean multiple, EntityProto entity) {
Property property = new Property();
property.setName(name);
property.setMultiple(multiple);
PropertyValue newValue = property.getMutableValue();
if (value != null) {
Type<?> type = getType(value.getClass());
Meaning meaning = type.getV3Meaning();
if (meaning != property.getMeaningEnum()) {
property.setMeaning(meaning);
}
type.toV3Value(value, newValue);
if (indexed && forceIndexedEmbeddedEntity && DataTypeUtils.isUnindexableType(value.getClass())) {
// with collections whose contents have been changed in the meantime.
throw new UnsupportedOperationException("Value must be indexable.");
}
if (!forceIndexedEmbeddedEntity || !(value instanceof EmbeddedEntity)) {
// If client was trying to index a type that they shouldn't then clear the index flag for
// them.
indexed &= type.canBeIndexed();
}
}
if (indexed) {
entity.addProperty(property);
} else {
entity.addRawProperty(property);
}
}
Aggregations