Search in sources :

Example 6 with Property

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

the class DataTypeTranslator method getPropertyValue.

/**
 * Returns the value for the property as its canonical type.
 *
 * @param property a not {@code null} property
 * @return {@code null} if no value was set for {@code property}
 */
@Nullable
public static Object getPropertyValue(Property property) {
    int meaningInt = property.getMeaning();
    PropertyValue value = property.getValue();
    if (meaningInt == 0) {
        // The value has no meaning.  Check possible types, most likely first.
        for (Type<?> type : TYPES_WITHOUT_MEANING_IN_EXPECTED_FREQUENCY_ORDER) {
            if (type.hasValue(value)) {
                return type.getValue(value);
            }
        }
    // The value is null or malformed.
    } else if ((meaningInt > 0) && (meaningInt < MEANING_INT_TO_TYPE.length)) {
        // The value has a meaning.  Check that meaning's type.
        Type<?> type = MEANING_INT_TO_TYPE[meaningInt];
        if ((type != null) && type.hasValue(value)) {
            return type.getValue(value);
        }
    // The value is malformed.
    } else {
    // The value is malformed.
    }
    return null;
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 7 with Property

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

the class IndexComponentsOnlyQuery method categorizeQuery.

private void categorizeQuery() {
    Set<String> ineqProps = Sets.newHashSet();
    hasKeyProperty = false;
    for (Filter filter : query.filters()) {
        String propName = filter.getProperty(0).getName();
        switch(filter.getOpEnum()) {
            case EQUAL:
                equalityProps.add(propName);
                break;
            case EXISTS:
                existsProps.add(propName);
                break;
            case GREATER_THAN:
            case GREATER_THAN_OR_EQUAL:
            case LESS_THAN:
            case LESS_THAN_OR_EQUAL:
                ineqProps.add(propName);
                break;
            case CONTAINED_IN_REGION:
                containmentProps.add(propName);
                break;
            default:
                throw new IllegalArgumentException("Unable to categorize query using filter operator " + filter.getOp());
        }
        if (propName.equals(Entity.KEY_RESERVED_PROPERTY)) {
            hasKeyProperty = true;
        }
    }
    // Add the inequality filter properties, if any.
    if (query.orderSize() == 0 && !ineqProps.isEmpty()) {
        // We do not add an index property for the inequality filter because
        // it will be taken care of when we add the sort on that same property
        // down below.
        orderProps.add(new Property().setName(ineqProps.iterator().next()));
    }
    groupByProps.addAll(query.groupByPropertyNames());
    // If a property is included in the group by, its existance will be satisfied.
    existsProps.removeAll(groupByProps);
    // Add orders.
    for (Order order : query.orders()) {
        if (order.getProperty().equals(Entity.KEY_RESERVED_PROPERTY)) {
            hasKeyProperty = true;
        }
        // If a property is in the ordering, it has already been satisfied.
        groupByProps.remove(order.getProperty());
        orderProps.add(new Property().setName(order.getProperty()).setDirection(order.getDirection()));
    }
}
Also used : Order(com.google.apphosting.datastore.DatastoreV3Pb.Query.Order) Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) Property(com.google.storage.onestore.v3.OnestoreEntity.Index.Property)

Example 8 with Property

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

the class LocalDatastoreService method applyGroupByProperties.

/**
 * Creates a new List of entities after applying group by properties.
 *
 * @param queryEntities a sorted list of entities.
 * @param query the current query.
 * @return a new list of entities with unique properties.
 */
private List<EntityProto> applyGroupByProperties(List<EntityProto> queryEntities, Query query) {
    Set<String> groupByProperties = Sets.newHashSet(query.groupByPropertyNames());
    // Nothing to do if there are no group by properties.
    if (groupByProperties.isEmpty()) {
        return queryEntities;
    }
    Set<NameValue> lastEntity = Sets.newHashSet();
    List<EntityProto> results = Lists.newArrayList();
    for (EntityProto entity : queryEntities) {
        boolean isFirst = false;
        for (Property prop : entity.propertys()) {
            if (groupByProperties.contains(prop.getName()) && !lastEntity.contains(NameValue.of(prop.getName(), prop.getValue()))) {
                isFirst = true;
                break;
            }
        }
        if (isFirst) {
            results.add(entity);
            // Set lastEntity to be the new set of properties.
            lastEntity.clear();
            for (Property prop : entity.propertys()) {
                if (groupByProperties.contains(prop.getName())) {
                    lastEntity.add(NameValue.of(prop.getName(), prop.getValue()));
                }
            }
        }
    }
    return results;
}
Also used : ByteString(com.google.protobuf.ByteString) Property(com.google.storage.onestore.v3.OnestoreEntity.Property) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 9 with Property

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

the class LocalDatastoreService method validateAndProcessEntityProto.

private void validateAndProcessEntityProto(EntityProto entity) {
    validatePathForPut(entity.getKey());
    for (Property prop : entity.propertys()) {
        validateAndProcessProperty(prop);
        validateLengthLimit(prop);
    }
    for (Property prop : entity.rawPropertys()) {
        validateAndProcessProperty(prop);
        validateRawPropLengthLimit(prop);
    }
}
Also used : Property(com.google.storage.onestore.v3.OnestoreEntity.Property)

Example 10 with Property

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

the class LocalDatastoreService method validateRawPropLengthLimit.

private void validateRawPropLengthLimit(Property property) {
    String name = property.getName();
    PropertyValue value = property.getValue();
    if (!value.hasStringValue() || !property.hasMeaning()) {
        return;
    }
    if (property.getMeaningEnum() == Property.Meaning.BLOB || property.getMeaningEnum() == Property.Meaning.ENTITY_PROTO || property.getMeaningEnum() == Property.Meaning.TEXT) {
        if (value.getStringValueAsBytes().length > MAX_BLOB_LENGTH) {
            throw newError(ErrorCode.BAD_REQUEST, "Property " + name + " is too long. It cannot exceed " + MAX_BLOB_LENGTH + " bytes.");
        }
    }
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) ByteString(com.google.protobuf.ByteString)

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