Search in sources :

Example 1 with PropertyType

use of com.google.storage.onestore.PropertyType 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

Extent (com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent)1 Profile (com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile)1 PropertyType (com.google.storage.onestore.PropertyType)1 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)1 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)1 Map (java.util.Map)1