Moved special id-property handling into PersistentProperty interface.
The PersistentProperty interface now has a isIdPropertyMethod(). Subclasses might alter it to support further id property detection mechanisms. Added missing import in BasicPersistentProperty.
This commit is contained in:
@@ -80,16 +80,6 @@ public class BasicMappingConfigurationBuilder implements MappingConfigurationBui
|
||||
return new BasicPersistentProperty(field.getName(), field.getType(), field, descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> PersistentProperty<?> getIdProperty(Class<T> type) throws MappingConfigurationException {
|
||||
for (Field field : type.getDeclaredFields()) {
|
||||
if (isIdField(field)) {
|
||||
return createPersistentProperty(field, null);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
public <T> PreferredConstructor<T> getPreferredConstructor(Class<T> type) throws MappingConfigurationException {
|
||||
@@ -189,8 +179,4 @@ public class BasicMappingConfigurationBuilder implements MappingConfigurationBui
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isIdField(Field field) {
|
||||
return field.isAnnotationPresent(Id.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,10 @@ public class BasicMappingContext implements MappingContext, InitializingBean {
|
||||
Association association = builder.createAssociation(property);
|
||||
entity.addAssociation(association);
|
||||
}
|
||||
|
||||
if (property.isIdProperty()) {
|
||||
entity.setIdProperty(property);
|
||||
}
|
||||
}
|
||||
} catch (MappingConfigurationException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
@@ -115,8 +119,6 @@ public class BasicMappingContext implements MappingContext, InitializingBean {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
entity.setIdProperty(builder.getIdProperty(type));
|
||||
entity.setPreferredConstructor(builder.getPreferredConstructor(type));
|
||||
|
||||
// Inform listeners
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.mapping;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mapping.model.Association;
|
||||
import org.springframework.data.mapping.model.PersistentEntity;
|
||||
@@ -146,4 +147,9 @@ public class BasicPersistentProperty<T> implements PersistentProperty<T> {
|
||||
}
|
||||
return type.getComponentType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIdProperty() {
|
||||
return field.isAnnotationPresent(Id.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ public interface MappingConfigurationBuilder {
|
||||
|
||||
PersistentProperty<?> createPersistentProperty(Field field, PropertyDescriptor descriptor) throws MappingConfigurationException;
|
||||
|
||||
<T> PersistentProperty<?> getIdProperty(Class<T> clazz) throws MappingConfigurationException;
|
||||
|
||||
<T> PreferredConstructor<?> getPreferredConstructor(Class<T> clazz) throws MappingConfigurationException;
|
||||
|
||||
boolean isAssociation(Field field, PropertyDescriptor descriptor) throws MappingConfigurationException;
|
||||
|
||||
@@ -49,4 +49,5 @@ public interface PersistentProperty<T> {
|
||||
|
||||
Class<?> getComponentType();
|
||||
|
||||
boolean isIdProperty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user