Skip to content

Commit b315cb3

Browse files
fixed #10
1 parent 2c3d8f8 commit b315cb3

File tree

13 files changed

+73
-110
lines changed

13 files changed

+73
-110
lines changed

src/main/java/org/woehlke/beachbox/entities/Rubrik.java

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

src/main/java/org/woehlke/beachbox/entities/Tontraeger.java

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

src/main/java/org/woehlke/beachbox/entities/Vinyl.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ public class Vinyl implements Serializable {
1717
private Long id;
1818

1919
@Enumerated(EnumType.STRING)
20-
private Rubrik rubrik;
21-
22-
@Enumerated(EnumType.STRING)
23-
private Tontraeger tontraeger;
20+
private VinylType type;
2421

2522
@Column
2623
private String interpret;
@@ -54,20 +51,12 @@ public void setId(Long id) {
5451
this.id = id;
5552
}
5653

57-
public Rubrik getRubrik() {
58-
return rubrik;
59-
}
60-
61-
public void setRubrik(Rubrik rubrik) {
62-
this.rubrik = rubrik;
63-
}
64-
65-
public Tontraeger getTontraeger() {
66-
return tontraeger;
54+
public VinylType getType() {
55+
return type;
6756
}
6857

69-
public void setTontraeger(Tontraeger tontraeger) {
70-
this.tontraeger = tontraeger;
58+
public void setType(VinylType type) {
59+
this.type = type;
7160
}
7261

7362
public String getInterpret() {
@@ -137,7 +126,7 @@ public void setBemerkung(String bemerkung) {
137126
@Override
138127
public boolean equals(Object o) {
139128
if (this == o) return true;
140-
if (o == null || getClass() != o.getClass()) return false;
129+
if (!(o instanceof Vinyl)) return false;
141130

142131
Vinyl vinyl = (Vinyl) o;
143132

@@ -148,19 +137,17 @@ public boolean equals(Object o) {
148137
if (jahr != null ? !jahr.equals(vinyl.jahr) : vinyl.jahr != null) return false;
149138
if (label != null ? !label.equals(vinyl.label) : vinyl.label != null) return false;
150139
if (name != null ? !name.equals(vinyl.name) : vinyl.name != null) return false;
151-
if (rubrik != vinyl.rubrik) return false;
152140
if (seite != null ? !seite.equals(vinyl.seite) : vinyl.seite != null) return false;
153141
if (song != null ? !song.equals(vinyl.song) : vinyl.song != null) return false;
154-
if (tontraeger != vinyl.tontraeger) return false;
142+
if (type != vinyl.type) return false;
155143

156144
return true;
157145
}
158146

159147
@Override
160148
public int hashCode() {
161149
int result = id != null ? id.hashCode() : 0;
162-
result = 31 * result + (rubrik != null ? rubrik.hashCode() : 0);
163-
result = 31 * result + (tontraeger != null ? tontraeger.hashCode() : 0);
150+
result = 31 * result + (type != null ? type.hashCode() : 0);
164151
result = 31 * result + (interpret != null ? interpret.hashCode() : 0);
165152
result = 31 * result + (song != null ? song.hashCode() : 0);
166153
result = 31 * result + (name != null ? name.hashCode() : 0);
@@ -176,8 +163,7 @@ public int hashCode() {
176163
public String toString() {
177164
return "Vinyl{" +
178165
"id=" + id +
179-
", rubrik=" + rubrik +
180-
", tontraeger=" + tontraeger +
166+
", type=" + type +
181167
", interpret='" + interpret + '\'' +
182168
", song='" + song + '\'' +
183169
", name='" + name + '\'' +

src/main/java/org/woehlke/beachbox/repository/InstallDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
public interface InstallDao {
77

88
void installInitialData();
9+
10+
void update01();
911
}

src/main/java/org/woehlke/beachbox/repository/InstallDaoImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,22 @@ public void installInitialData() {
3838
e.printStackTrace();
3939
}
4040
}
41+
42+
@Override
43+
public void update01() {
44+
System.out.println("run SQL update01.");
45+
try {
46+
ClassLoader cl = InstallDaoImpl.class.getClassLoader();
47+
InputStream is = cl.getResourceAsStream("update01.sql");
48+
InputStreamReader isr =
49+
new InputStreamReader(is,"UTF-8");
50+
BufferedReader br = new BufferedReader(isr);
51+
br.lines().forEach(sql -> jdbcTemplate.execute(sql));
52+
br.close();
53+
} catch (FileNotFoundException e) {
54+
e.printStackTrace();
55+
} catch (IOException e) {
56+
e.printStackTrace();
57+
}
58+
}
4159
}

src/main/java/org/woehlke/beachbox/service/VinylService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public interface VinylService {
2020
void deleteById(long id);
2121

2222
void installInitialData();
23+
24+
void update01();
2325
}

src/main/java/org/woehlke/beachbox/service/VinylServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ public void deleteById(long id) {
5252
}
5353

5454
@Override
55+
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
5556
public void installInitialData() {
5657
installDao.installInitialData();
5758
}
59+
60+
@Override
61+
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false)
62+
public void update01() {
63+
installDao.update01();
64+
}
5865
}

src/main/java/org/woehlke/beachbox/web/VinylController.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
import org.springframework.web.bind.annotation.RequestMapping;
1515
import org.springframework.web.bind.annotation.RequestMethod;
1616
import org.springframework.web.bind.annotation.SessionAttributes;
17-
import org.woehlke.beachbox.entities.Rubrik;
18-
import org.woehlke.beachbox.entities.Tontraeger;
1917
import org.woehlke.beachbox.entities.Vinyl;
18+
import org.woehlke.beachbox.entities.VinylType;
2019
import org.woehlke.beachbox.service.VinylService;
2120

2221
import javax.inject.Inject;
@@ -103,24 +102,22 @@ public String search(@Valid SessionBean searchItem, BindingResult result,
103102
sort = page.getSort().toString().split(":")[0];
104103
//LOGGER.info("sort: " + sort);
105104
}
106-
model.addAttribute("page",page);
105+
model.addAttribute("page", page);
107106
searchItem.setBeginIndex(begin);
108107
searchItem.setEndIndex(end);
109108
searchItem.setCurrentIndex(current);
110109
searchItem.setSort(sort);
111110
searchItem.setSortDir("asc");
112111
model.addAttribute("searchItem",searchItem);
113-
model.addAttribute("rubrik", Rubrik.values());
114-
model.addAttribute("tontraeger", Tontraeger.values());
112+
model.addAttribute("type", VinylType.values());
115113
return "all";
116114
}
117115

118116
@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
119117
public String editGet(@PathVariable long id, Model model){
120118
Vinyl vinyl = vinylService.findById(id);
121119
model.addAttribute("vinyl",vinyl);
122-
model.addAttribute("rubrik", Rubrik.values());
123-
model.addAttribute("tontraeger", Tontraeger.values());
120+
model.addAttribute("type", VinylType.values());
124121
return "edit";
125122
}
126123

@@ -144,8 +141,7 @@ public String editPost(@PathVariable long id, @Valid Vinyl vinyl,Model model){
144141
public String newGet(Model model){
145142
Vinyl vinyl = new Vinyl();
146143
model.addAttribute("vinyl",vinyl);
147-
model.addAttribute("rubrik", Rubrik.values());
148-
model.addAttribute("tontraeger", Tontraeger.values());
144+
model.addAttribute("type", VinylType.values());
149145
return "new";
150146
}
151147

@@ -169,8 +165,7 @@ public String newPost(@Valid Vinyl vinyl,Model model){
169165
public String deleteGet(@PathVariable long id, Model model){
170166
Vinyl vinyl = vinylService.findById(id);
171167
model.addAttribute("vinyl",vinyl);
172-
model.addAttribute("rubrik", Rubrik.values());
173-
model.addAttribute("tontraeger", Tontraeger.values());
168+
model.addAttribute("type", VinylType.values());
174169
return "delete";
175170
}
176171

@@ -210,4 +205,10 @@ public String install(Model model){
210205
vinylService.installInitialData();
211206
return "redirect:/";
212207
}
208+
209+
@RequestMapping(value = "/update01", method = RequestMethod.GET)
210+
public String update01(Model model){
211+
vinylService.update01();
212+
return "redirect:/";
213+
}
213214
}

src/main/resources/update01.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
update Vinyl set type='CD_SAMPLER' where rubrik='CD_SAMPLER';
2+
update Vinyl set type='LP_SAMPLER' where rubrik='LP_SAMPLER';
3+
update Vinyl set type='CD' where rubrik='CD';
4+
update Vinyl set type='LP' where rubrik='LP';
5+
update Vinyl set type='SINGLES' where rubrik in ('SINGLES','SINGLES_COUNTRY_UND_JAZZ','SINGLES_DEUTSCH');
6+
update Vinyl set type='MC' where tontraeger='MC';
7+
update Vinyl set type='DVD' where tontraeger='DVD';
8+
update Vinyl set type='VIDEO' where tontraeger='VIDEO';
9+
ALTER TABLE Vinyl DROP COLUMN tontraeger, DROP COLUMN rubrik;

src/main/webapp/WEB-INF/views/all.jsp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@
108108
<tr>
109109
<c:url var="startUrl" value="/?page.page=1&page.size=${page.size}"/>
110110
<!--<th><a href="${startUrl}&page.sort=id&page.sort.dir=asc">Id</a></th>-->
111-
<th><a href="${startUrl}&page.sort=rubrik&page.sort.dir=asc">Rubrik</th>
112-
<th><a href="${startUrl}&page.sort=tontraeger&page.sort.dir=asc">Tontraeger</th>
111+
<th><a href="${startUrl}&page.sort=type&page.sort.dir=asc">Tontraeger</th>
113112
<th><a href="${startUrl}&page.sort=interpret&page.sort.dir=asc">Interpret</th>
114113
<th><a href="${startUrl}&page.sort=song&page.sort.dir=asc">Song</th>
115114
<th><a href="${startUrl}&page.sort=name&page.sort.dir=asc">Name</th>
@@ -128,8 +127,7 @@
128127
<c:url var="editUrl" value="/edit"/>
129128
<c:url var="deleteUrl" value="/delete"/>
130129
<!--<td>${v.id}</td>-->
131-
<td>${v.rubrik}</td>
132-
<td>${v.tontraeger}</td>
130+
<td>${v.type}</td>
133131
<td>${v.interpret}</td>
134132
<td>${v.song}</td>
135133
<td>${v.name}</td>

src/main/webapp/WEB-INF/views/delete.jsp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,14 @@
2020
<form:form id="formId" commandName="vinyl" method="post"
2121
class="form-horizontal">
2222
<div class="input-group">
23-
<form:label path="rubrik" class="control-label">Rubrik</form:label>
23+
<form:label path="type" class="control-label">Tontraeger</form:label>
2424
<div class="controls">
25-
<form:select path="rubrik">
26-
<form:options items="${rubrik}"/>
25+
<form:select path="type">
26+
<form:options items="${type}" />
2727
</form:select>
2828
</div>
29-
<form:errors path="rubrik" class="alert alert-danger"/>
29+
<form:errors path="type" class="alert alert-danger"/>
3030
</div>
31-
<div class="input-group">
32-
<form:label path="tontraeger" class="control-label">Tontraeger</form:label>
33-
<div class="controls">
34-
<form:select path="tontraeger">
35-
<form:options items="${tontraeger}" />
36-
</form:select>
37-
</div>
38-
<form:errors path="tontraeger" class="alert alert-danger"/>
39-
</div>
40-
4131
<div class="input-group">
4232
<form:label path="interpret" class="control-label">Interpret</form:label>
4333
<div class="controls">

src/main/webapp/WEB-INF/views/edit.jsp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,13 @@
1919
<form:form id="formId" commandName="vinyl" method="post"
2020
class="form-horizontal">
2121
<div class="input-group">
22-
<form:label path="rubrik" class="control-label">Rubrik</form:label>
22+
<form:label path="type" class="control-label">Tontraeger</form:label>
2323
<div class="controls">
24-
<form:select path="rubrik">
25-
<form:options items="${rubrik}"/>
24+
<form:select path="type">
25+
<form:options items="${type}" />
2626
</form:select>
2727
</div>
28-
<form:errors path="rubrik" class="alert alert-danger"/>
29-
</div>
30-
<div class="input-group">
31-
<form:label path="tontraeger" class="control-label">Tontraeger</form:label>
32-
<div class="controls">
33-
<form:select path="tontraeger">
34-
<form:options items="${tontraeger}" />
35-
</form:select>
36-
</div>
37-
<form:errors path="tontraeger" class="alert alert-danger"/>
28+
<form:errors path="type" class="alert alert-danger"/>
3829
</div>
3930

4031
<div class="input-group">

src/main/webapp/WEB-INF/views/new.jsp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,13 @@
1919
<form:form id="formId" commandName="vinyl" method="post"
2020
class="form-horizontal">
2121
<div class="input-group">
22-
<form:label path="rubrik" class="control-label">Rubrik</form:label>
22+
<form:label path="type" class="control-label">Tontraeger</form:label>
2323
<div class="controls">
24-
<form:select path="rubrik">
25-
<form:options items="${rubrik}"/>
24+
<form:select path="type">
25+
<form:options items="${type}" />
2626
</form:select>
2727
</div>
28-
<form:errors path="rubrik" class="alert alert-danger"/>
29-
</div>
30-
<div class="input-group">
31-
<form:label path="tontraeger" class="control-label">Tontraeger</form:label>
32-
<div class="controls">
33-
<form:select path="tontraeger">
34-
<form:options items="${tontraeger}" />
35-
</form:select>
36-
</div>
37-
<form:errors path="tontraeger" class="alert alert-danger"/>
28+
<form:errors path="type" class="alert alert-danger"/>
3829
</div>
3930

4031
<div class="input-group">

0 commit comments

Comments
 (0)