DATACOUCH-27: Mapping @Id field with MappingCouchbaseConverter

Fixed @Id field rewriting from CouchbaseDocument into domain object.
More info can be found at DATACOUCH-27 JIRA issue.
This commit is contained in:
Maciej Zasada
2013-09-18 23:14:28 +02:00
parent b489f09924
commit c62ad426e3
4 changed files with 25 additions and 7 deletions

View File

@@ -82,7 +82,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter
protected <R> R read(TypeInformation<R> type, CouchbaseDocument doc) {
return read(type, doc, null);
}
protected <R> R read(TypeInformation<R> type, final CouchbaseDocument source, Object parent) {
if (source == null) {
@@ -118,13 +118,17 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter
entity.doWithProperties(new PropertyHandler<CouchbasePersistentProperty>() {
public void doWithPersistentProperty(final CouchbasePersistentProperty prop) {
if (!source.containsKey(prop.getFieldName()) || entity.isConstructorArgument(prop)) {
if (!doesPropertyExistInSource(prop) || entity.isConstructorArgument(prop)) {
return;
}
Object obj = prop.isIdProperty() ? source.getId() : getValueInternal(prop, source, evaluator, result);
wrapper.setProperty(prop, obj, useFieldAccessOnly);
}
private boolean doesPropertyExistInSource(CouchbasePersistentProperty property) {
return property.isIdProperty() || source.containsKey(property.getFieldName());
}
});
entity.doWithAssociations(new AssociationHandler<CouchbasePersistentProperty>() {
@@ -201,7 +205,6 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter
return target.isAssignableFrom(value.getClass()) ? value : conversionService.convert(value, target);
}
@Override
public void write(final Object source, final CouchbaseDocument target) {
if (source == null) {