List of usage examples for org.springframework.data.mapping PersistentPropertyAccessor setProperty
default void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>> path, @Nullable Object value)
From source file:com.frank.search.solr.core.convert.MappingSolrConverter.java
private <S extends Object> S read(final SolrPersistentEntity<S> entity, final Map<String, ?> source, Object parent) {//from w w w. j a va2s. c o m ParameterValueProvider<SolrPersistentProperty> parameterValueProvider = getParameterValueProvider(entity, source, parent); EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final S instance = instantiator.createInstance(entity, parameterValueProvider); final PersistentPropertyAccessor accessor = new ConvertingPropertyAccessor( entity.getPropertyAccessor(instance), getConversionService()); entity.doWithProperties(new PropertyHandler<SolrPersistentProperty>() { @Override public void doWithPersistentProperty(SolrPersistentProperty persistentProperty) { if (entity.isConstructorArgument(persistentProperty)) { return; } Object o = getValue(persistentProperty, source, instance); if (o != null) { accessor.setProperty(persistentProperty, o); } } }); return instance; }
From source file:io.twipple.springframework.data.clusterpoint.convert.DefaultClusterpointEntityConverter.java
/** * Sets the property to the given value. * This method attempts to apply custom conversions if such exist. * * @param propertyAccessor the property accessor. Must not be {@literal null}. * @param property the property being set. Must not be {@literal null}. * @param newValue the value to set. *//*from ww w . j a v a2 s. com*/ protected void setPropertyInternal(@NotNull PersistentPropertyAccessor propertyAccessor, @NotNull ClusterpointPersistentProperty property, Object newValue) { Assert.notNull(propertyAccessor); Assert.notNull(property); if (newValue != null) { Class<?> valueType = newValue.getClass(); Class<?> propertyType = property.getType(); if (conversions.hasCustomReadTarget(valueType, propertyType)) { newValue = conversionService.convert(newValue, propertyType); } } propertyAccessor.setProperty(property, newValue); }
From source file:org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate.java
private void resolveChildEntity(Object entity, Set<String> includeProperties) { SpannerPersistentEntity spannerPersistentEntity = this.mappingContext .getPersistentEntity(entity.getClass()); PersistentPropertyAccessor accessor = spannerPersistentEntity.getPropertyAccessor(entity); spannerPersistentEntity.doWithInterleavedProperties( (PropertyHandler<SpannerPersistentProperty>) (spannerPersistentProperty) -> { if (includeProperties != null && !includeProperties.contains(spannerPersistentEntity.getName())) { return; }//from w w w . j a v a 2 s .c om Class childType = spannerPersistentProperty.getColumnInnerType(); SpannerPersistentEntity childPersistentEntity = this.mappingContext .getPersistentEntity(childType); Supplier<List> getChildrenEntitiesFunc = () -> queryAndResolveChildren(childType, SpannerStatementQueryExecutor.getChildrenRowsQuery( this.spannerSchemaUtils.getKey(entity), childPersistentEntity, this.spannerEntityProcessor.getWriteConverter()), null); accessor.setProperty(spannerPersistentProperty, spannerPersistentProperty.isLazyInterleaved() ? ConversionUtils.wrapSimpleLazyProxy(getChildrenEntitiesFunc, List.class) : getChildrenEntitiesFunc.get()); }); }
From source file:org.springframework.data.gemfire.mapping.MappingPdxSerializer.java
@Override public Object fromData(final Class<?> type, final PdxReader reader) { final GemfirePersistentEntity<?> entity = getPersistentEntity(type); final Object instance = getInstantiatorFor(entity).createInstance(entity, new PersistentEntityParameterValueProvider<GemfirePersistentProperty>(entity, new GemfirePropertyValueProvider(reader), null)); final PersistentPropertyAccessor accessor = new ConvertingPropertyAccessor( entity.getPropertyAccessor(instance), getConversionService()); entity.doWithProperties(new PropertyHandler<GemfirePersistentProperty>() { public void doWithPersistentProperty(GemfirePersistentProperty persistentProperty) { if (!entity.isConstructorArgument(persistentProperty)) { PdxSerializer customSerializer = getCustomSerializer(persistentProperty.getType()); Object value = null; try { if (log.isDebugEnabled()) { log.debug(String.format( "setting property [%1$s] for entity [%2$s] of type [%3$s] from PDX%4$s", persistentProperty.getName(), instance, type, (customSerializer != null ? String.format(" using custom PdxSerializer [%1$s]", customSerializer) : ""))); }/*w w w . j a v a 2 s . c o m*/ value = (customSerializer != null ? customSerializer.fromData(persistentProperty.getType(), reader) : reader.readField(persistentProperty.getName())); if (log.isDebugEnabled()) { log.debug(String.format("with value [%1$s]", value)); } accessor.setProperty(persistentProperty, value); } catch (Exception e) { throw new MappingException(String.format( "while setting value [%1$s] of property [%2$s] for entity of type [%3$s] from PDX%4$s", value, persistentProperty.getName(), type, (customSerializer != null ? String.format(" using custom PdxSerializer [%14s]", customSerializer) : "")), e); } } } }); return accessor.getBean(); }
From source file:org.springframework.data.solr.core.convert.MappingSolrConverter.java
private <S extends Object> S read(final SolrPersistentEntity<S> entity, final Map<String, ?> source, Object parent) {/* w w w .j a va2s . com*/ ParameterValueProvider<SolrPersistentProperty> parameterValueProvider = getParameterValueProvider(entity, source, parent); EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final S instance = instantiator.createInstance(entity, parameterValueProvider); final PersistentPropertyAccessor accessor = new ConvertingPropertyAccessor( entity.getPropertyAccessor(instance), getConversionService()); entity.doWithProperties(new PropertyHandler<SolrPersistentProperty>() { @Override public void doWithPersistentProperty(SolrPersistentProperty persistentProperty) { if (entity.isConstructorArgument(persistentProperty)) { return; } Object o = getValue(persistentProperty, source, instance); if (o != null) { accessor.setProperty(persistentProperty, o); } } }); return instance; }