Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
275 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
jpashop2/src/main/java/jpabook/jpashop/domain/Address.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
import lombok.Getter; | ||
|
||
import javax.persistence.Embeddable; | ||
|
||
@Embeddable | ||
@Getter | ||
public class Address { | ||
|
||
private String city; | ||
private String street; | ||
private String zipcode; | ||
|
||
protected Address() { | ||
} | ||
|
||
public Address(String city, String street, String zipcode) { | ||
this.city = city; | ||
this.street = street; | ||
this.zipcode = zipcode; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
jpashop2/src/main/java/jpabook/jpashop/domain/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
import jpabook.jpashop.domain.item.Item; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter @Setter | ||
public class Category { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "category_id") | ||
private Long id; | ||
|
||
private String name; | ||
|
||
@ManyToMany | ||
@JoinTable(name = "category_item", | ||
joinColumns = @JoinColumn(name = "category_id"), | ||
inverseJoinColumns = @JoinColumn(name = "item_id")) | ||
private List<Item> items = new ArrayList<>(); | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "parent_id") | ||
private Category parent; | ||
|
||
@OneToMany(mappedBy = "parent") | ||
private List<Category> child = new ArrayList<>(); | ||
|
||
//==연관관계 메서드==// | ||
public void addChildCategory(Category child) { | ||
this.child.add(child); | ||
child.setParent(this); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
jpashop2/src/main/java/jpabook/jpashop/domain/Delivery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter @Setter | ||
public class Delivery { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "delivery_id") | ||
private Long id; | ||
|
||
@OneToOne(mappedBy = "delivery", fetch = FetchType.LAZY) | ||
private Order order; | ||
|
||
@Embedded | ||
private Address address; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private DeliveryStatus status; //ENUM [READY(준비), COMP(배송)] | ||
} |
5 changes: 5 additions & 0 deletions
5
jpashop2/src/main/java/jpabook/jpashop/domain/DeliveryStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
public enum DeliveryStatus { | ||
READY, COMP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter @Setter | ||
public class Member { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "member_id") | ||
private Long id; | ||
|
||
private String name; | ||
|
||
@Embedded | ||
private Address address; | ||
|
||
@OneToMany(mappedBy = "member") | ||
private List<Order> orders = new ArrayList<>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "orders") | ||
@Getter @Setter | ||
public class Order { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "order_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; //주문 회원 | ||
|
||
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL) | ||
private List<OrderItem> orderItems = new ArrayList<>(); | ||
|
||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
@JoinColumn(name = "delivery_id") | ||
private Delivery delivery; //배송정보 | ||
|
||
private LocalDateTime orderDate; //주문시간 | ||
|
||
@Enumerated(EnumType.STRING) | ||
private OrderStatus status; //주문상태 [ORDER, CANCEL] | ||
|
||
//==연관관계 메서드==// | ||
public void setMember(Member member) { | ||
this.member = member; | ||
member.getOrders().add(this); | ||
} | ||
|
||
public void addOrderItem(OrderItem orderItem) { | ||
orderItems.add(orderItem); | ||
orderItem.setOrder(this); | ||
} | ||
|
||
public void setDelivery(Delivery delivery) { | ||
this.delivery = delivery; | ||
delivery.setOrder(this); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
jpashop2/src/main/java/jpabook/jpashop/domain/OrderItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
import jpabook.jpashop.domain.item.Item; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "order_item") | ||
@Getter @Setter | ||
public class OrderItem { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "order_item_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "item_id") | ||
private Item item; //주문 상품 | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "order_id") | ||
private Order order; //주문 | ||
|
||
private int orderPrice; //주문 가격 | ||
private int count; //주문 수량 | ||
} |
5 changes: 5 additions & 0 deletions
5
jpashop2/src/main/java/jpabook/jpashop/domain/OrderStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package jpabook.jpashop.domain; | ||
|
||
public enum OrderStatus { | ||
ORDER, CANCEL | ||
} |
16 changes: 16 additions & 0 deletions
16
jpashop2/src/main/java/jpabook/jpashop/domain/item/Album.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package jpabook.jpashop.domain.item; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.DiscriminatorValue; | ||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
@DiscriminatorValue("A") | ||
@Getter @Setter | ||
public class Album extends Item { | ||
|
||
private String artist; | ||
private String etc; | ||
} |
15 changes: 15 additions & 0 deletions
15
jpashop2/src/main/java/jpabook/jpashop/domain/item/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package jpabook.jpashop.domain.item; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@DiscriminatorValue("B") | ||
@Getter @Setter | ||
public class Book extends Item { | ||
|
||
private String author; | ||
private String isbn; | ||
} |
27 changes: 27 additions & 0 deletions
27
jpashop2/src/main/java/jpabook/jpashop/domain/item/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package jpabook.jpashop.domain.item; | ||
|
||
import jpabook.jpashop.domain.Category; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
@DiscriminatorColumn(name = "dtype") | ||
@Getter @Setter | ||
public abstract class Item { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "item_id") | ||
private Long id; | ||
|
||
private String name; | ||
private int price; | ||
private int stockQuantity; | ||
|
||
@ManyToMany(mappedBy = "items") | ||
private List<Category> categories = new ArrayList<Category>(); | ||
} |
16 changes: 16 additions & 0 deletions
16
jpashop2/src/main/java/jpabook/jpashop/domain/item/Movie.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package jpabook.jpashop.domain.item; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.DiscriminatorValue; | ||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
@DiscriminatorValue("M") | ||
@Getter @Setter | ||
public class Movie extends Item { | ||
|
||
private String director; | ||
private String actor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters