/** * Creates a new {@link Converter} to instantiate DTOs. * * @param dtoType must not be {@literal null}. * @param context must not be {@literal null}. * @param instantiators must not be {@literal null}. */ public DtoInstantiatingConverter(Class<?> dtoType, MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> context, EntityInstantiators instantiator) { Assert.notNull(dtoType, "DTO type must not be null!"); Assert.notNull(context, "MappingContext must not be null!"); Assert.notNull(instantiator, "EntityInstantiators must not be null!"); this.targetType = dtoType; this.context = context; this.instantiator = instantiator.getInstantiatorFor(context.getRequiredPersistentEntity(dtoType)); }
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final Document bson, final ObjectPath path) { SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(bson, spELContext); DocumentAccessor documentAccessor = new DocumentAccessor(bson); PreferredConstructor<S, MongoPersistentProperty> persistenceConstructor = entity.getPersistenceConstructor(); ParameterValueProvider<MongoPersistentProperty> provider = persistenceConstructor != null && persistenceConstructor.hasParameters() ? getParameterProvider(entity, documentAccessor, evaluator, path) : NoOpParameterValueProvider.INSTANCE; EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); S instance = instantiator.createInstance(entity, provider); if (entity.requiresPropertyPopulation()) { return populateProperties(entity, documentAccessor, path, evaluator, instance); } return instance; }
public EntityInstantiator getInstantiatorFor(PersistentEntity<?, ?> entity) { return instantiators.getInstantiatorFor(entity); }
EntityInstantiator instantiator = entityInstantiators.getInstantiatorFor(entity);
/** * Creates a new {@link Converter} to instantiate DTOs. * * @param dtoType must not be {@literal null}. * @param context must not be {@literal null}. * @param instantiators must not be {@literal null}. */ public DtoInstantiatingConverter(Class<?> dtoType, MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> context, EntityInstantiators instantiator) { Assert.notNull(dtoType, "DTO type must not be null!"); Assert.notNull(context, "MappingContext must not be null!"); Assert.notNull(instantiator, "EntityInstantiators must not be null!"); this.targetType = dtoType; this.context = context; this.instantiator = instantiator.getInstantiatorFor(context.getRequiredPersistentEntity(dtoType)); }
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final Document bson, final ObjectPath path) { SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(bson, spELContext); DocumentAccessor documentAccessor = new DocumentAccessor(bson); PreferredConstructor<S, MongoPersistentProperty> persistenceConstructor = entity.getPersistenceConstructor(); ParameterValueProvider<MongoPersistentProperty> provider = persistenceConstructor != null && persistenceConstructor.hasParameters() ? getParameterProvider(entity, documentAccessor, evaluator, path) : NoOpParameterValueProvider.INSTANCE; EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); S instance = instantiator.createInstance(entity, provider); if (entity.requiresPropertyPopulation()) { return populateProperties(entity, documentAccessor, path, evaluator, instance); } return instance; }
public EntityInstantiator getInstantiatorFor(PersistentEntity<?, ?> entity) { return instantiators.getInstantiatorFor(entity); }
/** * Looks up and returns an EntityInstantiator to construct and initialize an instance of the object defined * by the given PersistentEntity (meta-data). * * @param entity the PersistentEntity object used to lookup the custom EntityInstantiator. * @return an EntityInstantiator for the given PersistentEntity. * @see org.springframework.data.convert.EntityInstantiator * @see org.springframework.data.mapping.PersistentEntity */ protected EntityInstantiator resolveEntityInstantiator(PersistentEntity entity) { return getEntityInstantiators().getInstantiatorFor(entity); }
/** * Looks up and returns an EntityInstantiator to construct and initialize an instance of the object defined * by the given PersistentEntity (meta-data). * * @param entity the PersistentEntity object used to lookup the custom EntityInstantiator. * @return an EntityInstantiator for the given PersistentEntity. * @see org.springframework.data.convert.EntityInstantiator * @see org.springframework.data.mapping.PersistentEntity */ protected EntityInstantiator resolveEntityInstantiator(PersistentEntity entity) { return getEntityInstantiators().getInstantiatorFor(entity); }
/** * Create a new {@link Converter} to instantiate DTOs. * * @param dtoType must not be {@literal null}. * @param context must not be {@literal null}. * @param instantiators must not be {@literal null}. */ DtoInstantiatingConverter(Class<?> dtoType, MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> context, EntityInstantiators instantiator) { Assert.notNull(dtoType, "DTO type must not be null!"); Assert.notNull(context, "MappingContext must not be null!"); Assert.notNull(instantiator, "EntityInstantiators must not be null!"); this.targetType = dtoType; this.context = context; this.instantiator = instantiator.getInstantiatorFor(context.getRequiredPersistentEntity(dtoType)); }
/** * Creates a new {@link Converter} to instantiate DTOs. * * @param dtoType must not be {@literal null}. * @param context must not be {@literal null}. * @param instantiators must not be {@literal null}. */ public DtoInstantiatingConverter(Class<?> dtoType, MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, EntityInstantiators instantiator) { Assert.notNull(dtoType, "DTO type must not be null!"); Assert.notNull(context, "MappingContext must not be null!"); Assert.notNull(instantiator, "EntityInstantiators must not be null!"); this.targetType = dtoType; this.context = context; this.instantiator = instantiator.getInstantiatorFor(context.getRequiredPersistentEntity(dtoType)); }
/** * Creates a new {@link Converter} to instantiate DTOs. * * @param dtoType must not be {@literal null}. * @param context must not be {@literal null}. * @param instantiators must not be {@literal null}. */ public DtoInstantiatingConverter(Class<?> dtoType, MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, EntityInstantiators instantiator) { Assert.notNull(dtoType, "DTO type must not be null!"); Assert.notNull(context, "MappingContext must not be null!"); Assert.notNull(instantiator, "EntityInstantiators must not be null!"); this.targetType = dtoType; this.context = context; this.instantiator = instantiator.getInstantiatorFor(context.getRequiredPersistentEntity(dtoType)); }
@Override public <T> T createInstance(PersistentEntity<T, RelationalPersistentProperty> entity, Function<Parameter<?, RelationalPersistentProperty>, Object> parameterValueProvider) { return entityInstantiators.getInstantiatorFor(entity) // .createInstance(entity, new ConvertingParameterValueProvider<>(parameterValueProvider)); }
private Object instantiatePrimaryKey(CassandraPersistentEntity<?> entity, CassandraPersistentProperty keyProperty, CassandraValueProvider propertyProvider) { return this.instantiators.getInstantiatorFor(entity).createInstance(entity, newParameterValueProvider(entity, propertyProvider)); }
@Override public <T> T createInstance(PersistentEntity<T, RelationalPersistentProperty> entity, Function<Parameter<?, RelationalPersistentProperty>, Object> parameterValueProvider) { return entityInstantiators.getInstantiatorFor(entity) // .createInstance(entity, new ConvertingParameterValueProvider<>(parameterValueProvider)); }
@Override public <T> T createInstance(PersistentEntity<T, RelationalPersistentProperty> entity, Function<Parameter<?, RelationalPersistentProperty>, Object> parameterValueProvider) { return entityInstantiators.getInstantiatorFor(entity) // .createInstance(entity, new ConvertingParameterValueProvider<>(parameterValueProvider)); }
private ConvertingPropertyAccessor getConvertingPropertyAccessor(AerospikePersistentEntity<?> entity, RecordReadingPropertyValueProvider recordReadingPropertyValueProvider) { EntityInstantiator instantiator = entityInstantiators.getInstantiatorFor(entity); Object instance = instantiator.createInstance(entity, new PersistentEntityParameterValueProvider<>(entity, recordReadingPropertyValueProvider, null)); return new ConvertingPropertyAccessor(entity.getPropertyAccessor(instance), conversionService); }
private <S, V> S doRead(CassandraPersistentEntity<S> entity, V value, Function<SpELExpressionEvaluator, CassandraValueProvider> valueProviderSupplier) { SpELExpressionEvaluator expressionEvaluator = new DefaultSpELExpressionEvaluator(value, this.spELContext); CassandraValueProvider valueProvider = valueProviderSupplier.apply(expressionEvaluator); PersistentEntityParameterValueProvider<CassandraPersistentProperty> parameterValueProvider = newParameterValueProvider( entity, valueProvider); EntityInstantiator instantiator = this.instantiators.getInstantiatorFor(entity); S instance = instantiator.createInstance(entity, parameterValueProvider); ConvertingPropertyAccessor propertyAccessor = newConvertingPropertyAccessor(instance, entity); readProperties(entity, valueProvider, propertyAccessor); return (S) propertyAccessor.getBean(); }
private <S> S read(VaultPersistentEntity<S> entity, SecretDocument source) { ParameterValueProvider<VaultPersistentProperty> provider = getParameterProvider( entity, source); EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); S instance = instantiator.createInstance(entity, provider); PersistentPropertyAccessor accessor = new ConvertingPropertyAccessor( entity.getPropertyAccessor(instance), conversionService); VaultPersistentProperty idProperty = entity.getIdProperty(); SecretDocumentAccessor documentAccessor = new SecretDocumentAccessor(source); // make sure id property is set before all other properties Object idValue; if (entity.requiresPropertyPopulation()) { if (idProperty != null && !entity.isConstructorArgument(idProperty) && documentAccessor.hasValue(idProperty)) { idValue = readIdValue(idProperty, documentAccessor); accessor.setProperty(idProperty, idValue); } VaultPropertyValueProvider valueProvider = new VaultPropertyValueProvider( documentAccessor); readProperties(entity, accessor, idProperty, documentAccessor, valueProvider); } return instance; }
private Object readEntity( final TypeInformation<?> type, final VPackSlice source, final ArangoPersistentEntity<?> entity) { if (!source.isObject()) { throw new MappingException( String.format("Can't read entity type %s from VPack type %s!", type, source.getType())); } final EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final ParameterValueProvider<ArangoPersistentProperty> provider = getParameterProvider(entity, source); final Object instance = instantiator.createInstance(entity, provider); final PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(instance); final String id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; entity.doWithProperties((final ArangoPersistentProperty property) -> { if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); entity.doWithAssociations((final Association<ArangoPersistentProperty> association) -> { final ArangoPersistentProperty property = association.getInverse(); if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); return instance; }