minor formatting work
This commit is contained in:
parent
3380dba316
commit
dffd5fd903
|
@ -25,7 +25,7 @@ public class StudentJpaConfig {
|
|||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
|
@ -36,7 +36,7 @@ public class StudentJpaConfig {
|
|||
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
|
||||
|
@ -46,23 +46,23 @@ public class StudentJpaConfig {
|
|||
em.setJpaProperties(additionalProperties());
|
||||
return em;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
|
||||
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||
transactionManager.setEntityManagerFactory(entityManagerFactory);
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
|
||||
final Properties additionalProperties() {
|
||||
final Properties hibernateProperties = new Properties();
|
||||
|
||||
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||
hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql"));
|
||||
hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", env.getProperty("hibernate.cache.use_second_level_cache"));
|
||||
hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", env.getProperty("hibernate.cache.use_second_level_cache"));
|
||||
hibernateProperties.setProperty("hibernate.cache.use_query_cache", env.getProperty("hibernate.cache.use_query_cache"));
|
||||
|
||||
|
||||
return hibernateProperties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,7 @@ public class ClientDao {
|
|||
}
|
||||
|
||||
public String getClientName() {
|
||||
return this.jdbcTemplate.query(SQL_GET_CLIENT_NAME, rowMapper)
|
||||
.get(0);
|
||||
return this.jdbcTemplate.query(SQL_GET_CLIENT_NAME, rowMapper).get(0);
|
||||
}
|
||||
|
||||
private static RowMapper<String> rowMapper = (rs, rowNum) -> {
|
||||
|
|
|
@ -27,8 +27,7 @@ public class ExtendedRepositoryImpl<T, ID extends Serializable> extends SimpleJp
|
|||
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<T> query = builder.createQuery(getDomainClass());
|
||||
Root<T> root = query.from(getDomainClass());
|
||||
query.select(root)
|
||||
.where(builder.like(root.<String> get(attributeName), "%" + text + "%"));
|
||||
query.select(root).where(builder.like(root.<String> get(attributeName), "%" + text + "%"));
|
||||
TypedQuery<T> q = entityManager.createQuery(query);
|
||||
return q.getResultList();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ public class KVTag {
|
|||
private String key;
|
||||
private String value;
|
||||
|
||||
public KVTag(){}
|
||||
public KVTag() {
|
||||
}
|
||||
|
||||
public KVTag(String key, String value) {
|
||||
super();
|
||||
|
|
|
@ -8,7 +8,8 @@ public class LocationTag {
|
|||
private int xPos;
|
||||
private int yPos;
|
||||
|
||||
public LocationTag(){}
|
||||
public LocationTag() {
|
||||
}
|
||||
|
||||
public LocationTag(String name, int xPos, int yPos) {
|
||||
super();
|
||||
|
|
|
@ -13,12 +13,11 @@ public class ManyStudent {
|
|||
private String name;
|
||||
|
||||
@ManyToMany(cascade = CascadeType.ALL)
|
||||
@JoinTable(name = "manystudent_manytags",
|
||||
joinColumns = @JoinColumn(name = "manystudent_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "manytag_id", referencedColumnName = "id"))
|
||||
@JoinTable(name = "manystudent_manytags", joinColumns = @JoinColumn(name = "manystudent_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "manytag_id", referencedColumnName = "id"))
|
||||
private Set<ManyTag> manyTags = new HashSet<>();
|
||||
|
||||
public ManyStudent() {}
|
||||
public ManyStudent() {
|
||||
}
|
||||
|
||||
public ManyStudent(String name) {
|
||||
this.name = name;
|
||||
|
|
|
@ -15,7 +15,8 @@ public class ManyTag {
|
|||
@ManyToMany(mappedBy = "manyTags")
|
||||
private Set<ManyStudent> students = new HashSet<>();
|
||||
|
||||
public ManyTag() {}
|
||||
public ManyTag() {
|
||||
}
|
||||
|
||||
public ManyTag(String name) {
|
||||
this.name = name;
|
||||
|
|
|
@ -7,7 +7,8 @@ public class SkillTag {
|
|||
private String name;
|
||||
private int value;
|
||||
|
||||
public SkillTag(){}
|
||||
public SkillTag() {
|
||||
}
|
||||
|
||||
public SkillTag(String name, int value) {
|
||||
super();
|
||||
|
|
|
@ -13,21 +13,24 @@ public class Country {
|
|||
@Id
|
||||
@GeneratedValue(strategy = IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,17 +34,11 @@ public class DataSourceRoutingTestConfiguration {
|
|||
|
||||
private DataSource clientADatasource() {
|
||||
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
||||
return dbBuilder.setType(EmbeddedDatabaseType.H2)
|
||||
.setName("CLIENT_A")
|
||||
.addScript("classpath:dsrouting-db.sql")
|
||||
.build();
|
||||
return dbBuilder.setType(EmbeddedDatabaseType.H2).setName("CLIENT_A").addScript("classpath:dsrouting-db.sql").build();
|
||||
}
|
||||
|
||||
private DataSource clientBDatasource() {
|
||||
EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
|
||||
return dbBuilder.setType(EmbeddedDatabaseType.H2)
|
||||
.setName("CLIENT_B")
|
||||
.addScript("classpath:dsrouting-db.sql")
|
||||
.build();
|
||||
return dbBuilder.setType(EmbeddedDatabaseType.H2).setName("CLIENT_B").addScript("classpath:dsrouting-db.sql").build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class AdvancedTaggingIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenStudentWithKVTags_whenSave_thenGetByTagOk(){
|
||||
public void givenStudentWithKVTags_whenSave_thenGetByTagOk() {
|
||||
Student student = new Student(0, "John");
|
||||
student.setKVTags(Arrays.asList(new KVTag("department", "computer science")));
|
||||
studentRepository.save(student);
|
||||
|
|
|
@ -16,13 +16,13 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { StudentJPAH2Config.class})
|
||||
@ContextConfiguration(classes = { StudentJPAH2Config.class })
|
||||
public class ExtendedStudentRepositoryIntegrationTest {
|
||||
@Resource
|
||||
private ExtendedStudentRepository extendedStudentRepository;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
public void setup() {
|
||||
Student student = new Student(1, "john");
|
||||
extendedStudentRepository.save(student);
|
||||
Student student2 = new Student(2, "johnson");
|
||||
|
@ -30,10 +30,10 @@ public class ExtendedStudentRepositoryIntegrationTest {
|
|||
Student student3 = new Student(3, "tom");
|
||||
extendedStudentRepository.save(student3);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenStudents_whenFindByName_thenGetOk(){
|
||||
public void givenStudents_whenFindByName_thenGetOk() {
|
||||
List<Student> students = extendedStudentRepository.findByAttributeContainsText("name", "john");
|
||||
assertThat(students.size()).isEqualTo(2);
|
||||
assertThat(students.size()).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,24 +21,24 @@ import static org.junit.Assert.assertEquals;
|
|||
@ContextConfiguration(classes = { StudentJpaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@Transactional
|
||||
public class InMemoryDBIntegrationTest {
|
||||
|
||||
|
||||
@Resource
|
||||
private StudentRepository studentRepository;
|
||||
|
||||
|
||||
private static final long ID = 1;
|
||||
private static final String NAME="john";
|
||||
|
||||
private static final String NAME = "john";
|
||||
|
||||
@Test
|
||||
public void givenStudent_whenSave_thenGetOk(){
|
||||
public void givenStudent_whenSave_thenGetOk() {
|
||||
Student student = new Student(ID, NAME);
|
||||
studentRepository.save(student);
|
||||
|
||||
|
||||
Student student2 = studentRepository.findOne(ID);
|
||||
assertEquals("name incorrect", NAME, student2.getName());
|
||||
assertEquals("name incorrect", NAME, student2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStudentWithTags_whenSave_thenGetByTagOk(){
|
||||
public void givenStudentWithTags_whenSave_thenGetByTagOk() {
|
||||
Student student = new Student(ID, NAME);
|
||||
student.setTags(Arrays.asList("full time", "computer science"));
|
||||
studentRepository.save(student);
|
||||
|
@ -48,7 +48,7 @@ public class InMemoryDBIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenMultipleStudentsWithTags_whenSave_thenGetByTagReturnsCorrectCount(){
|
||||
public void givenMultipleStudentsWithTags_whenSave_thenGetByTagReturnsCorrectCount() {
|
||||
Student student = new Student(0, "Larry");
|
||||
student.setTags(Arrays.asList("full time", "computer science"));
|
||||
studentRepository.save(student);
|
||||
|
@ -70,7 +70,7 @@ public class InMemoryDBIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenStudentWithTags_whenSave_thenGetByNameAndTagOk(){
|
||||
public void givenStudentWithTags_whenSave_thenGetByNameAndTagOk() {
|
||||
Student student = new Student(ID, NAME);
|
||||
student.setTags(Arrays.asList("full time", "computer science"));
|
||||
studentRepository.save(student);
|
||||
|
|
|
@ -117,9 +117,7 @@ public class DeletionIntegrationTest {
|
|||
entityManager.persist(foo);
|
||||
flushAndClear();
|
||||
|
||||
entityManager.createQuery("delete from Foo where id = :id")
|
||||
.setParameter("id", foo.getId())
|
||||
.executeUpdate();
|
||||
entityManager.createQuery("delete from Foo where id = :id").setParameter("id", foo.getId()).executeUpdate();
|
||||
|
||||
assertThat(entityManager.find(Foo.class, foo.getId()), nullValue());
|
||||
}
|
||||
|
@ -131,9 +129,7 @@ public class DeletionIntegrationTest {
|
|||
entityManager.persist(foo);
|
||||
flushAndClear();
|
||||
|
||||
entityManager.createNativeQuery("delete from FOO where ID = :id")
|
||||
.setParameter("id", foo.getId())
|
||||
.executeUpdate();
|
||||
entityManager.createNativeQuery("delete from FOO where ID = :id").setParameter("id", foo.getId()).executeUpdate();
|
||||
|
||||
assertThat(entityManager.find(Foo.class, foo.getId()), nullValue());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue