use of com.google.appengine.api.datastore.Entity.UnindexedValue in project appengine-java-standard by GoogleCloudPlatform.
the class DataTypeTranslator method addPropertyToMap.
private static void addPropertyToMap(String name, Value value, Map<String, @Nullable Object> map) {
boolean isOrContainsIndexedEntityValue = false;
boolean indexed;
Object result;
if (DatastoreServiceConfig.getEmptyListSupport() && value.getValueTypeCase() == Value.ValueTypeCase.ARRAY_VALUE && value.getArrayValue().getValuesCount() == 0) {
result = new ArrayList<Object>();
indexed = !value.getExcludeFromIndexes();
} else if (value.getArrayValue().getValuesCount() > 0) {
indexed = false;
// Must be ArrayList for backwards compatibility.
ArrayList<@Nullable Object> resultList = new ArrayList<>(value.getArrayValue().getValuesCount());
for (Value subValue : value.getArrayValue().getValuesList()) {
if (subValue.getValueTypeCase() == ValueTypeCase.ARRAY_VALUE) {
throw new IllegalArgumentException("Invalid Entity PB: list within a list.");
}
result = getValue(subValue);
if (!subValue.getExcludeFromIndexes()) {
// This is not optimal but it's needed to be "bug compatible" with v3.
indexed = true;
if (result instanceof EmbeddedEntity) {
isOrContainsIndexedEntityValue = true;
}
}
resultList.add(result);
}
result = resultList;
} else {
// Empty list becomes null.
indexed = !value.getExcludeFromIndexes();
result = getValue(value);
if (indexed && result instanceof EmbeddedEntity) {
isOrContainsIndexedEntityValue = true;
}
}
if (isOrContainsIndexedEntityValue) {
result = new WrappedValueImpl(result, true, true);
} else if (!indexed) {
result = new UnindexedValue(result);
}
map.put(name, result);
}
use of com.google.appengine.api.datastore.Entity.UnindexedValue in project appengine-java-standard by GoogleCloudPlatform.
the class PropertyContainer method setPropertiesFrom.
/**
* A convenience method that populates properties from those in the given container.
*
* <p>This method transfers information about unindexed properties and clones any mutable values.
*
* @param src The container from which we will populate ourself.
*/
public void setPropertiesFrom(PropertyContainer src) {
for (Map.Entry<String, @Nullable Object> entry : src.getPropertyMap().entrySet()) {
String name = entry.getKey();
Object entryValue = entry.getValue();
boolean isUnindexedValue = false;
boolean isWrappedValue = false;
boolean indexed = true;
boolean forceIndexedEntityValue = false;
Object valueToAdd = entryValue;
if (entryValue instanceof UnindexedValue) {
isUnindexedValue = true;
indexed = false;
valueToAdd = ((UnindexedValue) entryValue).getValue();
} else if (entryValue instanceof WrappedValue) {
WrappedValue wrappedValue = (WrappedValue) entryValue;
isWrappedValue = true;
indexed = wrappedValue.isIndexed();
forceIndexedEntityValue = wrappedValue.getForceIndexedEmbeddedEntity();
valueToAdd = wrappedValue.getValue();
}
// Clone collections
if (valueToAdd instanceof Collection<?>) {
// Convert all collections to an ArrayList, as that is the representation
// returned from the datastore.
Collection<?> srcColl = (Collection<?>) valueToAdd;
Collection<Object> destColl = new ArrayList<Object>(srcColl.size());
valueToAdd = destColl;
for (Object element : srcColl) {
destColl.add(cloneIfMutable(element));
}
} else {
valueToAdd = cloneIfMutable(valueToAdd);
}
if (isUnindexedValue) {
valueToAdd = new UnindexedValue(valueToAdd);
} else if (isWrappedValue) {
valueToAdd = new WrappedValueImpl(valueToAdd, indexed, forceIndexedEntityValue);
}
// Put the copy in the map
getPropertyMap().put(name, valueToAdd);
}
}
use of com.google.appengine.api.datastore.Entity.UnindexedValue in project appengine-java-standard by GoogleCloudPlatform.
the class DataTypeTranslator method addPropertyToMap.
private static void addPropertyToMap(Property property, boolean indexed, Map<String, @Nullable Object> map) {
String name = property.getName();
if (property.getMeaningEnum() == Meaning.EMPTY_LIST) {
// Read an empty list, but user hasn't enabled empty list support. In order to be
// backward compatible, return null because thats what they used to get for empty lists.
Object emptyListValue = DatastoreServiceConfig.getEmptyListSupport() ? new ArrayList<Object>() : null;
map.put(name, wrapIfUnindexed(indexed, emptyListValue));
} else {
Object value = getPropertyValue(property);
if (property.isMultiple()) {
@SuppressWarnings({ "unchecked" }) List<Object> resultList = (List<Object>) PropertyContainer.unwrapValue(map.get(name));
if (resultList == null) {
resultList = new ArrayList<Object>();
map.put(name, indexed ? resultList : new UnindexedValue(resultList));
}
if (indexed && value instanceof EmbeddedEntity) {
map.put(name, new WrappedValueImpl(resultList, true, true));
}
resultList.add(value);
} else {
if (indexed && value instanceof EmbeddedEntity) {
value = new WrappedValueImpl(value, true, true);
} else if (!indexed) {
value = new UnindexedValue(value);
}
map.put(name, value);
}
}
}
use of com.google.appengine.api.datastore.Entity.UnindexedValue in project appengine-java-standard by GoogleCloudPlatform.
the class PropertyContainer method setUnindexedProperty.
/**
* Like {@code #setProperty}, but doesn't index the property in the built-in single property
* indexes or the user-defined composite indexes.
*
* @param value may be one of the supported datatypes, or a heterogeneous {@code Collection} of
* one of the supported datatypes.
* <p>Overrides any existing value for this property, whether indexed or unindexed.
* @throws IllegalArgumentException If the value is not of a type that the data store supports.
* @see #setProperty
*/
public void setUnindexedProperty(String propertyName, Object value) {
DataTypeUtils.checkSupportedValue(propertyName, value);
getPropertyMap().put(propertyName, new UnindexedValue(value));
}
Aggregations