/** * 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)); }
/** * Registers {@link EntityInstantiators} to customize entity instantiation. * * @param instantiators */ public void setInstantiators(@Nullable EntityInstantiators instantiators) { this.instantiators = instantiators == null ? new EntityInstantiators() : instantiators; }
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; }
/** * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractReactiveMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations operations) { Assert.notNull(method, "MongoQueryMethod must not be null!"); Assert.notNull(operations, "ReactiveMongoOperations must not be null!"); this.method = method; this.operations = operations; this.instantiators = new EntityInstantiators(); MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.findOperationWithProjection = operations.query(type); }
public EntityInstantiator getInstantiatorFor(PersistentEntity<?, ?> entity) { return instantiators.getInstantiatorFor(entity); }
/** * Creates new {@link MappingRedisConverter} and defaults {@link RedisMappingContext} when {@literal null}. * * @param mappingContext can be {@literal null}. * @param indexResolver can be {@literal null}. * @param referenceResolver can be {@literal null}. * @param typeMapper can be {@literal null}. * @since 2.1 */ public MappingRedisConverter(@Nullable RedisMappingContext mappingContext, @Nullable IndexResolver indexResolver, @Nullable ReferenceResolver referenceResolver, @Nullable RedisTypeMapper typeMapper) { this.mappingContext = mappingContext != null ? mappingContext : new RedisMappingContext(); this.entityInstantiators = new EntityInstantiators(); this.conversionService = new DefaultConversionService(); this.customConversions = new RedisCustomConversions(); this.typeMapper = typeMapper != null ? typeMapper : new DefaultRedisTypeMapper(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, this.mappingContext); this.indexResolver = indexResolver != null ? indexResolver : new PathIndexResolver(this.mappingContext); this.referenceResolver = referenceResolver; }
EntityInstantiator instantiator = entityInstantiators.getInstantiatorFor(entity);
/** * Registers {@link EntityInstantiators} to customize entity instantiation. * * @param instantiators */ public void setInstantiators(@Nullable EntityInstantiators instantiators) { this.instantiators = instantiators == null ? new EntityInstantiators() : instantiators; }
/** * 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)); }
/** * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractReactiveMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations operations) { Assert.notNull(method, "MongoQueryMethod must not be null!"); Assert.notNull(operations, "ReactiveMongoOperations must not be null!"); this.method = method; this.operations = operations; this.instantiators = new EntityInstantiators(); MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.findOperationWithProjection = operations.query(type); }
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; }
ConverterAwareMappingSpannerEntityReader(SpannerMappingContext spannerMappingContext, SpannerReadConverter spannerReadConverter) { this.spannerMappingContext = spannerMappingContext; this.instantiators = new EntityInstantiators(); this.converter = spannerReadConverter; }
public EntityInstantiator getInstantiatorFor(PersistentEntity<?, ?> entity) { return instantiators.getInstantiatorFor(entity); }
ConverterAwareMappingSpannerEntityReader(SpannerMappingContext spannerMappingContext, SpannerReadConverter spannerReadConverter) { this.spannerMappingContext = spannerMappingContext; this.instantiators = new EntityInstantiators(); this.converter = spannerReadConverter; }
/** * 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); }
/** * Creates a new {@link AbstractR2dbcQuery} from the given {@link R2dbcQueryMethod} and {@link DatabaseClient}. * * @param method must not be {@literal null}. * @param databaseClient must not be {@literal null}. * @param converter must not be {@literal null}. */ public AbstractR2dbcQuery(R2dbcQueryMethod method, DatabaseClient databaseClient, MappingR2dbcConverter converter) { Assert.notNull(method, "R2dbcQueryMethod must not be null!"); Assert.notNull(databaseClient, "DatabaseClient must not be null!"); Assert.notNull(converter, "MappingR2dbcConverter must not be null!"); this.method = method; this.databaseClient = databaseClient; this.converter = converter; this.instantiators = new EntityInstantiators(); }
/** * 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); }
/** * Creates a new {@link AbstractR2dbcQuery} from the given {@link R2dbcQueryMethod} and {@link DatabaseClient}. * * @param method must not be {@literal null}. * @param databaseClient must not be {@literal null}. * @param converter must not be {@literal null}. */ public AbstractR2dbcQuery(R2dbcQueryMethod method, DatabaseClient databaseClient, MappingR2dbcConverter converter) { Assert.notNull(method, "R2dbcQueryMethod must not be null!"); Assert.notNull(databaseClient, "DatabaseClient must not be null!"); Assert.notNull(converter, "MappingR2dbcConverter must not be null!"); this.method = method; this.databaseClient = databaseClient; this.converter = converter; this.instantiators = new EntityInstantiators(); }
/** * 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 BasicRelationalConverter} given {@link MappingContext} and {@link CustomConversions}. * * @param context must not be {@literal null}. * @param conversions must not be {@literal null}. */ public BasicRelationalConverter( MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, CustomConversions conversions) { this(context, conversions, new DefaultConversionService(), new EntityInstantiators()); }