Skip to content

Commit

Permalink
Add support for factory methods.
Browse files Browse the repository at this point in the history
Simply annotate a static factory method on your entity class with @PersistenceCreator.

Closes #1312
  • Loading branch information
schauder committed Oct 5, 2022
1 parent f919ab9 commit cd28784
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PersistentPropertyPathAccessor;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
Expand Down Expand Up @@ -338,11 +337,11 @@ private <R> R doReadProjection(ConversionContext context, CassandraValueProvider
CassandraValueProvider valueProviderToUse = new TranslatingCassandraValueProvider(propertyTranslator,
valueProvider);

PreferredConstructor<?, CassandraPersistentProperty> persistenceConstructor = mappedEntity
.getPersistenceConstructor();
InstanceCreatorMetadata<CassandraPersistentProperty> persistenceCreator = mappedEntity
.getInstanceCreatorMetadata();

ParameterValueProvider<CassandraPersistentProperty> provider;
if (persistenceConstructor != null && persistenceConstructor.hasParameters()) {
if (persistenceCreator != null && persistenceCreator.hasParameters()) {
SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(valueProviderToUse.getSource(),
spELContext);
ParameterValueProvider<CassandraPersistentProperty> parameterValueProvider = newParameterValueProvider(context,
Expand Down Expand Up @@ -508,10 +507,10 @@ private static Class<?> getRawSourceType(CassandraValueProvider valueProvider) {
private <S> S doReadEntity(ConversionContext context, CassandraValueProvider valueProvider,
CassandraPersistentEntity<S> entity) {

PreferredConstructor<S, CassandraPersistentProperty> persistenceConstructor = entity.getPersistenceConstructor();
InstanceCreatorMetadata<CassandraPersistentProperty> persistenceCreator = entity.getInstanceCreatorMetadata();
ParameterValueProvider<CassandraPersistentProperty> provider;

if (persistenceConstructor != null && persistenceConstructor.hasParameters()) {
if (persistenceCreator != null && persistenceCreator.hasParameters()) {
SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(valueProvider.getSource(), spELContext);
ParameterValueProvider<CassandraPersistentProperty> parameterValueProvider = newParameterValueProvider(context,
entity, valueProvider);
Expand Down

0 comments on commit cd28784

Please sign in to comment.