Search in sources :

Example 1 with PropertyValue

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

the class DataTypeTranslator method buildImplicitKeyProperty.

private static Property buildImplicitKeyProperty(EntityProto proto) {
    Property keyProp = new Property();
    keyProp.setName(Entity.KEY_RESERVED_PROPERTY);
    PropertyValue propVal = new PropertyValue();
    propVal.setReferenceValue(KeyType.toReferenceValue(proto.getKey()));
    keyProp.setValue(propVal);
    return keyProp;
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) Property(com.google.storage.onestore.v3.OnestoreEntity.Property)

Example 2 with PropertyValue

use of com.google.storage.onestore.v3.OnestoreEntity.PropertyValue 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 3 with PropertyValue

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

Example 4 with PropertyValue

use of com.google.storage.onestore.v3.OnestoreEntity.PropertyValue 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 5 with PropertyValue

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

the class PropertyPseudoKind method addPropertyEntitiesToSchema.

/**
 * Build __property__ entities from results of scanning entities, and add them to the schema
 */
private static void addPropertyEntitiesToSchema(List<EntityProto> schema, String kind, SortedSetMultimap<String, String> allProps, String app, String namespace, boolean keysOnly) {
    // {@link SortedSet}s so the results will be ordered.
    for (String prop : allProps.keySet()) {
        // Create schema entity and set its key based on the kind
        EntityProto propEntity = new EntityProto();
        schema.add(propEntity);
        Path path = new Path();
        path.addElement().setType(KIND_METADATA_KIND).setName(kind);
        path.addElement().setType(PROPERTY_METADATA_KIND).setName(prop);
        Reference key = new Reference().setApp(app).setPath(path);
        if (namespace.length() > 0) {
            key.setNameSpace(namespace);
        }
        propEntity.setKey(key);
        // EntityProto.entity_group is a required PB field.
        propEntity.getMutableEntityGroup().addElement(path.getElement(0));
        if (!keysOnly) {
            for (String rep : allProps.get(prop)) {
                PropertyValue repValue = new PropertyValue().setStringValue(rep);
                propEntity.addProperty().setName("property_representation").setValue(repValue).setMultiple(true);
            }
        }
    }
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Aggregations

PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)18 Test (org.junit.Test)5 Filter (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)4 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)4 ByteString (com.google.protobuf.ByteString)3 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)3 DatastoreV3Pb (com.google.apphosting.datastore.DatastoreV3Pb)2 Path (com.google.storage.onestore.v3.OnestoreEntity.Path)2 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 GeoRegion (com.google.apphosting.datastore.DatastoreV3Pb.GeoRegion)1 Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Meaning (com.google.storage.onestore.v3.OnestoreEntity.Property.Meaning)1 ReferenceValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue.ReferenceValue)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1