Search in sources :

Example 11 with Property

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

Example 12 with Property

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

the class OrderedIndexComponentTest method testPreferredIndexProperties.

/**
 * Tests the preferred index of the component.
 */
@Test
public void testPreferredIndexProperties() {
    List<Property> preferredIndex = newIndex("P1", "P2", "P3");
    assertThat(orderedComponent.preferredIndexProperties()).isEqualTo(preferredIndex);
    Property noDirectionProperty = new Property().setName("P1");
    IndexComponent directionlessComponent = new OrderedIndexComponent(Lists.newArrayList(noDirectionProperty, newProperty("P2"), newProperty("P3")));
    // With a directionless property, the preferred index property should have an ASC direction.
    assertThat(directionlessComponent.preferredIndexProperties()).isEqualTo(preferredIndex);
}
Also used : Property(com.google.storage.onestore.v3.OnestoreEntity.Index.Property) Test(org.junit.Test)

Example 13 with Property

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

the class OrderedIndexComponentTest method testNoDirection.

/**
 * Tests that properties that do not have directions specified can match on any direction.
 */
@Test
public void testNoDirection() {
    Property noDirectionProperty = new Property().setName("P1");
    List<Property> indexDesc = newIndex(newProperty("P1", Direction.DESCENDING), "P2", "P3");
    List<Property> indexAsc = newIndex("P1", "P2", "P3");
    List<Property> indexNoDir = newIndex(noDirectionProperty, "P2", "P3");
    IndexComponent directionlessOrderedComponent = new OrderedIndexComponent(Lists.newArrayList(noDirectionProperty, newProperty("P2"), newProperty("P3")));
    assertThat(directionlessOrderedComponent.matches(indexDesc)).isTrue();
    assertThat(directionlessOrderedComponent.matches(indexAsc)).isTrue();
    assertThat(directionlessOrderedComponent.matches(indexNoDir)).isTrue();
    assertThat(orderedComponent.matches(indexDesc)).isFalse();
    assertThat(orderedComponent.matches(indexAsc)).isTrue();
    assertThat(orderedComponent.matches(indexNoDir)).isFalse();
}
Also used : Property(com.google.storage.onestore.v3.OnestoreEntity.Index.Property) Test(org.junit.Test)

Example 14 with Property

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

the class IndexTranslatorTest method testIgnoreGeoMode.

/**
 * Ensures that an Index with a GEOSPATIAL mode can be converted (even though for now we're
 * ignoring the mode).
 */
// TODO add support for Mode, so that it can be surfaced to the app
@Test
public void testIgnoreGeoMode() {
    OnestoreEntity.CompositeIndex ci = new OnestoreEntity.CompositeIndex();
    ci.setAppId("foo");
    ci.setId(1);
    ci.setState(OnestoreEntity.CompositeIndex.State.WRITE_ONLY);
    OnestoreEntity.Index indexPb = new OnestoreEntity.Index().setEntityType("Mountain").setAncestor(false);
    indexPb.addProperty(new OnestoreEntity.Index.Property().setName("location").setMode(OnestoreEntity.Index.Property.Mode.GEOSPATIAL));
    ci.setDefinition(indexPb);
    Index index = IndexTranslator.convertFromPb(ci);
    assertThat(index.getProperties()).hasSize(1);
    Property property = index.getProperties().get(0);
    assertThat(property.getName()).isEqualTo("location");
    assertThat(property.getDirection()).isNull();
}
Also used : OnestoreEntity(com.google.storage.onestore.v3.OnestoreEntity) Property(com.google.appengine.api.datastore.Index.Property) Test(org.junit.Test)

Example 15 with Property

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

the class UnorderedIndexComponent method preferredIndexProperties.

@Override
public List<Property> preferredIndexProperties() {
    List<Property> indexProps = Lists.newArrayListWithExpectedSize(matcherProperties.size());
    for (String name : matcherProperties) {
        Property indexProperty = new Property();
        indexProperty.setName(name);
        indexProperty.setDirection(Direction.ASCENDING);
        indexProps.add(indexProperty);
    }
    return indexProps;
}
Also used : Property(com.google.storage.onestore.v3.OnestoreEntity.Index.Property)

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