HHH-17284 Fix indentation in caching tests/documentation

This commit is contained in:
Daniel Kraus 2023-10-03 14:38:33 +02:00 committed by Christian Beikov
parent 9bbac65523
commit b19ca2dadc
3 changed files with 56 additions and 56 deletions

View File

@ -44,8 +44,8 @@ public class FirstLevelCacheTest {
entityManager.persist(new Person()); entityManager.persist(new Person());
entityManager.persist(new Person()); entityManager.persist(new Person());
Person person = new Person(); Person person = new Person();
entityManager.persist(person); entityManager.persist(person);
}); });
scope.inTransaction( entityManager -> { scope.inTransaction( entityManager -> {
List<Object> dtos = new ArrayList<>(); List<Object> dtos = new ArrayList<>();
//tag::caching-management-jpa-detach-example[] //tag::caching-management-jpa-detach-example[]
@ -86,7 +86,7 @@ public class FirstLevelCacheTest {
session.contains(person); session.contains(person);
//end::caching-management-contains-example[] //end::caching-management-contains-example[]
}); });
} }
private Object toDTO(Person person) { private Object toDTO(Person person) {
return person; return person;

View File

@ -65,16 +65,16 @@ public class NonStrictReadWriteCacheTest {
); );
} }
@Test @Test
public void testCache(EntityManagerFactoryScope scope) { public void testCache(EntityManagerFactoryScope scope) {
scope.inTransaction( entityManager -> { scope.inTransaction( entityManager -> {
Person person = new Person(); Person person = new Person();
entityManager.persist(person); entityManager.persist(person);
Phone home = new Phone("123-456-7890"); Phone home = new Phone("123-456-7890");
Phone office = new Phone("098-765-4321"); Phone office = new Phone("098-765-4321");
person.addPhone(home); person.addPhone(home);
person.addPhone(office); person.addPhone(office);
}); });
scope.inTransaction( entityManager -> { scope.inTransaction( entityManager -> {
Person person = entityManager.find(Person.class, 1L); Person person = entityManager.find(Person.class, 1L);
person.getPhones().size(); person.getPhones().size();
@ -88,21 +88,21 @@ public class NonStrictReadWriteCacheTest {
}); });
scope.inTransaction( entityManager -> { scope.inTransaction( entityManager -> {
log.info("Load from cache"); log.info("Load from cache");
entityManager.find(Person.class, 1L).getPhones().size(); entityManager.find(Person.class, 1L).getPhones().size();
}); });
} }
@Entity(name = "Person") @Entity(name = "Person")
@Cacheable @Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public static class Person { public static class Person {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
private String name; private String name;
//tag::caching-collection-mapping-example[] //tag::caching-collection-mapping-example[]
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL) @OneToMany(mappedBy = "person", cascade = CascadeType.ALL)
@ -110,26 +110,26 @@ public class NonStrictReadWriteCacheTest {
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//end::caching-collection-mapping-example[] //end::caching-collection-mapping-example[]
@Version @Version
private int version; private int version;
public Person() {} public Person() {}
public Person(String name) { public Person(String name) {
this.name = name; this.name = name;
} }
public Long getId() { public Long getId() {
return id; return id;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public List<Phone> getPhones() { public List<Phone> getPhones() {
return phones; return phones;

View File

@ -55,15 +55,15 @@ import static org.junit.Assert.assertNotNull;
public class SecondLevelCacheTest { public class SecondLevelCacheTest {
private final Logger log = Logger.getLogger( SecondLevelCacheTest.class ); private final Logger log = Logger.getLogger( SecondLevelCacheTest.class );
@Test @Test
public void testCache(EntityManagerFactoryScope scope) { public void testCache(EntityManagerFactoryScope scope) {
scope.inTransaction( entityManager -> { scope.inTransaction( entityManager -> {
entityManager.persist(new Person()); entityManager.persist(new Person());
Person aPerson= new Person(); Person aPerson= new Person();
aPerson.setName("John Doe"); aPerson.setName("John Doe");
aPerson.setCode("unique-code"); aPerson.setCode("unique-code");
entityManager.persist(aPerson); entityManager.persist(aPerson);
}); });
scope.inTransaction( entityManager -> { scope.inTransaction( entityManager -> {
log.info("Jpa load by id"); log.info("Jpa load by id");
@ -249,13 +249,13 @@ public class SecondLevelCacheTest {
@Entity(name = "Person") @Entity(name = "Person")
@Cacheable @Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE) @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public static class Person { public static class Person {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private Long id;
private String name; private String name;
@NaturalId @NaturalId
@Column(name = "code", unique = true) @Column(name = "code", unique = true)
@ -267,21 +267,21 @@ public class SecondLevelCacheTest {
public Person() {} public Person() {}
public Person(String name) { public Person(String name) {
this.name = name; this.name = name;
} }
public Long getId() { public Long getId() {
return id; return id;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getCode() { public String getCode() {
return code; return code;