Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. package hibernate.model;
  2.  
  3. import javax.persistence.*;
  4. import java.io.Serializable;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.stream.Collectors;
  8.  
  9. /**
  10. *
  11. * @author Arvid Kirkbakk
  12. * @author Mats Sollid Eide
  13. */
  14. @Entity
  15. @Table(name = "albums")
  16. @NamedQueries({
  17. @NamedQuery(name="Album.count", query="SELECT COUNT(a) FROM Album a"),
  18. @NamedQuery(name="Album.findAll", query="SELECT a FROM Album a")
  19. })
  20.  
  21. public class Album implements Serializable {
  22. @Id
  23. @GeneratedValue(strategy = GenerationType.IDENTITY)
  24. @Column(name = "albumid", insertable = false, updatable = false)
  25. private int albumid;
  26.  
  27. // Karl: Database stuff
  28. @Column(name = "title", nullable = false)
  29. private String title;
  30.  
  31. @ManyToOne(fetch = FetchType.LAZY)
  32. @JoinColumn(name = "userid", nullable = false)
  33. private User user;
  34.  
  35. @ManyToMany(fetch = FetchType.EAGER)
  36. @OrderBy("imageid DESC")
  37. private List<ImageData> images = new ArrayList<>();
  38.  
  39.  
  40. //todo: getters and setters
  41. public int getAlbumID(){
  42. return albumid;
  43. }
  44.  
  45. /**
  46. * set new album title
  47. * @param newTitle new album title
  48. */
  49. public void setTitle(String newTitle){
  50. this.title = newTitle;
  51. }
  52.  
  53. public String getTitle(){
  54. return title;
  55. }
  56.  
  57. // Might not be necessary
  58. public User getUser(){
  59. return user;
  60. }
  61.  
  62. public void addImage(ImageData image){
  63. images.add(image);
  64. }
  65.  
  66. public void removeImage(ImageData image){
  67. for(ImageData img : images){
  68. if(img.equals(image)) {
  69. images.remove(images.indexOf(image));
  70. }
  71. }
  72.  
  73.  
  74. //images = images.stream().filter(img -> !(img.equals(image))).collect(Collectors.toList());
  75. }
  76.  
  77. public void clear(){
  78. images.clear();
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement