Search in sources :

Example 21 with Index

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

Aggregations

Index (com.google.storage.onestore.v3.OnestoreEntity.Index)8 OnestoreEntity (com.google.storage.onestore.v3.OnestoreEntity)5 Property (com.google.storage.onestore.v3.OnestoreEntity.Index.Property)5 Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)4 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)4 IndexComponentsOnlyQuery (com.google.appengine.api.datastore.CompositeIndexManager.IndexComponentsOnlyQuery)3 DatastoreV3Pb (com.google.apphosting.datastore.DatastoreV3Pb)3 ByteString (com.google.protobuf.ByteString)3 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Test (org.junit.Test)3 Filter (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)2 ImmutableList (com.google.common.collect.ImmutableList)2 CompositeIndex (com.google.storage.onestore.v3.OnestoreEntity.CompositeIndex)2 PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)2 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2