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;
}
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);
}
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();
}
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();
}
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;
}
Aggregations