Search in sources :

Example 31 with Property

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

the class EntityStorageConversions method restoreStashedProperties.

/**
 * Moves stashed properties back from raw properties to properties.
 *
 * <p>Note: this piece of code assumes that stashed properties appear in the raw property list in
 * stashed index order.
 *
 * @param storageEntity The EntityProto to modify.
 */
static void restoreStashedProperties(EntityProto storageEntity) {
    ImmutableList<Property> properties = ImmutableList.copyOf(storageEntity.propertys());
    ImmutableList<Property> rawProperties = ImmutableList.copyOf(storageEntity.rawPropertys());
    ImmutableList.Builder<Property> badlyStashedProperties = ImmutableList.builder();
    int propertyListIndex = 0;
    storageEntity.clearProperty();
    storageEntity.clearRawProperty();
    for (Property rawProperty : rawProperties) {
        if (rawProperty.hasStashed()) {
            int stashed = rawProperty.getStashed();
            int advance = stashed - storageEntity.propertySize();
            if (// Not at the end (out-of-order, duplicate)
            stashed < storageEntity.propertySize() || propertyListIndex + advance > properties.size()) {
                // Past the end
                // The value of stashed is bad.
                badlyStashedProperties.add(rawProperty.clearStashed());
            } else {
                // Copy until before the position where the stashed property needs to be restored.
                if (advance > 0) {
                    storageEntity.mutablePropertys().addAll(properties.subList(propertyListIndex, propertyListIndex + advance));
                    propertyListIndex = propertyListIndex + advance;
                }
                storageEntity.addProperty(rawProperty.clearStashed());
            }
        } else {
            storageEntity.addRawProperty(rawProperty);
        }
    }
    storageEntity.mutablePropertys().addAll(properties.subList(propertyListIndex, properties.size()));
    storageEntity.mutablePropertys().addAll(badlyStashedProperties.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Property(com.google.storage.onestore.v3.OnestoreEntity.Property)

Example 32 with Property

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

the class EntityStorageConversions method createComputedAndStashedValuesForEntityValues.

/**
 * Modifies an entity by marking all indexed entity values for stashing, and flattening all leaf
 * sub-properties into top-level properties. Does not perform any kind of validation.
 *
 * @param diskEntity The EntityProto to modify.
 */
private static void createComputedAndStashedValuesForEntityValues(EntityProto diskEntity) {
    ImmutableList.Builder<Property> computedProperties = ImmutableList.builder();
    for (int i = 0; i < diskEntity.propertySize(); i++) {
        Property property = diskEntity.getProperty(i);
        if (isEntityValue(property)) {
            // Mark for stashing.
            property.setStashed(i);
            flattenIndexedEntityValues(property.getName(), property.isMultiple(), property.getValue().getStringValueAsBytes(), computedProperties);
        }
    }
    diskEntity.mutablePropertys().addAll(computedProperties.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Property(com.google.storage.onestore.v3.OnestoreEntity.Property)

Example 33 with Property

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

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