DATACMNS-1325 - Added dedicated identifier accessor for Persistable entities.
BasicPersistentEntity now returns a dedicated IdentifierAccessor that uses Persistable.getId() in case the entity implements Persistable.
This commit is contained in:
@@ -44,6 +44,7 @@ import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.annotation.TypeAlias;
|
||||
import org.springframework.data.domain.Persistable;
|
||||
import org.springframework.data.mapping.Alias;
|
||||
import org.springframework.data.mapping.Document;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
@@ -338,6 +339,14 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
assertThat(failed.get()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1325
|
||||
public void supportsPersistableViaIdentifierAccessor() {
|
||||
|
||||
PersistentEntity<PersistableEntity, T> entity = createEntity(PersistableEntity.class);
|
||||
|
||||
assertThat(entity.getIdentifierAccessor(new PersistableEntity()).getRequiredIdentifier()).isEqualTo(4711L);
|
||||
}
|
||||
|
||||
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type) {
|
||||
return createEntity(type, null);
|
||||
}
|
||||
@@ -382,4 +391,29 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
static class EntityWithAnnotation {
|
||||
|
||||
}
|
||||
|
||||
// DATACMNS-1325
|
||||
|
||||
static class PersistableEntity implements Persistable<Long> {
|
||||
|
||||
private final Long id = 42L;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.domain.Persistable#getId()
|
||||
*/
|
||||
@Override
|
||||
public Long getId() {
|
||||
return 4711L;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.domain.Persistable#isNew()
|
||||
*/
|
||||
@Override
|
||||
public boolean isNew() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user