Search in sources :

Example 1 with Meaning

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

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

the class NamespacePseudoKind method runQuery.

@Override
List<EntityProto> runQuery(Query query, Key startKey, boolean startInclusive, Key endKey, boolean endInclusive) {
    /* Ancestor has no meaning in namespace queries. This also has the desirable side effect that
     * schema queries cannot live in transactions. */
    checkRequest(!query.hasAncestor(), "ancestor queries on " + NAMESPACE_METADATA_KIND + " not allowed");
    String app = query.getApp();
    String startNamespace = namespaceKeyToString(startKey);
    String endNamespace = namespaceKeyToString(endKey);
    Profile profile = getDatastore().getOrCreateProfile(app);
    Map<String, Extent> extents = profile.getExtents();
    Set<String> namespaceSet = new HashSet<String>();
    synchronized (extents) {
        // Just collect all namespaces that are in the selected range
        for (Map.Entry<String, Extent> entry : extents.entrySet()) {
            for (EntityProto entity : entry.getValue().getAllEntityProtos()) {
                String namespace = entity.getKey().getNameSpace();
                // Apply filters.
                if (startNamespace != null) {
                    int namespacesCompared = namespace.compareTo(startNamespace);
                    if ((startInclusive && namespacesCompared < 0) || (!startInclusive && namespacesCompared <= 0)) {
                        continue;
                    }
                }
                if (endNamespace != null) {
                    int namespacesCompared = namespace.compareTo(endNamespace);
                    if ((endInclusive && namespacesCompared > 0) || (!endInclusive && namespacesCompared >= 0)) {
                        continue;
                    }
                }
                namespaceSet.add(namespace);
            }
        }
    }
    return makeNamespaceEntities(namespaceSet, app, query.getNameSpace());
}
Also used : Extent(com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent) Map(java.util.Map) Profile(com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile) HashSet(java.util.HashSet) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 3 with Meaning

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

the class DataTypeTranslator method addPropertyToPb.

/**
 * Adds a property to {@code entity}.
 *
 * @param name the property name
 * @param value the property value
 * @param indexed whether this property should be indexed. This may be overridden by property
 *     types like Blob and Text that are never indexed.
 * @param forceIndexedEmbeddedEntity whether indexed embedded entities should actually be indexed,
 *     as opposed to silently moved to unindexed properties (legacy behavior)
 * @param multiple whether this property has multiple values
 * @param entity the entity to populate
 */
private static void addPropertyToPb(String name, @Nullable Object value, boolean indexed, boolean forceIndexedEmbeddedEntity, boolean multiple, EntityProto entity) {
    Property property = new Property();
    property.setName(name);
    property.setMultiple(multiple);
    PropertyValue newValue = property.getMutableValue();
    if (value != null) {
        Type<?> type = getType(value.getClass());
        Meaning meaning = type.getV3Meaning();
        if (meaning != property.getMeaningEnum()) {
            property.setMeaning(meaning);
        }
        type.toV3Value(value, newValue);
        if (indexed && forceIndexedEmbeddedEntity && DataTypeUtils.isUnindexableType(value.getClass())) {
            // with collections whose contents have been changed in the meantime.
            throw new UnsupportedOperationException("Value must be indexable.");
        }
        if (!forceIndexedEmbeddedEntity || !(value instanceof EmbeddedEntity)) {
            // If client was trying to index a type that they shouldn't then clear the index flag for
            // them.
            indexed &= type.canBeIndexed();
        }
    }
    if (indexed) {
        entity.addProperty(property);
    } else {
        entity.addRawProperty(property);
    }
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) Property(com.google.storage.onestore.v3.OnestoreEntity.Property) Meaning(com.google.storage.onestore.v3.OnestoreEntity.Property.Meaning)

Example 4 with Meaning

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

the class KindPseudoKind method runQuery.

// Based on LocalDatastoreService.getSchema (now removed)
@Override
List<EntityProto> runQuery(Query query, Key startKey, boolean startInclusive, Key endKey, boolean endInclusive) {
    /* Ancestor has no meaning in schema queries. This also has the desirable side effect that
     * schema queries cannot live in transactions. */
    checkRequest(!query.hasAncestor(), "ancestor queries on " + KIND_METADATA_KIND + " not allowed");
    String app = query.getApp();
    String namespace = query.getNameSpace();
    String startKind = kindKeyToString(startKey);
    String endKind = kindKeyToString(endKey);
    Profile profile = getDatastore().getOrCreateProfile(app);
    Map<String, Extent> extents = profile.getExtents();
    List<EntityProto> kinds = Lists.newArrayList();
    synchronized (extents) {
        // We create one EntityProto per kind with a key containing the kind name
        for (Map.Entry<String, Extent> entry : extents.entrySet()) {
            String kind = entry.getKey();
            // Apply filters.
            if (startKind != null) {
                int kindsCompared = kind.compareTo(startKind);
                if ((startInclusive && kindsCompared < 0) || (!startInclusive && kindsCompared <= 0)) {
                    continue;
                }
            }
            if (endKind != null) {
                int kindsCompared = kind.compareTo(endKind);
                if ((endInclusive && kindsCompared > 0) || (!endInclusive && kindsCompared >= 0)) {
                    continue;
                }
            }
            if (entry.getValue().getAllEntityProtos().isEmpty()) {
                // no entities of this kind
                continue;
            }
            // Add an entry only if entities exist in the requested namespace.
            if (isKindPresentInNamespace(entry.getValue(), namespace)) {
                kinds.add(makeKindEntity(kind, app, namespace));
            }
        }
    }
    return kinds;
}
Also used : Extent(com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent) Map(java.util.Map) Profile(com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Aggregations

Extent (com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent)2 Profile (com.google.appengine.api.datastore.dev.LocalDatastoreService.Profile)2 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)2 PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)2 Map (java.util.Map)2 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)1 Meaning (com.google.storage.onestore.v3.OnestoreEntity.Property.Meaning)1 HashSet (java.util.HashSet)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1