Search in sources :

Example 16 with EntityProto

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

the class PropertyPseudoKind method addPropertyEntitiesToSchema.

/**
 * Build __property__ entities from results of scanning entities, and add them to the schema
 */
private static void addPropertyEntitiesToSchema(List<EntityProto> schema, String kind, SortedSetMultimap<String, String> allProps, String app, String namespace, boolean keysOnly) {
    // {@link SortedSet}s so the results will be ordered.
    for (String prop : allProps.keySet()) {
        // Create schema entity and set its key based on the kind
        EntityProto propEntity = new EntityProto();
        schema.add(propEntity);
        Path path = new Path();
        path.addElement().setType(KIND_METADATA_KIND).setName(kind);
        path.addElement().setType(PROPERTY_METADATA_KIND).setName(prop);
        Reference key = new Reference().setApp(app).setPath(path);
        if (namespace.length() > 0) {
            key.setNameSpace(namespace);
        }
        propEntity.setKey(key);
        // EntityProto.entity_group is a required PB field.
        propEntity.getMutableEntityGroup().addElement(path.getElement(0));
        if (!keysOnly) {
            for (String rep : allProps.get(prop)) {
                PropertyValue repValue = new PropertyValue().setStringValue(rep);
                propEntity.addProperty().setName("property_representation").setValue(repValue).setMultiple(true);
            }
        }
    }
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 17 with EntityProto

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

the class EntityTest method testUnindexedValue.

@Test
public void testUnindexedValue() {
    Entity entity = new Entity("foo");
    entity.setProperty("indexed", "foo");
    entity.setUnindexedProperty("unindexed", "bar");
    entity.setProperty("text", new Text("hello"));
    entity.setProperty("blob", new Blob(new byte[] { 1, 2, 3 }));
    entity.setProperty("entity", new EmbeddedEntity());
    assertThat(entity.hasProperty("indexed")).isTrue();
    assertThat(entity.getProperty("indexed")).isEqualTo("foo");
    assertThat(entity.isUnindexedProperty("indexed")).isFalse();
    assertWithMessage("isUnindexed for text").that(entity.isUnindexedProperty("text")).isTrue();
    assertWithMessage("isUnindexed for blob").that(entity.isUnindexedProperty("blob")).isTrue();
    assertWithMessage("isUnindexed for embedded entity").that(entity.isUnindexedProperty("entity")).isTrue();
    assertThat(entity.hasProperty("unindexed")).isTrue();
    assertThat(entity.getProperty("unindexed")).isEqualTo("bar");
    assertThat(entity.isUnindexedProperty("unindexed")).isTrue();
    assertThat(entity.getProperties()).containsExactly("indexed", "foo", "unindexed", "bar", "text", new Text("hello"), "blob", new Blob(new byte[] { 1, 2, 3 }), "entity", new EmbeddedEntity());
    assertThat(entity.getPropertyMap()).containsExactly("indexed", "foo", "unindexed", new Entity.UnindexedValue("bar"), "text", new Text("hello"), "blob", new Blob(new byte[] { 1, 2, 3 }), "entity", new EmbeddedEntity());
    EntityProto proto = EntityTranslator.convertToPb(entity);
    assertThat(proto.propertySize()).isEqualTo(1);
    assertThat(proto.rawPropertySize()).isEqualTo(4);
}
Also used : EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto) Test(org.junit.Test)

Example 18 with EntityProto

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

the class RecordAccumulator method getEntityWrapperSet.

/**
 * Creates an {@link EntityWrapper} set from the current set of raw records.
 */
ImmutableSet<EntityWrapper> getEntityWrapperSet() {
    ImmutableSet.Builder<EntityWrapper> builder = new ImmutableSet.Builder<>();
    for (byte[] rawRecord : records) {
        // Parse the entity proto and create an Entity object from it.
        EntityProto proto = new EntityProto();
        proto.parseFrom(rawRecord);
        EntityWrapper entity = new EntityWrapper(EntityTranslator.createFromPb(proto));
        builder.add(entity);
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 19 with EntityProto

use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto 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 20 with EntityProto

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

the class EntityImportsTest method loadEntityProtos.

private static ImmutableList<EntityProto> loadEntityProtos(InputStream inputStream) {
    ImmutableList.Builder<EntityProto> protosBuilder = new ImmutableList.Builder<>();
    while (true) {
        EntityProto proto = new EntityProto();
        boolean parsed = proto.parseDelimitedFrom(inputStream);
        if (parsed && proto.isInitialized()) {
            protosBuilder.add(proto);
        } else {
            break;
        }
    }
    return protosBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Aggregations

EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)32 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)13 Path (com.google.storage.onestore.v3.OnestoreEntity.Path)9 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)9 ByteString (com.google.protobuf.ByteString)7 ImmutableList (com.google.common.collect.ImmutableList)6 Map (java.util.Map)6 PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)5 Entity (com.google.appengine.api.datastore.Entity)3 Extent (com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent)3 Profile (com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile)3 Cost (com.google.apphosting.datastore.DatastoreV3Pb.Cost)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Element (com.google.storage.onestore.v3.OnestoreEntity.Path.Element)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 WeakHashMap (java.util.WeakHashMap)3