-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
회원 관련 엔티티 추가 (그리고 H2 환경 추가) #8
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.shopping.jpa.converter; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
@Converter | ||
public class BooleanToYOrNConverter implements AttributeConverter<Boolean, String> { | ||
@Override | ||
public String convertToDatabaseColumn(Boolean attribute) { | ||
return attribute ? "Y" : "N"; | ||
} | ||
|
||
@Override | ||
public Boolean convertToEntityAttribute(String dbData) { | ||
return dbData.equals("Y"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 만약 요즘 NPE 로 고생중이라 JPA 외적인 부분들만 눈에 들어오네요 ㅠㅠ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 최근에 저도 실무에 코딩 가이드 적용하면서 NPE 지적을 엄청 받았으면서 또 이랬어요. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.shopping.jpa.member.model; | ||
|
||
import com.shopping.jpa.converter.BooleanToYOrNConverter; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Setter @Getter | ||
public class Address { | ||
|
||
@Id | ||
@Column(name = "ADDR_ID"/*, columnDefinition = "char(20)"*/) | ||
private Long id; | ||
|
||
@Column(name = "NAME", length = 20, nullable = false) | ||
private String name; | ||
|
||
@Column(name = "ZIPCD", length = 10, nullable = false) | ||
private String zipCode; | ||
|
||
@Column(name = "ADDR", length = 50, nullable = false) | ||
private String address; | ||
|
||
@Column(name = "ADDR_DTL", length = 50, nullable = false) | ||
private String detail; | ||
|
||
@Column(name = "IS_MAS", nullable = false, columnDefinition = "char(1)") | ||
@Convert(converter = BooleanToYOrNConverter.class) | ||
private boolean isMaster; | ||
|
||
@Column(name = "LST_USE_DT") | ||
//@Temporal(TemporalType.TIMESTAMP) | ||
private LocalDateTime lastUsedDateTime; | ||
|
||
@Column(name = "REG_DT") | ||
//@Temporal(TemporalType.TIMESTAMP) | ||
private LocalDateTime registerDateTime; | ||
|
||
@Column(name = "UPT_DT") | ||
//@Temporal(TemporalType.TIMESTAMP) | ||
private LocalDateTime updateDateTime; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "id") | ||
private Member member; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.shopping.jpa.member.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@PrimaryKeyJoinColumn(name = "MID") | ||
@Setter @Getter | ||
public class AdminMember extends Member { | ||
|
||
@Column(name = "PA_IDX", columnDefinition = "char(5)") | ||
private String partCode; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.shopping.jpa.member.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@PrimaryKeyJoinColumn(name = "MID") | ||
@Getter @Setter | ||
public class CommonMember extends Member { | ||
|
||
@Column(name = "GRD_IDX", columnDefinition = "char(5)") | ||
private String gradeCode; | ||
|
||
@OneToMany(mappedBy = "member") | ||
@OrderBy("priority") | ||
private List<Address> addresses = new ArrayList<>(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.shopping.jpa.member.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Table(name = "LOGIN_HIS") | ||
@Setter @Getter | ||
public class LoginHistory { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer seq; | ||
|
||
@Column(nullable = false, columnDefinition = "char(5)") | ||
@Enumerated(value = EnumType.STRING) | ||
private LoginResult result; | ||
|
||
@Column(name = "REG_IP", nullable = false, length = 30) | ||
private String ip; | ||
|
||
@Column(name = "REG_DT") | ||
//@Temporal(TemporalType.TIMESTAMP) | ||
private LocalDateTime registerDateTime; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "id") | ||
private Member member; | ||
|
||
|
||
@Converter(autoApply = true) | ||
public static class LoginResultConverter implements AttributeConverter<LoginResult, String> { | ||
@Override | ||
public String convertToDatabaseColumn(LoginResult attribute) { | ||
return attribute.getValue(); | ||
} | ||
|
||
@Override | ||
public LoginResult convertToEntityAttribute(String dbData) { | ||
return LoginResult.valueOf(dbData); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.shopping.jpa.member.model; | ||
|
||
public enum LoginResult { | ||
SUCCESS("00000"), | ||
FAILURE("99999"), | ||
EXPIRED("99998"), | ||
DENIED("99997"); | ||
|
||
private String value; | ||
|
||
LoginResult(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.shopping.jpa.member.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
@Setter @Getter | ||
public abstract class Member { | ||
|
||
@Id | ||
@GeneratedValue | ||
@Column(name = "MID", columnDefinition = "char(10)") | ||
private String id; | ||
|
||
@Column(name = "UID", length = 50, unique = true, nullable = false) | ||
private String username; | ||
|
||
@Column(name = "PWD", length = 100,nullable = false) | ||
private String password; | ||
|
||
@Column(name = "NAME", length = 20, nullable = false) | ||
private String name; | ||
|
||
@Column(name = "REG_DT", nullable = false) | ||
//@Temporal(TemporalType.TIMESTAMP) | ||
private LocalDateTime registerDate; | ||
|
||
@Column(name = "ADDR_USE_IDX", nullable = false, columnDefinition = "char(5)") | ||
private String addressUseIndex; | ||
|
||
@OneToMany(mappedBy = "member") | ||
private List<LoginHistory> loginHistories = new ArrayList<>(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
spring: | ||
|
||
jpa: | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: create | ||
|
||
datasource: | ||
hikari: | ||
driver-class-name: org.h2.Driver | ||
jdbc-url: jdbc:h2:tcp://localhost/~/shopping-site | ||
username: sa | ||
password: "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttributeConverter
라니..! 새로운걸 배워갑니다!그런데 만약
Boolean attribute
가null
이면 조건식이 어떻게 되는건가요?별도의 NPE 체크 없이 사용 가능한가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
당연히 안되겠죠^^;
좋은 지적 감사합니다, 수정할게요. 항상 대충하는 버릇이...
코드 리뷰 하니까 좋네요, 성준님😍