DATACMNS-1101 - Remove Alias.ofOptional(…).
Refactored type alias detection invocation in BasicPersistentEntity into separate method and avoid the factory method Alias.ofOptional(…) so that it can be removed.
This commit is contained in:
@@ -19,8 +19,6 @@ import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -71,20 +69,6 @@ public class Alias {
|
||||
return alias == null ? NONE : new Alias(alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link Alias} from an {@link Optional}. Returns an {@link Alias} object of the optional value is present,
|
||||
* otherwise {@link #empty()}.
|
||||
*
|
||||
* @param optional must not be {@literal null}.
|
||||
* @return the {@link Alias} for {@code alias} or {@link #empty()} if the given alias was {@literal null}.
|
||||
*/
|
||||
public static Alias ofOptional(Optional<? extends Object> optional) {
|
||||
|
||||
Assert.notNull(optional, "Optional must not be null!");
|
||||
|
||||
return optional.map(Alias::new).orElse(NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty {@code Alias} instance. No value is present for this Alias.
|
||||
*
|
||||
|
||||
@@ -32,7 +32,18 @@ import java.util.TreeSet;
|
||||
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.data.annotation.TypeAlias;
|
||||
import org.springframework.data.mapping.*;
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.IdentifierAccessor;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.data.mapping.PreferredConstructor;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.SimpleAssociationHandler;
|
||||
import org.springframework.data.mapping.SimplePropertyHandler;
|
||||
import org.springframework.data.mapping.TargetAwareIdentifierAccessor;
|
||||
import org.springframework.data.util.Lazy;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -99,11 +110,7 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
this.propertyCache = new HashMap<>();
|
||||
this.annotationCache = new HashMap<>();
|
||||
this.propertyAccessorFactory = BeanWrapperPropertyAccessorFactory.INSTANCE;
|
||||
|
||||
this.typeAlias = Lazy.of(() -> Alias
|
||||
.ofOptional(Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(getType(), TypeAlias.class))//
|
||||
.map(TypeAlias::value)//
|
||||
.filter(StringUtils::hasText)));
|
||||
this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -458,6 +465,22 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
|
||||
return hasIdProperty() ? new IdPropertyIdentifierAccessor(this, bean) : new AbsentIdentifierAccessor(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the {@link Alias} to be used for the given type.
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private static Alias getAliasFromAnnotation(Class<?> type) {
|
||||
|
||||
Optional<String> typeAliasValue = Optional
|
||||
.ofNullable(AnnotatedElementUtils.findMergedAnnotation(type, TypeAlias.class))//
|
||||
.map(TypeAlias::value)//
|
||||
.filter(StringUtils::hasText);
|
||||
|
||||
return Alias.ofNullable(typeAliasValue.orElse(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* A null-object implementation of {@link IdentifierAccessor} to be able to return an accessor for entities that do
|
||||
* not have an identifier property.
|
||||
|
||||
Reference in New Issue
Block a user