Skip to content

Rename Embedded annotation to Unwrapped. #3604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-3600-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-3600-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-3600-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-3600-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
import org.springframework.data.mongodb.CodecRegistryProvider;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.mapping.Embedded;
import org.springframework.data.mongodb.core.mapping.Embedded.OnEmpty;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.mongodb.core.mapping.Unwrapped;
import org.springframework.data.mongodb.core.mapping.Unwrapped.OnEmpty;
import org.springframework.data.mongodb.core.mapping.event.AfterConvertCallback;
import org.springframework.data.mongodb.core.mapping.event.AfterConvertEvent;
import org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent;
Expand Down Expand Up @@ -447,10 +447,10 @@ private void readProperties(ConversionContext context, MongoPersistentEntity<?>
continue;
}

if (prop.isEmbedded()) {
if (prop.isUnwrapped()) {

accessor.setProperty(prop,
readEmbedded(context, documentAccessor, prop, mappingContext.getRequiredPersistentEntity(prop)));
readUnwrapped(context, documentAccessor, prop, mappingContext.getRequiredPersistentEntity(prop)));
continue;
}

Expand Down Expand Up @@ -500,17 +500,17 @@ private void readAssociation(Association<MongoPersistentProperty> association, P
}

@Nullable
private Object readEmbedded(ConversionContext context, DocumentAccessor documentAccessor,
private Object readUnwrapped(ConversionContext context, DocumentAccessor documentAccessor,
MongoPersistentProperty prop,
MongoPersistentEntity<?> embeddedEntity) {
MongoPersistentEntity<?> unwrappedEntity) {

if (prop.findAnnotation(Embedded.class).onEmpty().equals(OnEmpty.USE_EMPTY)) {
return read(context, embeddedEntity, (Document) documentAccessor.getDocument());
if (prop.findAnnotation(Unwrapped.class).onEmpty().equals(OnEmpty.USE_EMPTY)) {
return read(context, unwrappedEntity, (Document) documentAccessor.getDocument());
}

for (MongoPersistentProperty persistentProperty : embeddedEntity) {
for (MongoPersistentProperty persistentProperty : unwrappedEntity) {
if (documentAccessor.hasValue(persistentProperty)) {
return read(context, embeddedEntity, (Document) documentAccessor.getDocument());
return read(context, unwrappedEntity, (Document) documentAccessor.getDocument());
}
}
return null;
Expand Down Expand Up @@ -680,7 +680,7 @@ protected void writePropertyInternal(@Nullable Object obj, DocumentAccessor acce
TypeInformation<?> valueType = ClassTypeInformation.from(obj.getClass());
TypeInformation<?> type = prop.getTypeInformation();

if (prop.isEmbedded()) {
if (prop.isUnwrapped()) {

Document target = new Document();
writeInternal(obj, target, mappingContext.getPersistentEntity(prop));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Document getMappedObject(Bson query, @Nullable MongoPersistentEntity<?> e
Field field = createPropertyField(entity, key, mappingContext);

// TODO: move to dedicated method
if (field.getProperty() != null && field.getProperty().isEmbedded()) {
if (field.getProperty() != null && field.getProperty().isUnwrapped()) {

Object theNestedObject = BsonUtils.get(query, key);
Document mappedValue = (Document) getMappedValue(field, theNestedObject);
Expand Down Expand Up @@ -189,13 +189,13 @@ public Document getMappedSort(Document sortObject, @Nullable MongoPersistentEnti
return new Document();
}

sortObject = filterEmbeddedObjects(sortObject, entity);
sortObject = filterUnwrappedObjects(sortObject, entity);

Document mappedSort = new Document();
for (Map.Entry<String, Object> entry : BsonUtils.asMap(sortObject).entrySet()) {

Field field = createPropertyField(entity, entry.getKey(), mappingContext);
if (field.getProperty() != null && field.getProperty().isEmbedded()) {
if (field.getProperty() != null && field.getProperty().isUnwrapped()) {
continue;
}

Expand All @@ -219,7 +219,7 @@ public Document getMappedFields(Document fieldsObject, @Nullable MongoPersistent

Assert.notNull(fieldsObject, "FieldsObject must not be null!");

fieldsObject = filterEmbeddedObjects(fieldsObject, entity);
fieldsObject = filterUnwrappedObjects(fieldsObject, entity);

Document mappedFields = getMappedObject(fieldsObject, entity);
mapMetaAttributes(mappedFields, entity, MetaMapping.FORCE);
Expand All @@ -241,7 +241,7 @@ private void mapMetaAttributes(Document source, @Nullable MongoPersistentEntity<
}
}

private Document filterEmbeddedObjects(Document fieldsObject, @Nullable MongoPersistentEntity<?> entity) {
private Document filterUnwrappedObjects(Document fieldsObject, @Nullable MongoPersistentEntity<?> entity) {

if (fieldsObject.isEmpty() || entity == null) {
return fieldsObject;
Expand All @@ -258,13 +258,13 @@ private Document filterEmbeddedObjects(Document fieldsObject, @Nullable MongoPer
.getPersistentPropertyPath(path);
MongoPersistentProperty property = mappingContext.getPersistentPropertyPath(path).getRequiredLeafProperty();

if (property.isEmbedded() && property.isEntity()) {
if (property.isUnwrapped() && property.isEntity()) {

MongoPersistentEntity<?> embeddedEntity = mappingContext.getRequiredPersistentEntity(property);
MongoPersistentEntity<?> unwrappedEntity = mappingContext.getRequiredPersistentEntity(property);

for (MongoPersistentProperty embedded : embeddedEntity) {
for (MongoPersistentProperty unwrappedProperty : unwrappedEntity) {

DotPath dotPath = DotPath.from(persistentPropertyPath.toDotPath()).append(embedded.getName());
DotPath dotPath = DotPath.from(persistentPropertyPath.toDotPath()).append(unwrappedProperty.getName());
target.put(dotPath.toString(), field.getValue());
}

Expand Down Expand Up @@ -564,7 +564,7 @@ protected Object convertSimpleOrDocument(Object source, @Nullable MongoPersisten
@Nullable
protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) {

if (entity != null && entity.isEmbedded()) {
if (entity != null && entity.isUnwrapped()) {
return converter.convertToMongoType(source, entity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static boolean isUpdateObject(@Nullable Document updateObj) {
@Override
protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersistentEntity<?> entity) {

if(entity != null && entity.isEmbedded()) {
if(entity != null && entity.isUnwrapped()) {
return converter.convertToMongoType(source, entity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void potentiallyAddIndexForProperty(MongoPersistentEntity<?> root, Mongo
try {
if (persistentProperty.isEntity()) {
indexes.addAll(resolveIndexForEntity(mappingContext.getPersistentEntity(persistentProperty),
persistentProperty.isEmbedded() ? "" : persistentProperty.getFieldName(), Path.of(persistentProperty),
persistentProperty.isUnwrapped() ? "" : persistentProperty.getFieldName(), Path.of(persistentProperty),
root.getCollection(), guard));
}

Expand Down Expand Up @@ -187,7 +187,7 @@ private void guardAndPotentiallyAddIndexForProperty(MongoPersistentProperty pers

DotPath propertyDotPath = DotPath.from(dotPath);

if (!persistentProperty.isEmbedded()) {
if (!persistentProperty.isUnwrapped()) {
propertyDotPath = propertyDotPath.append(persistentProperty.getFieldName());
}

Expand Down Expand Up @@ -216,11 +216,11 @@ private List<IndexDefinitionHolder> createIndexDefinitionHolderForProperty(Strin

List<IndexDefinitionHolder> indices = new ArrayList<>(2);

if (persistentProperty.isEmbedded() && (persistentProperty.isAnnotationPresent(Indexed.class)
if (persistentProperty.isUnwrapped() && (persistentProperty.isAnnotationPresent(Indexed.class)
|| persistentProperty.isAnnotationPresent(HashIndexed.class)
|| persistentProperty.isAnnotationPresent(GeoSpatialIndexed.class))) {
throw new InvalidDataAccessApiUsageException(
String.format("Index annotation not allowed on embedded object for path '%s'.", dotPath));
String.format("Index annotation not allowed on unwrapped object for path '%s'.", dotPath));
}

if (persistentProperty.isAnnotationPresent(Indexed.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ public MongoPersistentEntity<?> getPersistentEntity(MongoPersistentProperty pers

MongoPersistentEntity<?> entity = super.getPersistentEntity(persistentProperty);

if(entity == null || !persistentProperty.isEmbedded()) {
if(entity == null || !persistentProperty.isUnwrapped()) {
return entity;
}

return new EmbeddedMongoPersistentEntity<>(entity, new EmbeddedEntityContext(persistentProperty));
return new UnwrappedMongoPersistentEntity<>(entity, new UnwrapEntityContext(persistentProperty));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ default boolean isSharded() {
}

/**
* @return {@literal true} if the entity should be embedded.
* @return {@literal true} if the entity should be unwrapped.
* @since 3.2
*/
default boolean isEmbedded() {
default boolean isUnwrapped() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ default boolean hasExplicitWriteTarget() {
}

/**
* @return {@literal true} if the property should be embedded.
* @return {@literal true} if the property should be unwrapped.
* @since 3.2
*/
default boolean isEmbedded() {
return isEntity() && isAnnotationPresent(Embedded.class);
default boolean isUnwrapped() {
return isEntity() && isAnnotationPresent(Unwrapped.class);
}

/**
Expand All @@ -145,7 +145,7 @@ enum PropertyToFieldNameConverter implements Converter<MongoPersistentProperty,
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
*/
public String convert(MongoPersistentProperty source) {
if (!source.isEmbedded()) {
if (!source.isUnwrapped()) {
return source.getFieldName();
}
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* @author Christoph Strobl
* @since 3.2
*/
class EmbeddedEntityContext {
class UnwrapEntityContext {

private final MongoPersistentProperty property;

public EmbeddedEntityContext(MongoPersistentProperty property) {
public UnwrapEntityContext(MongoPersistentProperty property) {
this.property = property;
}

Expand Down
Loading