Search in sources :

Example 16 with Property

use of com.google.storage.onestore.v3.OnestoreEntity.Property in project appengine-java-standard by GoogleCloudPlatform.

the class OrderedIndexComponent method preferredIndexProperties.

@Override
public List<Property> preferredIndexProperties() {
    List<Property> indexProps = Lists.newArrayListWithExpectedSize(matcherProperties.size());
    for (Property prop : matcherProperties) {
        if (!prop.hasDirection()) {
            prop = prop.clone();
            prop.setDirection(Direction.ASCENDING);
        }
        indexProps.add(prop);
    }
    return indexProps;
}
Also used : Property(com.google.storage.onestore.v3.OnestoreEntity.Index.Property)

Example 17 with Property

use of com.google.storage.onestore.v3.OnestoreEntity.Property in project nomulus by google.

the class EntityImports method fixProperty.

private static void fixProperty(OnestoreEntity.Property property, String appId) {
    OnestoreEntity.PropertyValue value = property.getMutableValue();
    if (value.hasReferenceValue()) {
        fixKey(value.getMutableReferenceValue(), appId);
        return;
    }
    if (property.getMeaningEnum().equals(Meaning.ENTITY_PROTO)) {
        EntityProto embeddedProto = bytesToEntityProto(value.getStringValueAsBytes());
        fixEntity(embeddedProto, appId);
        value.setStringValueAsBytes(embeddedProto.toByteArray());
    }
}
Also used : OnestoreEntity(com.google.storage.onestore.v3.OnestoreEntity) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 18 with Property

use of com.google.storage.onestore.v3.OnestoreEntity.Property in project nomulus by google.

the class EntityWrapperTest method testEquals.

@Test
void testEquals() {
    // Create an entity with a key and some properties.
    Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID);
    // Note that we need to specify these as long for property comparisons to work because that's
    // how they are deserialized from protos.
    entity.setProperty("eeny", 100L);
    entity.setProperty("meeny", 200L);
    entity.setProperty("miney", 300L);
    EntityProto proto1 = EntityTranslator.convertToPb(entity);
    EntityProto proto2 = EntityTranslator.convertToPb(entity);
    // Reorder the property list of proto2 (the protobuf stores this as a repeated field, so
    // we just have to clear and re-add them in a different order).
    ImmutableList<Property> properties = ImmutableList.of(proto2.getProperty(2), proto2.getProperty(0), proto2.getProperty(1));
    proto2.clearProperty();
    for (Property property : properties) {
        proto2.addProperty(property);
    }
    // Construct entity objects from the two protos.
    Entity e1 = EntityTranslator.createFromPb(proto1);
    Entity e2 = EntityTranslator.createFromPb(proto2);
    // Ensure that we have a normalized representation.
    EntityWrapper ce1 = new EntityWrapper(e1);
    EntityWrapper ce2 = new EntityWrapper(e2);
    assertThat(ce1).isEqualTo(ce2);
    assertThat(ce1.hashCode()).isEqualTo(ce2.hashCode());
    // Ensure that the original entity is equal.
    assertThat(new EntityWrapper(entity)).isEqualTo(ce1);
}
Also used : Entity(com.google.appengine.api.datastore.Entity) Property(com.google.storage.onestore.v3.OnestoreEntity.Property) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto) Test(org.junit.jupiter.api.Test)

Example 19 with Property

use of com.google.storage.onestore.v3.OnestoreEntity.Property in project nomulus by google.

the class EntityWrapperTest method testDifferentPropertiesNotEqual.

@Test
void testDifferentPropertiesNotEqual() {
    Entity entity = new Entity(TEST_ENTITY_KIND, ARBITRARY_KEY_ID);
    // Note that we need to specify these as long for property comparisons to work because that's
    // how they are deserialized from protos.
    entity.setProperty("eeny", 100L);
    entity.setProperty("meeny", 200L);
    entity.setProperty("miney", 300L);
    EntityProto proto1 = EntityTranslator.convertToPb(entity);
    entity.setProperty("tiger!", 400);
    EntityProto proto2 = EntityTranslator.convertToPb(entity);
    // Construct entity objects from the two protos.
    Entity e1 = EntityTranslator.createFromPb(proto1);
    Entity e2 = EntityTranslator.createFromPb(proto2);
    EntityWrapper ce1 = new EntityWrapper(e1);
    EntityWrapper ce2 = new EntityWrapper(e2);
    // The keys should still be the same.
    assertThat(e1).isEqualTo(e2);
    assertThat(ce1).isNotEqualTo(ce2);
    assertThat(ce1.hashCode()).isNotEqualTo(ce2.hashCode());
}
Also used : Entity(com.google.appengine.api.datastore.Entity) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto) Test(org.junit.jupiter.api.Test)

Example 20 with Property

use of com.google.storage.onestore.v3.OnestoreEntity.Property in project nomulus by google.

the class EntityImports method fixMutationEntityProtoBytes.

private static void fixMutationEntityProtoBytes(EntityProto entityProto, String appId) {
    for (OnestoreEntity.Property property : entityProto.mutableRawPropertys()) {
        if (Objects.equals(property.getName(), "entityProtoBytes")) {
            OnestoreEntity.PropertyValue value = property.getValue();
            EntityProto fixedProto = fixEntity(bytesToEntityProto(value.getStringValueAsBytes()), appId);
            value.setStringValueAsBytes(fixedProto.toByteArray());
            return;
        }
    }
}
Also used : OnestoreEntity(com.google.storage.onestore.v3.OnestoreEntity) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Aggregations

Property (com.google.storage.onestore.v3.OnestoreEntity.Property)15 PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)9 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)8 Property (com.google.storage.onestore.v3.OnestoreEntity.Index.Property)8 Filter (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)5 Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)4 ByteString (com.google.protobuf.ByteString)4 Index (com.google.storage.onestore.v3.OnestoreEntity.Index)4 OnestoreEntity (com.google.storage.onestore.v3.OnestoreEntity)3 Map (java.util.Map)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)3 Test (org.junit.Test)3 Entity (com.google.appengine.api.datastore.Entity)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 Property (com.google.appengine.api.datastore.Index.Property)1 Extent (com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent)1 Profile (com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile)1