org.springframework.data.mapping.model.PropertyValueProvider Java Examples
The following examples show how to use
org.springframework.data.mapping.model.PropertyValueProvider.
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: TypicalEntityReaderBenchmark.java From spring-data-dev-tools with Apache License 2.0 | 6 votes |
private void readProperties(Map<String, Object> data, MyPersistentEntity<?> persistentEntity, PropertyValueProvider<MyPersistentProperty> valueProvider, PersistentPropertyAccessor<?> accessor) { for (MyPersistentProperty prop : persistentEntity) { if (prop.isAssociation() && !persistentEntity.isConstructorArgument(prop)) { continue; } // We skip the id property since it was already set if (persistentEntity.isIdProperty(prop)) { continue; } if (persistentEntity.isConstructorArgument(prop) || !data.containsKey(persistentEntity.getName())) { continue; } accessor.setProperty(prop, valueProvider.getPropertyValue(prop)); } }
Example #2
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 5 votes |
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: TypicalEntityReaderBenchmark.java From spring-data-dev-tools with Apache License 2.0 | 4 votes |
/** * Typical code used to read entities in {@link org.springframework.data.convert.EntityReader}. * * @param data * @param classToRead * @param queryCustomConversions {@literal true} to call {@link CustomConversions#hasCustomReadTarget(Class, Class)}. * @return */ @SuppressWarnings("unchecked") private Object read(Map<String, Object> data, Class<?> classToRead, boolean queryCustomConversions) { if (queryCustomConversions) { customConversions.hasCustomReadTarget(Map.class, classToRead); } MyPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(classToRead); PreferredConstructor<?, MyPersistentProperty> constructor = persistentEntity.getPersistenceConstructor(); ParameterValueProvider<MyPersistentProperty> provider = constructor.isNoArgConstructor() // ? NONE // : new ParameterValueProvider<MyPersistentProperty>() { @Override public <T> T getParameterValue(Parameter<T, MyPersistentProperty> parameter) { return (T) getValue(data, parameter.getName(), parameter.getType().getType(), queryCustomConversions); } }; EntityInstantiator instantiator = instantiators.getInstantiatorFor(persistentEntity); Object instance = instantiator.createInstance(persistentEntity, provider); if (!persistentEntity.requiresPropertyPopulation()) { return instance; } PropertyValueProvider<MyPersistentProperty> valueProvider = new PropertyValueProvider<MyPersistentProperty>() { @Override public <T> T getPropertyValue(MyPersistentProperty property) { return (T) getValue(data, property.getName(), property.getType(), queryCustomConversions); } }; PersistentPropertyAccessor<?> accessor = new ConvertingPropertyAccessor<>( persistentEntity.getPropertyAccessor(instance), conversionService); readProperties(data, persistentEntity, valueProvider, accessor); return accessor.getBean(); }