Skip to content

Commit fcb22ea

Browse files
committed
Simplify code for persisting entities by cascading this operation from primary entity.
No functional changes.
1 parent 2f5cdf8 commit fcb22ea

File tree

7 files changed

+5
-208
lines changed

7 files changed

+5
-208
lines changed

src/main/java/ru/mystamps/web/dao/GibbonsCatalogDao.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/ru/mystamps/web/dao/MichelCatalogDao.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/ru/mystamps/web/dao/ScottCatalogDao.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/ru/mystamps/web/dao/YvertCatalogDao.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/ru/mystamps/web/entity/Series.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Date;
2121
import java.util.Set;
2222

23+
import javax.persistence.CascadeType;
2324
import javax.persistence.Column;
2425
import javax.persistence.Embedded;
2526
import javax.persistence.Entity;
@@ -65,19 +66,19 @@ public class Series {
6566
@Column(nullable = false)
6667
private Boolean perforated;
6768

68-
@ManyToMany(fetch = FetchType.EAGER)
69+
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
6970
@OrderBy
7071
private Set<MichelCatalog> michel;
7172

72-
@ManyToMany(fetch = FetchType.EAGER)
73+
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
7374
@OrderBy
7475
private Set<ScottCatalog> scott;
7576

76-
@ManyToMany(fetch = FetchType.EAGER)
77+
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
7778
@OrderBy
7879
private Set<YvertCatalog> yvert;
7980

80-
@ManyToMany(fetch = FetchType.EAGER)
81+
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
8182
@OrderBy
8283
private Set<GibbonsCatalog> gibbons;
8384

src/main/java/ru/mystamps/web/service/SeriesService.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232

3333
import org.apache.commons.lang3.Validate;
3434

35-
import ru.mystamps.web.dao.GibbonsCatalogDao;
36-
import ru.mystamps.web.dao.MichelCatalogDao;
37-
import ru.mystamps.web.dao.ScottCatalogDao;
3835
import ru.mystamps.web.dao.SeriesDao;
39-
import ru.mystamps.web.dao.YvertCatalogDao;
4036
import ru.mystamps.web.entity.GibbonsCatalog;
4137
import ru.mystamps.web.entity.MichelCatalog;
4238
import ru.mystamps.web.entity.ScottCatalog;
@@ -52,18 +48,6 @@ public class SeriesService {
5248
@Inject
5349
private SeriesDao seriesDao;
5450

55-
@Inject
56-
private MichelCatalogDao michelCatalogDao;
57-
58-
@Inject
59-
private ScottCatalogDao scottCatalogDao;
60-
61-
@Inject
62-
private YvertCatalogDao yvertCatalogDao;
63-
64-
@Inject
65-
private GibbonsCatalogDao gibbonsCatalogDao;
66-
6751
@Inject
6852
private ImageService imageService;
6953

@@ -130,7 +114,6 @@ private void setMichelNumbersIfProvided(AddSeriesDto dto, Series series) {
130114
Set<MichelCatalog> michelNumbers =
131115
CatalogUtils.fromString(dto.getMichelNumbers(), MichelCatalog.class);
132116
if (!michelNumbers.isEmpty()) {
133-
michelCatalogDao.save(michelNumbers);
134117
series.setMichel(michelNumbers);
135118
}
136119
}
@@ -139,7 +122,6 @@ private void setScottNumbersIfProvided(AddSeriesDto dto, Series series) {
139122
Set<ScottCatalog> scottNumbers =
140123
CatalogUtils.fromString(dto.getScottNumbers(), ScottCatalog.class);
141124
if (!scottNumbers.isEmpty()) {
142-
scottCatalogDao.save(scottNumbers);
143125
series.setScott(scottNumbers);
144126
}
145127
}
@@ -148,7 +130,6 @@ private void setYvertNumbersIfProvided(AddSeriesDto dto, Series series) {
148130
Set<YvertCatalog> yvertNumbers =
149131
CatalogUtils.fromString(dto.getYvertNumbers(), YvertCatalog.class);
150132
if (!yvertNumbers.isEmpty()) {
151-
yvertCatalogDao.save(yvertNumbers);
152133
series.setYvert(yvertNumbers);
153134
}
154135
}
@@ -157,7 +138,6 @@ private void setGibbonsNumbersIfProvided(AddSeriesDto dto, Series series) {
157138
Set<GibbonsCatalog> gibbonsNumbers =
158139
CatalogUtils.fromString(dto.getGibbonsNumbers(), GibbonsCatalog.class);
159140
if (!gibbonsNumbers.isEmpty()) {
160-
gibbonsCatalogDao.save(gibbonsNumbers);
161141
series.setGibbons(gibbonsNumbers);
162142
}
163143
}

src/test/java/ru/mystamps/web/service/SeriesServiceTest.java

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@
4343
import static org.fest.assertions.api.Assertions.assertThat;
4444

4545
import ru.mystamps.web.dao.CountryDao;
46-
import ru.mystamps.web.dao.GibbonsCatalogDao;
47-
import ru.mystamps.web.dao.MichelCatalogDao;
48-
import ru.mystamps.web.dao.ScottCatalogDao;
4946
import ru.mystamps.web.dao.SeriesDao;
50-
import ru.mystamps.web.dao.YvertCatalogDao;
5147
import ru.mystamps.web.entity.Country;
5248
import ru.mystamps.web.entity.GibbonsCatalog;
5349
import ru.mystamps.web.entity.MetaInfo;
@@ -65,18 +61,6 @@ public class SeriesServiceTest {
6561
@Mock
6662
private CountryDao countryDao;
6763

68-
@Mock
69-
private MichelCatalogDao michelCatalogDao;
70-
71-
@Mock
72-
private ScottCatalogDao scottCatalogDao;
73-
74-
@Mock
75-
private YvertCatalogDao yvertCatalogDao;
76-
77-
@Mock
78-
private GibbonsCatalogDao gibbonsCatalogDao;
79-
8064
@Mock
8165
private ImageService imageService;
8266

@@ -89,18 +73,6 @@ public class SeriesServiceTest {
8973
@Captor
9074
private ArgumentCaptor<Series> seriesCaptor;
9175

92-
@Captor
93-
private ArgumentCaptor<Set<MichelCatalog>> michelCatalogCaptor;
94-
95-
@Captor
96-
private ArgumentCaptor<Set<ScottCatalog>> scottCatalogCaptor;
97-
98-
@Captor
99-
private ArgumentCaptor<Set<YvertCatalog>> yvertCatalogCaptor;
100-
101-
@Captor
102-
private ArgumentCaptor<Set<GibbonsCatalog>> gibbonsCatalogCaptor;
103-
10476
@Captor
10577
private ArgumentCaptor<MultipartFile> multipartFileCaptor;
10678

@@ -221,20 +193,6 @@ public void addShouldPassNullToSeriesDaoIfMichelNumbersIsNull() {
221193
assertThat(seriesCaptor.getValue().getMichel()).isNull();
222194
}
223195

224-
@Test
225-
public void addShouldSaveMichelNumbers() {
226-
Set<MichelCatalog> expectedNumbers = newSet(
227-
new MichelCatalog("1"),
228-
new MichelCatalog("2")
229-
);
230-
form.setMichelNumbers(StringUtils.join(expectedNumbers, ','));
231-
232-
service.add(form, user);
233-
234-
verify(michelCatalogDao).save(michelCatalogCaptor.capture());
235-
assertThat(michelCatalogCaptor.getValue()).isEqualTo(expectedNumbers);
236-
}
237-
238196
@Test
239197
public void addShouldPassMichelNumbersToSeriesDao() {
240198
Set<MichelCatalog> expectedNumbers = newSet(
@@ -260,20 +218,6 @@ public void addShouldPassNullToSeriesDaoIfScottNumbersIsNull() {
260218
assertThat(seriesCaptor.getValue().getScott()).isNull();
261219
}
262220

263-
@Test
264-
public void addShouldSaveScottNumbers() {
265-
Set<ScottCatalog> expectedNumbers = newSet(
266-
new ScottCatalog("1"),
267-
new ScottCatalog("2")
268-
);
269-
form.setScottNumbers(StringUtils.join(expectedNumbers, ','));
270-
271-
service.add(form, user);
272-
273-
verify(scottCatalogDao).save(scottCatalogCaptor.capture());
274-
assertThat(scottCatalogCaptor.getValue()).isEqualTo(expectedNumbers);
275-
}
276-
277221
@Test
278222
public void addShouldPassScottNumbersToSeriesDao() {
279223
Set<ScottCatalog> expectedNumbers = newSet(
@@ -299,20 +243,6 @@ public void addShouldPassNullToSeriesDaoIfYvertNumbersIsNull() {
299243
assertThat(seriesCaptor.getValue().getYvert()).isNull();
300244
}
301245

302-
@Test
303-
public void addShouldSaveYvertNumbers() {
304-
Set<YvertCatalog> expectedNumbers = newSet(
305-
new YvertCatalog("1"),
306-
new YvertCatalog("2")
307-
);
308-
form.setYvertNumbers(StringUtils.join(expectedNumbers, ','));
309-
310-
service.add(form, user);
311-
312-
verify(yvertCatalogDao).save(yvertCatalogCaptor.capture());
313-
assertThat(yvertCatalogCaptor.getValue()).isEqualTo(expectedNumbers);
314-
}
315-
316246
@Test
317247
public void addShouldPassYvertNumbersToSeriesDao() {
318248
Set<YvertCatalog> expectedNumbers = newSet(
@@ -338,20 +268,6 @@ public void addShouldPassNullToSeriesDaoIfGibbonsNumbersIsNull() {
338268
assertThat(seriesCaptor.getValue().getGibbons()).isNull();
339269
}
340270

341-
@Test
342-
public void addShouldSaveGibbonsNumbers() {
343-
Set<GibbonsCatalog> expectedNumbers = newSet(
344-
new GibbonsCatalog("1"),
345-
new GibbonsCatalog("2")
346-
);
347-
form.setGibbonsNumbers(StringUtils.join(expectedNumbers, ','));
348-
349-
service.add(form, user);
350-
351-
verify(gibbonsCatalogDao).save(gibbonsCatalogCaptor.capture());
352-
assertThat(gibbonsCatalogCaptor.getValue()).isEqualTo(expectedNumbers);
353-
}
354-
355271
@Test
356272
public void addShouldPassGibbonsNumbersToSeriesDao() {
357273
Set<GibbonsCatalog> expectedNumbers = newSet(

0 commit comments

Comments
 (0)