Polished codebase and added architecture management.

Added Sonargraph architecture description. Removed cyclic package dependency. Introduced JpaEntityInformationSupport to contain common getEntityName() method and serving as factory for JpaEntityInformation instances.
This commit is contained in:
Oliver Gierke
2011-07-21 12:18:37 +02:00
parent 14e8bd6955
commit 00ece2c25e
13 changed files with 430 additions and 137 deletions

View File

@@ -21,6 +21,7 @@ import java.io.Serializable;
import javax.persistence.EntityManager;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
@@ -52,8 +53,8 @@ public class CustomGenericJpaRepositoryFactory extends JpaRepositoryFactory {
*/
@Override
@SuppressWarnings("unchecked")
protected Object getTargetRepository(RepositoryMetadata metadata,
EntityManager em) {
protected JpaRepository<?, ?> getTargetRepository(
RepositoryMetadata metadata, EntityManager em) {
JpaEntityInformation<Object, Serializable> entityMetadata =
mock(JpaEntityInformation.class);

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jpa.repository.support;
import static org.junit.Assert.*;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.metamodel.SingularAttribute;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
/**
* Unit tests for {@link AbstractJpaEntityInformation}.
*
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class JpaEntityInformationSupportUnitTests {
@Test
public void usesSimpleClassNameIfNoEntityNameGiven() throws Exception {
JpaEntityInformation<User, Long> information =
new DummyJpaEntityInformation<User, Long>(User.class);
assertEquals("User", information.getEntityName());
JpaEntityInformation<NamedUser, ?> second =
new DummyJpaEntityInformation<NamedUser, Serializable>(
NamedUser.class);
assertEquals("AnotherNamedUser", second.getEntityName());
}
static class User {
}
@Entity(name = "AnotherNamedUser")
public class NamedUser {
}
static class DummyJpaEntityInformation<T, ID extends Serializable> extends
JpaEntityInformationSupport<T, ID> {
public DummyJpaEntityInformation(Class<T> domainClass) {
super(domainClass);
}
public SingularAttribute<? super T, ?> getIdAttribute() {
return null;
}
public ID getId(T entity) {
return null;
}
public Class<ID> getIdType() {
return null;
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2008-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jpa.repository.util;
import static org.junit.Assert.*;
import static org.springframework.data.jpa.repository.utils.JpaClassUtils.*;
import javax.persistence.Entity;
import org.junit.Test;
/**
* @author Oliver Gierke
*/
public class JpaClassUtilsUnitTests {
@Test
public void usesSimpleClassNameIfNoEntityNameGiven() throws Exception {
assertEquals("User", getEntityName(User.class));
assertEquals("AnotherNamedUser", getEntityName(NamedUser.class));
}
static class User {
}
@Entity(name = "AnotherNamedUser")
public class NamedUser {
}
}