org.springframework.data.mapping.model.PersistentEntityParameterValueProvider Java Examples

The following examples show how to use org.springframework.data.mapping.model.PersistentEntityParameterValueProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MappingVaultConverter.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
private ParameterValueProvider<VaultPersistentProperty> getParameterProvider(VaultPersistentEntity<?> entity,
		SecretDocument source) {

	VaultPropertyValueProvider provider = new VaultPropertyValueProvider(source);

	PersistentEntityParameterValueProvider<VaultPersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<>(
			entity, provider, source);

	return new ParameterValueProvider<VaultPersistentProperty>() {

		@Nullable
		@Override
		public <T> T getParameterValue(Parameter<T, VaultPersistentProperty> parameter) {

			Object value = parameterProvider.getParameterValue(parameter);
			return value != null ? readValue(value, parameter.getType()) : null;
		}
	};
}
 
Example #2
Source File: DefaultArangoConverter.java    From spring-data with Apache License 2.0 5 votes vote down vote up
private ParameterValueProvider<ArangoPersistentProperty> getParameterProvider(
	final ArangoPersistentEntity<?> entity,
	final VPackSlice source) {

	final PropertyValueProvider<ArangoPersistentProperty> provider = new ArangoPropertyValueProvider(entity,
			source);
	return new PersistentEntityParameterValueProvider<>(entity, provider, null);
}
 
Example #3
Source File: MappingSolrConverter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private ParameterValueProvider<SolrPersistentProperty> getParameterValueProvider(SolrPersistentEntity<?> entity,
		Map<String, ?> source, Object parent) {

	SolrPropertyValueProvider provider = new SolrPropertyValueProvider(source, parent);
	PersistentEntityParameterValueProvider<SolrPersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<SolrPersistentProperty>(
			entity, provider, parent);

	return parameterProvider;
}
 
Example #4
Source File: DefaultDatastoreEntityConverter.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <R> R read(Class<R> aClass, BaseEntity entity) {
	if (entity == null) {
		return null;
	}
	DatastorePersistentEntity<R> ostensiblePersistentEntity = (DatastorePersistentEntity<R>) this.mappingContext
			.getPersistentEntity(aClass);

	if (ostensiblePersistentEntity == null) {
		throw new DatastoreDataException("Unable to convert Datastore Entity to " + aClass);
	}

	EntityPropertyValueProvider propertyValueProvider = new EntityPropertyValueProvider(entity, this.conversions);

	DatastorePersistentEntity<?> persistentEntity = getDiscriminationPersistentEntity(ostensiblePersistentEntity,
			propertyValueProvider);

	ParameterValueProvider<DatastorePersistentProperty> parameterValueProvider =
			new PersistentEntityParameterValueProvider<>(persistentEntity, propertyValueProvider, null);

	EntityInstantiator instantiator = this.instantiators.getInstantiatorFor(persistentEntity);
	Object instance;
	try {
		instance = instantiator.createInstance(persistentEntity, parameterValueProvider);
		PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(instance);

		persistentEntity.doWithColumnBackedProperties((datastorePersistentProperty) -> {
			// if a property is a constructor argument, it was already computed on instantiation
			if (!persistentEntity.isConstructorArgument(datastorePersistentProperty)) {
				Object value = propertyValueProvider
						.getPropertyValue(datastorePersistentProperty);
				accessor.setProperty(datastorePersistentProperty, value);
			}
		});
	}
	catch (DatastoreDataException ex) {
		throw new DatastoreDataException("Unable to read " + persistentEntity.getName() + " entity", ex);
	}

	return (R) instance;
}
 
Example #5
Source File: ConverterAwareMappingSpannerEntityReader.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a single POJO from a Cloud Spanner row.
 * @param type the type of POJO
 * @param source the Cloud Spanner row
 * @param includeColumns the columns to read. If null then all columns will be read.
 * @param allowMissingColumns if true, then properties with no corresponding column are
 * not mapped. If false, then an exception is thrown.
 * @param <R> the type of the POJO.
 * @return the POJO
 */
@SuppressWarnings("unchecked")
public <R> R read(Class<R> type, Struct source, Set<String> includeColumns,
		boolean allowMissingColumns) {
	boolean readAllColumns = includeColumns == null;
	SpannerPersistentEntity<R> persistentEntity =
			(SpannerPersistentEntity<R>) this.spannerMappingContext.getPersistentEntity(type);

	StructAccessor structAccessor = new StructAccessor(source);

	StructPropertyValueProvider propertyValueProvider = new StructPropertyValueProvider(
			structAccessor,
			this.converter,
			this, allowMissingColumns);

	PreferredConstructor<?, SpannerPersistentProperty> persistenceConstructor = persistentEntity
			.getPersistenceConstructor();

	// @formatter:off
	ParameterValueProvider<SpannerPersistentProperty> parameterValueProvider =
					new PersistentEntityParameterValueProvider<>(persistentEntity, propertyValueProvider, null);
	// @formatter:on

	EntityInstantiator instantiator = this.instantiators.getInstantiatorFor(persistentEntity);
	R instance = instantiator.createInstance(persistentEntity, parameterValueProvider);
	PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(instance);

	persistentEntity.doWithProperties(
			(PropertyHandler<SpannerPersistentProperty>) (spannerPersistentProperty) -> {
				if (spannerPersistentProperty.isEmbedded()) {
					accessor.setProperty(spannerPersistentProperty,
							read(spannerPersistentProperty.getType(), source,
									includeColumns, allowMissingColumns));
				}
				else {
					if (!shouldSkipProperty(structAccessor, spannerPersistentProperty,
							includeColumns, readAllColumns, allowMissingColumns,
							persistenceConstructor)) {

						Object value = propertyValueProvider
								.getPropertyValue(spannerPersistentProperty);
						accessor.setProperty(spannerPersistentProperty, value);
					}
				}
			});

	return instance;
}
 
Example #6
Source File: MappingCrateConverter.java    From spring-data-crate with Apache License 2.0 3 votes vote down vote up
/**
   * Creates a new parameter provider.
   *
   * @param entity the persistent entity.
   * @param source the source document.
   * @param evaluator the SPEL expression evaluator.
   * @param parent the optional parent.
   * @return a new parameter value provider.
   */
private ParameterValueProvider<CratePersistentProperty> getParameterProvider(final CratePersistentEntity<?> entity, final CrateDocument source, 
																			 final DefaultSpELExpressionEvaluator evaluator, final Object parent) {
	
    CratePropertyValueProvider provider = new CratePropertyValueProvider(source, evaluator, parent);
    
    PersistentEntityParameterValueProvider<CratePersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<>(entity, provider, parent);

    return new ConverterAwareSpELExpressionParameterValueProvider(evaluator, conversionService, parameterProvider, parent);
}