Commit 069a0012a16bae69ef092b7695a0d61189e408de

Authored by rvangrev
1 parent 24e5d678

Annotations ajoutées

Méthodes findByXX Ajoutées
src/main/java/fr/plil/sio/examen/api/Animal.java
... ... @@ -6,22 +6,26 @@ import javax.persistence.Entity;
6 6 import javax.persistence.GeneratedValue;
7 7 import javax.persistence.GenerationType;
8 8 import javax.persistence.Id;
  9 +import javax.persistence.JoinColumn;
9 10 import javax.persistence.ManyToOne;
  11 +import javax.persistence.Table;
10 12  
11 13 /**
12 14 * An animal must have a name one and only one owner
13 15 */
14 16 @Entity
  17 +@Table(name="ANIMAL_T")
15 18 public class Animal implements Serializable {
16 19  
17 20 @Id
18 21 @GeneratedValue(strategy = GenerationType.AUTO)
19 22 private Long id;
20 23  
21   - @Column(nullable = false)
  24 + @Column(name="NAME_A",nullable = false)
22 25 private String name;
23 26  
24 27 @ManyToOne(optional = false)
  28 + @JoinColumn(name="OWNER_ID")
25 29 private Owner owner;
26 30  
27 31 public Long getId() {
... ...
src/main/java/fr/plil/sio/examen/api/Comment.java
1 1 package fr.plil.sio.examen.api;
2 2  
  3 +import javax.persistence.Column;
  4 +import javax.persistence.Entity;
  5 +import javax.persistence.GeneratedValue;
  6 +import javax.persistence.GenerationType;
  7 +import javax.persistence.Id;
  8 +import javax.persistence.JoinColumn;
  9 +import javax.persistence.ManyToOne;
  10 +import javax.persistence.OneToOne;
  11 +import javax.persistence.Table;
  12 +
3 13 /**
4 14 * A comment is made by an reporter (i.e. an owner) on ANY animal
5 15 * (not only the ones he owns).
... ... @@ -11,11 +21,22 @@ package fr.plil.sio.examen.api;
11 21 * TODO: complete the classes in API to support comment serialization in the
12 22 * database.
13 23 */
  24 +@Entity
  25 +@Table(name="COMMENT_T")
14 26 public class Comment {
15 27  
  28 + @Id
  29 + @GeneratedValue(strategy = GenerationType.AUTO)
  30 + private Long id;
  31 +
  32 + @ManyToOne(optional = false)
  33 + @JoinColumn(name="OWNER_ID")
16 34 private Owner reporter;
17 35  
  36 + @ManyToOne(optional = false)
  37 + @JoinColumn(name="ANIMAL_ID")
18 38 private Animal animal;
19 39  
  40 + @Column(nullable = false)
20 41 private String message;
21 42 }
... ...
src/main/java/fr/plil/sio/examen/api/Owner.java
... ... @@ -8,18 +8,20 @@ import javax.persistence.GeneratedValue;
8 8 import javax.persistence.GenerationType;
9 9 import javax.persistence.Id;
10 10 import javax.persistence.OneToMany;
  11 +import javax.persistence.Table;
11 12  
12 13 /**
13 14 * An owner has a name and zero, one or more animals.
14 15 */
15 16 @Entity
  17 +@Table(name="OWNER_T")
16 18 public class Owner {
17 19  
18 20 @Id
19 21 @GeneratedValue(strategy = GenerationType.AUTO)
20 22 private Long id;
21 23  
22   - @Column(nullable = false)
  24 + @Column(name="NAME_O",nullable = false)
23 25 private String name;
24 26  
25 27 @OneToMany(mappedBy = "owner")
... ...
src/main/java/fr/plil/sio/examen/repositories/AnimalRepository.java
... ... @@ -13,4 +13,8 @@ public interface AnimalRepository extends JpaRepository<Animal,Long> {
13 13 * about other kind of object ?).
14 14 */
15 15 List<Animal> findByOwner(Owner owner);
  16 +
  17 + List<Animal> findByName(String name);
  18 +
  19 +// Animal findById(Long id);
16 20 }
... ...
src/main/java/fr/plil/sio/examen/repositories/CommentRepository.java
1 1 package fr.plil.sio.examen.repositories;
2 2  
3 3 import fr.plil.sio.examen.api.Comment;
  4 +import fr.plil.sio.examen.api.Owner;
  5 +import fr.plil.sio.examen.api.Animal;
  6 +import java.util.List;
4 7 import org.springframework.data.jpa.repository.JpaRepository;
5 8  
6 9 /**
7 10 * TODO: complete this interface for new find methods.
8 11 */
9 12 public interface CommentRepository extends JpaRepository<Comment, Long>{
  13 +
  14 + List<Comment> findByOwner(Owner owner);
  15 +
  16 + List<Comment> findByAnimal(Animal animal);
  17 +
  18 + List<Comment> findByMessage(String message);
  19 +
  20 +// Comment findById(Long id);
10 21 }
... ...
src/main/java/fr/plil/sio/examen/repositories/OwnerRepository.java
1 1 package fr.plil.sio.examen.repositories;
2 2  
3 3 import fr.plil.sio.examen.api.Owner;
  4 +import java.util.List;
4 5 import org.springframework.data.jpa.repository.JpaRepository;
5 6  
6 7 public interface OwnerRepository extends JpaRepository<Owner, Long>{
7 8  
  9 + List<Owner> findByName(String name);
  10 +
  11 +// Owner findById(Long id);
8 12 }
... ...