Browse Source

DATACMNS-406 - Polishing.

Refactored code in RepositoryMetadata implementations to avoid compiler warnings. Some JavaDoc polishing.

Original pull request: #58.
pull/73/merge
Oliver Gierke 12 years ago
parent
commit
5b72373ddf
  1. 3
      src/main/java/org/springframework/data/repository/core/support/AbstractRepositoryMetadata.java
  2. 24
      src/main/java/org/springframework/data/repository/core/support/AnnotationRepositoryMetadata.java
  3. 35
      src/main/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadata.java
  4. 1
      src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryMetadataUnitTests.java

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

@ -59,7 +59,8 @@ public abstract class AbstractRepositoryMetadata implements RepositoryMetadata { @@ -59,7 +59,8 @@ public abstract class AbstractRepositoryMetadata implements RepositoryMetadata {
return Iterable.class.isAssignableFrom(rawType) ? returnTypeInfo.getComponentType().getType() : rawType;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.RepositoryMetadata#getRepositoryInterface()
*/
public Class<?> getRepositoryInterface() {

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

@ -69,32 +69,24 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata { @@ -69,32 +69,24 @@ public class AnnotationRepositoryMetadata extends AbstractRepositoryMetadata {
return this.domainType;
}
/**
* @param repositoryInterface must not be {@literal null}.
* @return the resolved domain type, never {@literal null}.
*/
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) {
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class);
Assert.isTrue(annotation != null && annotation.idClass() != null,
String.format("Could not resolve id type of %s!", repositoryInterface));
if (annotation == null || annotation.idClass() == null) {
throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface));
}
return annotation.idClass();
}
/**
* @param repositoryInterface must not be {@literal null}.
* @return the resolved domain type, never {@literal null}.
*/
private Class<?> resolveDomainType(Class<?> repositoryInterface) {
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
RepositoryDefinition annotation = repositoryInterface.getAnnotation(RepositoryDefinition.class);
Assert.isTrue(annotation != null && annotation.domainClass() != null,
String.format("Could not resolve domain type of %s!", repositoryInterface));
if (annotation == null || annotation.domainClass() == null) {
throw new IllegalArgumentException(String.format("Could not resolve domain type of %s!", repositoryInterface));
}
return annotation.domainClass();
}

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

@ -41,7 +41,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { @@ -41,7 +41,7 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata {
/**
* Creates a new {@link DefaultRepositoryMetadata} for the given repository interface.
*
* @param repositoryInterface
* @param repositoryInterface must not be {@literal null}.
*/
public DefaultRepositoryMetadata(Class<?> repositoryInterface) {
@ -70,33 +70,26 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata { @@ -70,33 +70,26 @@ public class DefaultRepositoryMetadata extends AbstractRepositoryMetadata {
return this.idType;
}
/**
* @param repositoryInterface must not be {@literal null}.
* @return the resolved domain type, never {@literal null}.
*/
private Class<?> resolveDomainType(Class<?> repositoryInterface) {
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
@SuppressWarnings("unchecked")
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) {
Class<?>[] arguments = resolveTypeArguments(repositoryInterface, Repository.class);
Assert.isTrue(arguments != null && arguments[0] != null,
String.format("Could not resolve domain type of %s!", repositoryInterface));
return arguments[0];
}
if (arguments == null || arguments[1] == null) {
throw new IllegalArgumentException(String.format("Could not resolve id type of %s!", repositoryInterface));
}
/**
* @param repositoryInterface must not be {@literal null}.
* @return the resolved id type, never {@literal null}.
*/
private Class<? extends Serializable> resolveIdType(Class<?> repositoryInterface) {
return (Class<? extends Serializable>) arguments[1];
}
Assert.notNull(repositoryInterface, "Repository interface must not be null!");
private Class<?> resolveDomainType(Class<?> repositoryInterface) {
Class<?>[] arguments = resolveTypeArguments(repositoryInterface, Repository.class);
Assert.isTrue(arguments != null && arguments[1] != null,
String.format("Could not resolve id type of %s!", repositoryInterface));
return (Class<? extends Serializable>) arguments[1];
if (arguments == null || arguments[0] == null) {
throw new IllegalArgumentException(String.format("Could not resolve domain type of %s!", repositoryInterface));
}
return arguments[0];
}
}

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

@ -88,7 +88,6 @@ public class DefaultRepositoryMetadataUnitTests { @@ -88,7 +88,6 @@ public class DefaultRepositoryMetadataUnitTests {
public void looksUpIdClassCorrectly() throws Exception {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);
assertEquals(Integer.class, metadata.getIdType());
}

Loading…
Cancel
Save