Search in sources :

Example 11 with EntityProto

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

the class EntityGroupPseudoKind method get.

@Override
@Nullable
public EntityProto get(@Nullable LiveTxn txn, EntityGroup eg, Reference key, boolean eventualConsistency) {
    // We plan to add support to query the set of entity groups by querying this pseudo-kind.  Such
    // queries would return pseudo-entities as direct children of the entity-group root with
    // numeric key ID. Thus to make sure we can get() and queries are consistent, we require that
    // key match that format.
    Path path = key.getPath();
    if (path.elementSize() != 2 || path.getElement(1).getId() != ENTITY_GROUP_METADATA_ID) {
        return null;
    }
    long version;
    if (txn == null) {
        // Can just grab the entity-group version as its incremented eagerly rather than on job-apply.
        version = eg.getVersion();
    } else {
        version = txn.trackEntityGroup(eg).getEntityGroupVersion();
    }
    // return a version even when the entity group is empty(new or not).
    return makeEntityGroupEntity(key, version + baseVersion);
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 12 with EntityProto

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

the class EntityGroupPseudoKind method makeEntityGroupEntity.

/**
 * Creates an __entity_group__ entity
 */
private static EntityProto makeEntityGroupEntity(Reference key, long version) {
    EntityProto egEntity = new EntityProto().setKey(key);
    // EntityProto.entity_group is a required PB field.
    egEntity.getMutableEntityGroup().addElement(key.getPath().getElement(0));
    PropertyValue value = new PropertyValue().setInt64Value(version);
    egEntity.addProperty().setMultiple(false).setName(VERSION_RESERVED_PROPERTY).setValue(value);
    return egEntity;
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 13 with EntityProto

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

the class NamespacePseudoKind method runQuery.

@Override
List<EntityProto> runQuery(Query query, Key startKey, boolean startInclusive, Key endKey, boolean endInclusive) {
    /* Ancestor has no meaning in namespace queries. This also has the desirable side effect that
     * schema queries cannot live in transactions. */
    checkRequest(!query.hasAncestor(), "ancestor queries on " + NAMESPACE_METADATA_KIND + " not allowed");
    String app = query.getApp();
    String startNamespace = namespaceKeyToString(startKey);
    String endNamespace = namespaceKeyToString(endKey);
    Profile profile = getDatastore().getOrCreateProfile(app);
    Map<String, Extent> extents = profile.getExtents();
    Set<String> namespaceSet = new HashSet<String>();
    synchronized (extents) {
        // Just collect all namespaces that are in the selected range
        for (Map.Entry<String, Extent> entry : extents.entrySet()) {
            for (EntityProto entity : entry.getValue().getAllEntityProtos()) {
                String namespace = entity.getKey().getNameSpace();
                // Apply filters.
                if (startNamespace != null) {
                    int namespacesCompared = namespace.compareTo(startNamespace);
                    if ((startInclusive && namespacesCompared < 0) || (!startInclusive && namespacesCompared <= 0)) {
                        continue;
                    }
                }
                if (endNamespace != null) {
                    int namespacesCompared = namespace.compareTo(endNamespace);
                    if ((endInclusive && namespacesCompared > 0) || (!endInclusive && namespacesCompared >= 0)) {
                        continue;
                    }
                }
                namespaceSet.add(namespace);
            }
        }
    }
    return makeNamespaceEntities(namespaceSet, app, query.getNameSpace());
}
Also used : Extent(com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent) Map(java.util.Map) Profile(com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile) HashSet(java.util.HashSet) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 14 with EntityProto

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

the class NamespacePseudoKind method makeNamespaceEntities.

private List<EntityProto> makeNamespaceEntities(Set<String> namespaceSet, String app, String executionNamespace) {
    List<EntityProto> namespaces = Lists.newArrayListWithCapacity(namespaceSet.size());
    for (String namespace : namespaceSet) {
        // Create namespace entity and set its key based on the namespace
        EntityProto namespaceEntity = new EntityProto();
        namespaces.add(namespaceEntity);
        Path path = new Path();
        // Empty namespaces use an EMPTY_NAMESPACE_ID key
        if (namespace.isEmpty()) {
            path.addElement().setType(NAMESPACE_METADATA_KIND).setId(EMPTY_NAMESPACE_ID);
        } else {
            path.addElement().setType(NAMESPACE_METADATA_KIND).setName(namespace);
        }
        Reference key = new Reference().setApp(app).setPath(path);
        if (executionNamespace.length() > 0) {
            key.setNameSpace(executionNamespace);
        }
        namespaceEntity.setKey(key);
        // EntityProto.entity_group is a required PB field.
        namespaceEntity.getMutableEntityGroup().addElement(path.getElement(0));
    }
    return namespaces;
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 15 with EntityProto

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

the class PropertyPseudoKind method getProperties.

/**
 * Get the results of a __property__ query over the specified range.
 */
private List<EntityProto> getProperties(String app, String namespace, boolean keysOnly, KindProperty start, boolean startInclusive, KindProperty end, boolean endInclusive) {
    Profile profile = getDatastore().getOrCreateProfile(app);
    Map<String, Extent> extents = profile.getExtents();
    List<EntityProto> schema = Lists.newArrayList();
    synchronized (extents) {
        // that kind.
        for (Map.Entry<String, Extent> entry : extents.entrySet()) {
            String kind = entry.getKey();
            boolean startKindEqual = false;
            boolean endKindEqual = false;
            // Apply kind filter (inclusive is only meaningful at the property level).
            if (start.kind != null) {
                int kindsCompared = kind.compareTo(start.kind);
                startKindEqual = kindsCompared == 0;
                if (kindsCompared < 0) {
                    continue;
                }
            }
            if (end.kind != null) {
                int kindsCompared = kind.compareTo(end.kind);
                endKindEqual = kindsCompared == 0;
                if (kindsCompared > 0) {
                    continue;
                }
            }
            List<EntityProto> entities = getEntitiesForNamespace(entry.getValue(), namespace);
            // Skip kinds with no entities in the specified namespace
            if (entities.isEmpty()) {
                continue;
            }
            // Collect and add the indexed properties. (schema queries don't
            // report unindexed properties; details in http://b/1004244)
            SortedSetMultimap<String, String> allProps = TreeMultimap.create();
            for (EntityProto entity : entities) {
                for (Property prop : entity.propertys()) {
                    String name = prop.getName();
                    PropertyType type = PropertyType.getType(prop.getValue());
                    // Apply start property filter if kind equal to start.kind
                    if (startKindEqual) {
                        int propertysCompared = name.compareTo(start.property);
                        if ((startInclusive && propertysCompared < 0) || (!startInclusive && propertysCompared <= 0)) {
                            continue;
                        }
                    }
                    // Apply end property filter if kind equal to end.kind
                    if (endKindEqual) {
                        int propertysCompared = name.compareTo(end.property);
                        if ((endInclusive && propertysCompared > 0) || (!endInclusive && propertysCompared >= 0)) {
                            continue;
                        }
                    }
                    // Skip invisible special properties.
                    if (getDatastore().getSpecialPropertyMap().containsKey(name) && !getDatastore().getSpecialPropertyMap().get(name).isVisible()) {
                        continue;
                    }
                    allProps.put(name, type.name());
                }
            }
            addPropertyEntitiesToSchema(schema, kind, allProps, app, namespace, keysOnly);
        }
    }
    return schema;
}
Also used : Extent(com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent) PropertyType(com.google.storage.onestore.PropertyType) Profile(com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile) Map(java.util.Map) Property(com.google.storage.onestore.v3.OnestoreEntity.Property) 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