Skip to content

Commit 9f65b57

Browse files
committed
DATACMNS-406 - Polishing.
Refactored code in RepositoryMetadata implementations to avoid compiler warnings. Some JavaDoc polishing. Original pull request: #58.
1 parent b96f613 commit 9f65b57

File tree

4 files changed

+24
-39
lines changed

4 files changed

+24
-39
lines changed

src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public Class<?> getReturnedDomainClass(Method method) {
5959
return Iterable.class.isAssignableFrom(rawType) ? returnTypeInfo.getComponentType().getType() : rawType;
6060
}
6161

62-
/* (non-Javadoc)
62+
/*
63+
* (non-Javadoc)
6364
* @see org.springframework.data.repository.core.RepositoryMetadata#getRepositoryInterface()
6465
*/
6566
public Class<?> getRepositoryInterface() {

src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,24 @@ public Class<?> getDomainType() {
6969
return this.domainType;
7070
}
7171

72-
/**
73-
* @param repositoryInterface must not be {@literal null}.
74-
* @return the resolved domain type, never {@literal null}.
75-
*/
7672
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) {
7773

78-
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
79-
8074
RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class);
81-
Assert.isTrue(annotation != null && annotation.idClass() != null,
82-
String.format("Could not resolve id type of %s!", repositoryInterface));
75+
76+
if (annotation == null || annotation.idClass() == null) {
77+
throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface));
78+
}
8379

8480
return annotation.idClass();
8581
}
8682

87-
/**
88-
* @param repositoryInterface must not be {@literal null}.
89-
* @return the resolved domain type, never {@literal null}.
90-
*/
9183
private Class<?> resolveDomainType(Class<?> repositoryInterface) {
9284

93-
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
94-
9585
RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class);
96-
Assert.isTrue(annotation != null && annotation.domainClass() != null,
97-
String.format("Could not resolve domain type of %s!", repositoryInterface));
86+
87+
if (annotation == null || annotation.domainClass() == null) {
88+
throw new IllegalArgumentException(String.format("Could not resolve domain type of %s!", repositoryInterface));
89+
}
9890

9991
return annotation.domainClass();
10092
}

src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata {
4141
/**
4242
* Creates a new {@link DefaultRepositoryMetadata} for the given repository interface.
4343
*
44-
* @param repositoryInterface
44+
* @param repositoryInterface must not be {@literal null}.
4545
*/
4646
public DefaultRepositoryMetadata(Class<?> repositoryInterface) {
4747

@@ -70,33 +70,26 @@ public Class<? extends Serializable> getIdType() {
7070
return this.idType;
7171
}
7272

73-
/**
74-
* @param repositoryInterface must not be {@literal null}.
75-
* @return the resolved domain type, never {@literal null}.
76-
*/
77-
private Class<?> resolveDomainType(Class<?> repositoryInterface) {
78-
79-
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
73+
@SuppressWarnings("unchecked")
74+
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) {
8075

8176
Class<?>[] arguments = resolveTypeArguments(repositoryInterface, Repository.class);
82-
Assert.isTrue(arguments != null && arguments[0] != null,
83-
String.format("Could not resolve domain type of %s!", repositoryInterface));
8477

85-
return arguments[0];
86-
}
78+
if (arguments == null || arguments[1] == null) {
79+
throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface));
80+
}
8781

88-
/**
89-
* @param repositoryInterface must not be {@literal null}.
90-
* @return the resolved id type, never {@literal null}.
91-
*/
92-
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) {
82+
return (Class<? extends Serializable>) arguments[1];
83+
}
9384

94-
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
85+
private Class<?> resolveDomainType(Class<?> repositoryInterface) {
9586

9687
Class<?>[] arguments = resolveTypeArguments(repositoryInterface, Repository.class);
97-
Assert.isTrue(arguments != null && arguments[1] != null,
98-
String.format("Could not resolve id type of %s!", repositoryInterface));
9988

100-
return (Class<? extends Serializable>) arguments[1];
89+
if (arguments == null || arguments[0] == null) {
90+
throw new IllegalArgumentException(String.format("Could not resolve domain type of %s!", repositoryInterface));
91+
}
92+
93+
return arguments[0];
10194
}
10295
}

src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public void detectsParameterizedEntitiesCorrectly() {
8888
public void looksUpIdClassCorrectly() throws Exception {
8989

9090
RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);
91-
9291
assertEquals(Integer.class, metadata.getIdType());
9392
}
9493

0 commit comments

Comments
 (0)