BAEL-6320: format & code review
This commit is contained in:
parent
7be3725480
commit
4f8662aa01
|
@ -24,6 +24,7 @@
|
|||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
@ -31,5 +32,4 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.spring.data.jpa.naturalid;
|
||||
|
||||
import com.baeldung.spring.data.jpa.naturalid.repository.NaturalIdRepositoryImpl;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
|
|
@ -2,8 +2,10 @@ package com.baeldung.spring.data.jpa.naturalid;
|
|||
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.ConferenceRoom;
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.GuestRoom;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package com.baeldung.spring.data.jpa.naturalid;
|
||||
|
||||
import com.baeldung.spring.data.jpa.naturalid.repository.NaturalIdRepositoryImpl;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(repositoryBaseClass = NaturalIdRepositoryImpl.class)
|
||||
public class NaturalIdRepoConfig {
|
||||
public class NaturalIdRepositoryConfig {
|
||||
}
|
|
@ -4,6 +4,7 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
|
||||
@Entity
|
||||
|
@ -12,7 +13,7 @@ public class ConferenceRoom {
|
|||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NaturalId(mutable = true)
|
||||
@NaturalId
|
||||
private String name;
|
||||
|
||||
private int capacity;
|
||||
|
@ -29,10 +30,6 @@ public class ConferenceRoom {
|
|||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -47,10 +44,6 @@ public class ConferenceRoom {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HotelRoom{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", capacity=" + capacity +
|
||||
'}';
|
||||
return "HotelRoom{" + "id=" + id + ", name='" + name + '\'' + ", capacity=" + capacity + '}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import jakarta.persistence.Entity;
|
|||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
|
||||
@Entity
|
||||
|
@ -21,7 +22,6 @@ public class GuestRoom {
|
|||
private String name;
|
||||
private int capacity;
|
||||
|
||||
|
||||
public GuestRoom(int roomNumber, int floor, String name, int capacity) {
|
||||
this.roomNumber = roomNumber;
|
||||
this.floor = floor;
|
||||
|
@ -62,12 +62,6 @@ public class GuestRoom {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GuestRoom{" +
|
||||
"id=" + id +
|
||||
", roomNumber=" + roomNumber +
|
||||
", floor=" + floor +
|
||||
", name=" + name +
|
||||
", capacity=" + capacity +
|
||||
'}';
|
||||
return "GuestRoom{" + "id=" + id + ", roomNumber=" + roomNumber + ", floor=" + floor + ", name=" + name + ", capacity=" + capacity + '}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package com.baeldung.spring.data.jpa.naturalid.repository;
|
||||
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.ConferenceRoom;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ConferenceRoomJpaRepo extends JpaRepository<ConferenceRoom, Long> {
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.spring.data.jpa.naturalid.repository;
|
||||
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.ConferenceRoom;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package com.baeldung.spring.data.jpa.naturalid.repository;
|
||||
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.GuestRoom;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface GuestRoomJpaRepo extends JpaRepository<GuestRoom, Long> {
|
||||
public interface GuestRoomJpaRepository extends JpaRepository<GuestRoom, Long> {
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.baeldung.spring.data.jpa.naturalid.repository;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
|
||||
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
package com.baeldung.spring.data.jpa.naturalid;
|
||||
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.ConferenceRoom;
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.GuestRoom;
|
||||
import com.baeldung.spring.data.jpa.naturalid.repository.ConferenceRoomJpaRepo;
|
||||
import com.baeldung.spring.data.jpa.naturalid.repository.ConferenceRoomRepository;
|
||||
import com.baeldung.spring.data.jpa.naturalid.repository.GuestRoomJpaRepo;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.ConferenceRoom;
|
||||
import com.baeldung.spring.data.jpa.naturalid.entity.GuestRoom;
|
||||
import com.baeldung.spring.data.jpa.naturalid.repository.ConferenceRoomRepository;
|
||||
import com.baeldung.spring.data.jpa.naturalid.repository.GuestRoomJpaRepository;
|
||||
|
||||
@SpringBootTest
|
||||
class NaturalIdIntegrationTest {
|
||||
|
@ -22,16 +20,13 @@ class NaturalIdIntegrationTest {
|
|||
private HotelRoomsService service;
|
||||
|
||||
@Autowired
|
||||
private GuestRoomJpaRepo guestRoomJpaRepo;
|
||||
@Autowired
|
||||
private ConferenceRoomJpaRepo conferenceRoomJpaRepo;
|
||||
|
||||
private GuestRoomJpaRepository guestRoomJpaRepository;
|
||||
@Autowired
|
||||
private ConferenceRoomRepository conferenceRoomRepository;
|
||||
|
||||
@Test
|
||||
void whenWeFindByNaturalKey_thenEntityIsReturnedCorrectly() {
|
||||
guestRoomJpaRepo.save(new GuestRoom(23, 3, "B-423", 4));
|
||||
guestRoomJpaRepository.save(new GuestRoom(23, 3, "B-423", 4));
|
||||
|
||||
Optional<GuestRoom> result = service.guestRoom(23, 3);
|
||||
|
||||
|
@ -41,7 +36,7 @@ class NaturalIdIntegrationTest {
|
|||
|
||||
@Test
|
||||
void whenWeFindBySimpleNaturalKey_thenEntityIsReturnedCorrectly() {
|
||||
conferenceRoomJpaRepo.save(new ConferenceRoom("Colorado", 100));
|
||||
conferenceRoomRepository.save(new ConferenceRoom("Colorado", 100));
|
||||
|
||||
Optional<ConferenceRoom> result = service.conferenceRoom("Colorado");
|
||||
|
||||
|
@ -50,8 +45,8 @@ class NaturalIdIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void givenNaturalIdRepo_whenWeFindBySimpleNaturalKey_thenEntityIsReturnedCorrectly() {
|
||||
conferenceRoomJpaRepo.save(new ConferenceRoom("Nevada", 200));
|
||||
void givenNaturalIdRepository_whenWeFindBySimpleNaturalKey_thenEntityIsReturnedCorrectly() {
|
||||
conferenceRoomRepository.save(new ConferenceRoom("Nevada", 200));
|
||||
|
||||
Optional<ConferenceRoom> result = conferenceRoomRepository.naturalId("Nevada");
|
||||
|
||||
|
|
Loading…
Reference in New Issue