Skip to content

Commit

Permalink
DATACMNS-862 - ReturnedInterface now considers interfaces implemented…
Browse files Browse the repository at this point in the history
… by the domain type.

We now check whether the interface return type is implemented by the domain type and opt out of all projection efforts if so.
  • Loading branch information
odrotbohm committed Jun 1, 2016
1 parent 5b5daaf commit e414cd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Class<?> getReturnedType() {
* @see org.springframework.data.repository.query.ReturnedType#needsCustomConstruction()
*/
public boolean needsCustomConstruction() {
return information.isClosed();
return isProjecting() && information.isClosed();
}

/*
Expand All @@ -169,7 +169,7 @@ public boolean needsCustomConstruction() {
*/
@Override
public boolean isProjecting() {
return true;
return !information.getType().isAssignableFrom(domainType);
}

/*
Expand All @@ -178,7 +178,7 @@ public boolean isProjecting() {
*/
@Override
public Class<?> getTypeToRead() {
return information.isClosed() ? null : domainType;
return isProjecting() && information.isClosed() ? null : domainType;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ public void considersAllJavaTypesAsNotProjecting() throws Exception {
assertThat(type.isProjecting(), is(false));
}

/**
* @see DATACMNS-862
*/
@Test
public void considersInterfaceImplementedByDomainTypeNotProjecting() throws Exception {

ReturnedType type = getReturnedType("findOneInterface");

assertThat(type.needsCustomConstruction(), is(false));
assertThat(type.isProjecting(), is(false));
}

private static ReturnedType getReturnedType(String methodName, Class<?>... parameters) throws Exception {
return getQueryMethod(methodName, parameters).getResultProcessor().getReturnedType();
}
Expand Down Expand Up @@ -206,12 +218,16 @@ interface SampleRepository extends Repository<Sample, Long> {

LocalDateTime timeQuery();

SampleInterface findOneInterface();

static enum MyEnum {
VALUE
}
}

static class Sample {
static interface SampleInterface {}

static class Sample implements SampleInterface {
public String firstname, lastname;

public Sample(String firstname, String lastname) {
Expand Down

0 comments on commit e414cd6

Please sign in to comment.