Search in sources :

Example 6 with PropertyValue

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);
}
Also used : Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) DatastoreV3Pb(com.google.apphosting.datastore.DatastoreV3Pb) Test(org.junit.Test)

Example 7 with PropertyValue

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);
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) Date(java.util.Date) Test(org.junit.Test)

Example 8 with PropertyValue

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);
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) Test(org.junit.Test)

Example 9 with PropertyValue

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();
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) Test(org.junit.Test)

Example 10 with PropertyValue

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);
    }
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) Property(com.google.storage.onestore.v3.OnestoreEntity.Property) Meaning(com.google.storage.onestore.v3.OnestoreEntity.Property.Meaning)

Aggregations

PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)18 Test (org.junit.Test)5 Filter (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)4 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)4 ByteString (com.google.protobuf.ByteString)3 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)3 DatastoreV3Pb (com.google.apphosting.datastore.DatastoreV3Pb)2 Path (com.google.storage.onestore.v3.OnestoreEntity.Path)2 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 GeoRegion (com.google.apphosting.datastore.DatastoreV3Pb.GeoRegion)1 Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Meaning (com.google.storage.onestore.v3.OnestoreEntity.Property.Meaning)1 ReferenceValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue.ReferenceValue)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1