Add most XML annotations

Some things aren't working yet...
This commit is contained in:
karl 2019-11-28 19:20:21 +01:00
parent a870c28d21
commit b7a21d4be2
6 changed files with 40 additions and 12 deletions

6
.idea/compiler.xml generated
View File

@ -13,9 +13,9 @@
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>
<module name="MoviesApp" target="11" /> <module name="MoviesApp" target="11" />
<module name="MoviesClient" target="9" /> <module name="MoviesClient" target="11" />
<module name="MoviesCommon" target="9" /> <module name="MoviesCommon" target="11" />
<module name="MoviesWebApp" target="9" /> <module name="MoviesWebApp" target="11" />
</bytecodeTargetLevel> </bytecodeTargetLevel>
</component> </component>
</project> </project>

View File

@ -23,21 +23,24 @@ import java.time.LocalDate;
) )
@XmlRootElement @XmlRootElement
public class Actors { public class Actors {
@XmlAttribute(name = "id")
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@Column(length = 100, nullable = false) @Column(length = 100, nullable = false)
@XmlAttribute
private String firstname; private String firstname;
@Column(length = 100, nullable = false) @Column(length = 100, nullable = false)
@XmlAttribute
private String lastname; private String lastname;
@Column(nullable = false) @Column(nullable = false)
@XmlAttribute
private Sex sex; private Sex sex;
@Column(nullable = false) @Column(nullable = false)
@XmlAttribute
private LocalDate birthdate; private LocalDate birthdate;
public Actors(String firstname, String lastname, Sex sex, LocalDate birthdate) { public Actors(String firstname, String lastname, Sex sex, LocalDate birthdate) {

View File

@ -4,6 +4,8 @@ import lombok.*;
import javax.persistence.*; import javax.persistence.*;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
@ -24,11 +26,8 @@ import java.util.List;
) )
@XmlRootElement @XmlRootElement
public class Movies { public class Movies {
// TODO: XmlAttributes may need different names
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@XmlAttribute
private Long id; private Long id;
@Column(length = 100, nullable = false) @Column(length = 100, nullable = false)
@ -56,10 +55,13 @@ public class Movies {
name = "t_movies_actors", name = "t_movies_actors",
joinColumns = @JoinColumn(name = "fk_movies_id"), joinColumns = @JoinColumn(name = "fk_movies_id"),
inverseJoinColumns = @JoinColumn(name = "fk_actors_id")) inverseJoinColumns = @JoinColumn(name = "fk_actors_id"))
@XmlElementWrapper(name = "actors")
@XmlElement(name = "actor")
private List<Actors> actors; private List<Actors> actors;
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fk_studios_id") @JoinColumn(name = "fk_studios_id")
@XmlElement
private Studios studio; private Studios studio;
public Movies(String title, String description, Genre genre, int length, int releaseyear) { public Movies(String title, String description, Genre genre, int length, int releaseyear) {

View File

@ -3,6 +3,8 @@ package at.technikumwien.movies;
import lombok.*; import lombok.*;
import javax.persistence.*; import javax.persistence.*;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -10,22 +12,23 @@ import javax.persistence.*;
@Entity @Entity
@Table(name = "t_studios") @Table(name = "t_studios")
@XmlRootElement
public class Studios { public class Studios {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@Column(length = 100, nullable = false) @Column(length = 100, nullable = false)
@XmlAttribute
private String name; private String name;
@XmlAttribute
private String countrycode; private String countrycode;
@XmlAttribute
private String postcode; private String postcode;
public Studios(String name, String countrycode, String postcode) { public Studios(String name, String countrycode, String postcode) {
this(null, name, countrycode, postcode); this(null, name, countrycode, postcode);
} }
//TODO consider using
//@ManyToMany(mappedBy = 'at.technikumwien.movies.Studios')
//private List<at.technikumwien.movies.Movies> movies
} }

View File

@ -0,0 +1,19 @@
package at.technikumwien.movies;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class LocalDateAdapter extends XmlAdapter<String, LocalDate> {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy");
@Override
public LocalDate unmarshal(String s) throws Exception {
return LocalDate.parse(s, FORMATTER);
}
@Override
public String marshal(LocalDate localDate) throws Exception {
return FORMATTER.format(localDate);
}
}

View File

@ -1,7 +1,8 @@
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@XmlJavaTypeAdapter(LocalDateAdapter.class)
package at.technikumwien.movies; package at.technikumwien.movies;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;