@SuppressWarnings("unchecked") public <T> T getPropertyValue(String fieldName, EmbeddedType embeddedType, TypeInformation targetTypeInformation) { if (!this.entity.contains(fieldName)) { return null; } try { return this.conversion.convertOnRead(this.entity.getValue(fieldName).get(), embeddedType, targetTypeInformation); } catch (ConversionException | DatastoreDataException ex) { throw new DatastoreDataException("Unable to read property " + fieldName, ex); } } }
@SuppressWarnings("unchecked") public <T> T getPropertyValue(String fieldName, EmbeddedType embeddedType, TypeInformation targetTypeInformation) { if (!this.entity.contains(fieldName)) { return null; } try { return this.conversion.convertOnRead(this.entity.getValue(fieldName).get(), embeddedType, targetTypeInformation); } catch (ConversionException | DatastoreDataException ex) { throw new DatastoreDataException("Unable to read property " + fieldName, ex); } } }
private Object findReferenced(BaseEntity entity, DatastorePersistentProperty referencePersistentProperty) { String fieldName = referencePersistentProperty.getFieldName(); try { Object referenced; if (!entity.contains(fieldName)) { referenced = null; } else if (referencePersistentProperty.isCollectionLike()) { Class referencedType = referencePersistentProperty.getComponentType(); List<Value<Key>> keyValues = entity.getList(fieldName); referenced = this.datastoreEntityConverter.getConversions() .convertOnRead( findAllById( keyValues.stream().map(Value::get).collect(Collectors.toList()), referencedType), referencePersistentProperty.getType(), referencedType); } else { referenced = findById(entity.getKey(fieldName), referencePersistentProperty.getType()); } return referenced; } catch (ClassCastException ex) { throw new DatastoreDataException( "Error loading reference property " + fieldName + "." + "Reference properties must be stored as Keys or lists of Keys" + " in Cloud Datastore for singular or multiple references, respectively."); } }
private Object findReferenced(BaseEntity entity, DatastorePersistentProperty referencePersistentProperty) { String fieldName = referencePersistentProperty.getFieldName(); try { Object referenced; if (!entity.contains(fieldName)) { referenced = null; } else if (referencePersistentProperty.isCollectionLike()) { Class referencedType = referencePersistentProperty.getComponentType(); List<Value<Key>> keyValues = entity.getList(fieldName); referenced = this.datastoreEntityConverter.getConversions() .convertOnRead( findAllById( keyValues.stream().map(Value::get).collect(Collectors.toList()), referencedType), referencePersistentProperty.getType(), referencedType); } else { referenced = findById(entity.getKey(fieldName), referencePersistentProperty.getType()); } return referenced; } catch (ClassCastException ex) { throw new DatastoreDataException( "Error loading reference property " + fieldName + "." + "Reference properties must be stored as Keys or lists of Keys" + " in Cloud Datastore for singular or multiple references, respectively."); } }
/** * Unmarshals the property with the given metadata and sets the unmarshalled value on the given * <code>target</code> object. * * @param propertyMetadata * the metadata of the property * @param target * the target object to set the unmarshalled value on * @param nativeEntity * the native entity containing the source property * @throws Throwable * propagated */ private static void unmarshalProperty(PropertyMetadata propertyMetadata, Object target, BaseEntity<?> nativeEntity) throws Throwable { // The datastore may not have every property that the entity class has // defined. For example, if we are running a projection query or if the // entity class added a new field without updating existing data...So // make sure there is a property or else, we get an exception from the // datastore. if (nativeEntity.contains(propertyMetadata.getMappedName())) { Value<?> datastoreValue = nativeEntity.getValue(propertyMetadata.getMappedName()); Object entityValue = propertyMetadata.getMapper().toModel(datastoreValue); MethodHandle writeMethod = propertyMetadata.getWriteMethod(); writeMethod.invoke(target, entityValue); } }
FullEntity<?> nativeEmbeddedEntity = null; String propertyName = embeddedMetadata.getMappedName(); if (nativeEntity.contains(propertyName)) { Value<?> nativeValue = nativeEntity.getValue(propertyName); if (nativeValue instanceof NullValue) {