Search in sources :

Example 16 with Path

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

the class EntityStorageConversions method flattenIndexedEntityValues.

/**
 * Recursively walk the given entity value and flattens all leaf sub-properties into
 * flattenedProperties. In the top level call pathPrefix and multiplePath should be respectively
 * the name and the multiple bit of the property enclosing the entity value. This method is
 * designed for internal use, do not make it public.
 *
 * @param pathPrefix Prefix to be added to property names for the current recursion level.
 * @param multiplePath Whether a multiple property has been encountered in the path.
 * @param currentSerializedEntityValue The serialized entity value to inspect recursively.
 * @param flattenedProperties The list where flattened sub-properties are to be added.
 */
private static void flattenIndexedEntityValues(String pathPrefix, boolean multiplePath, byte[] currentSerializedEntityValue, ImmutableList.Builder<Property> flattenedProperties) {
    checkArgument(!Strings.isNullOrEmpty(pathPrefix));
    EntityProto currentEntityValue = deserializeEmbeddedEntityProto(currentSerializedEntityValue, pathPrefix);
    if (currentEntityValue.getKey().getPath().elementSize() > 0) {
        // Path is not empty
        flattenedProperties.add(new Property().setName(pathPrefix + Kinds.PROPERTY_PATH_DELIMITER_AND_KEY_SUFFIX).setValue(ReferenceValues.toReferenceProperty(currentEntityValue.getKey())).setMultiple(multiplePath).setComputed(true));
    }
    for (Property property : currentEntityValue.propertys()) {
        if (isEntityValue(property)) {
            // This is a nested entity value.
            flattenIndexedEntityValues(pathPrefix + Kinds.PROPERTY_PATH_DELIMITER + property.getName(), multiplePath || property.isMultiple(), property.getValue().getStringValueAsBytes(), flattenedProperties);
        } else {
            // This is a leaf sub-property.
            flattenedProperties.add(property.setName(pathPrefix + Kinds.PROPERTY_PATH_DELIMITER + property.getName()).setMultiple(multiplePath || property.isMultiple()).setComputed(true));
        }
    }
}
Also used : Property(com.google.storage.onestore.v3.OnestoreEntity.Property) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Aggregations

Path (com.google.storage.onestore.v3.OnestoreEntity.Path)15 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)11 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)8 Element (com.google.storage.onestore.v3.OnestoreEntity.Path.Element)5 ByteString (com.google.protobuf.ByteString)4 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Utils.getLastElement (com.google.appengine.api.datastore.dev.Utils.getLastElement)2 Cost (com.google.apphosting.datastore.DatastoreV3Pb.Cost)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 WeakHashMap (java.util.WeakHashMap)2 Test (org.junit.Test)2 EntityProtoComparator (com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator)1 DeleteResponse (com.google.apphosting.datastore.DatastoreV3Pb.DeleteResponse)1