BAEL-2809: Added code samples
This commit is contained in:
parent
c0c5a64b10
commit
46f5e0dc93
@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@ -27,16 +28,16 @@ public class JpaBatchInsertsIntegrationTest {
|
|||||||
|
|
||||||
private static final int BATCH_SIZE = 5;
|
private static final int BATCH_SIZE = 5;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() {
|
public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
School school = createSchool(i);
|
School school = createSchool(i);
|
||||||
entityManager.persist(school);
|
entityManager.persist(school);
|
||||||
}
|
}
|
||||||
|
|
||||||
entityManager.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Test
|
@Test
|
||||||
public void whenFlushingAfterBatch_ThenClearsMemory() {
|
public void whenFlushingAfterBatch_ThenClearsMemory() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
@ -48,10 +49,9 @@ public class JpaBatchInsertsIntegrationTest {
|
|||||||
School school = createSchool(i);
|
School school = createSchool(i);
|
||||||
entityManager.persist(school);
|
entityManager.persist(school);
|
||||||
}
|
}
|
||||||
|
|
||||||
entityManager.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Test
|
@Test
|
||||||
public void whenThereAreMultipleEntities_ThenCreatesNewBatch() {
|
public void whenThereAreMultipleEntities_ThenCreatesNewBatch() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
@ -67,10 +67,9 @@ public class JpaBatchInsertsIntegrationTest {
|
|||||||
entityManager.persist(firstStudent);
|
entityManager.persist(firstStudent);
|
||||||
entityManager.persist(secondStudent);
|
entityManager.persist(secondStudent);
|
||||||
}
|
}
|
||||||
|
|
||||||
entityManager.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Test
|
@Test
|
||||||
public void whenUpdatingEntities_thenCreatesBatch() {
|
public void whenUpdatingEntities_thenCreatesBatch() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
@ -86,7 +85,10 @@ public class JpaBatchInsertsIntegrationTest {
|
|||||||
for (School school : allSchools) {
|
for (School school : allSchools) {
|
||||||
school.setName("Updated_" + school.getName());
|
school.setName("Updated_" + school.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
entityManager.flush();
|
entityManager.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user