-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add entity listener event created and updated
- Loading branch information
1 parent
3731872
commit 3f4cc56
Showing
16 changed files
with
360 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +0,0 @@ | ||
CREATE TABLE users ( | ||
id CHARACTER VARYING(100) NOT NULL PRIMARY KEY, | ||
email CHARACTER VARYING(150) NOT NULL, | ||
name CHARACTER VARYING(150) NOT NULL, | ||
birthday DATE NOT NULL, | ||
password CHARACTER VARYING(150) NOT NULL | ||
); | ||
|
||
CREATE TABLE artists ( | ||
id CHARACTER VARYING(100) NOT NULL PRIMARY KEY, | ||
name CHARACTER VARYING(150) NOT NULL, | ||
instagram CHARACTER VARYING(150), | ||
facebook CHARACTER VARYING(150), | ||
twitter CHARACTER VARYING(150), | ||
wikipedia CHARACTER VARYING(150), | ||
bio TEXT | ||
); | ||
|
||
CREATE TABLE albums ( | ||
id CHARACTER VARYING(100) NOT NULL PRIMARY KEY, | ||
title CHARACTER VARYING(150) NOT NULL, | ||
release CHARACTER VARYING(150) NOT NULL, | ||
image CHARACTER VARYING(150) NOT NULL | ||
); | ||
|
||
SELECT * FROM albums; | ||
|
||
CREATE TABLE songs ( | ||
id CHARACTER VARYING(100) NOT NULL PRIMARY KEY, | ||
album_id CHARACTER VARYING(150) NOT NULL, | ||
title CHARACTER VARYING(150) NOT NULL, | ||
duration INT NOT NULL, | ||
CONSTRAINT fk_albums_songs FOREIGN KEY (album_id) REFERENCES albums(id) | ||
); | ||
|
||
SELECT * FROM songs; | ||
|
||
CREATE TABLE concerts ( | ||
id CHARACTER VARYING(100) NOT NULL PRIMARY KEY, | ||
location CHARACTER VARYING(150) NOT NULL, | ||
lon DOUBLE PRECISION, | ||
lat DOUBLE PRECISION, | ||
event_at TIMESTAMP NOT NULL , | ||
url CHARACTER VARYING(150)NOT NULL | ||
); | ||
82 changes: 59 additions & 23 deletions
82
src/main/java/com/yeahbutstill/kepotify/entity/BaseEntity.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 |
---|---|---|
@@ -1,40 +1,76 @@ | ||
package com.yeahbutstill.kepotify.entity; | ||
|
||
import com.yeahbutstill.kepotify.enums.StatusRecord; | ||
import com.yeahbutstill.kepotify.listener.UpdatedCreatedAtAware; | ||
import com.yeahbutstill.kepotify.listener.impl.UpdatedCreatedAtListener; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
import org.hibernate.Hibernate; | ||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedBy; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
@MappedSuperclass | ||
@Getter | ||
@Setter | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class BaseEntity { | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@ToString | ||
@EntityListeners({ | ||
AuditingEntityListener.class, | ||
UpdatedCreatedAtListener.class | ||
}) | ||
public class BaseEntity implements UpdatedCreatedAtAware { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.UUID) | ||
private UUID id; | ||
|
||
// @CreatedBy | ||
// private String createdBy; | ||
// | ||
// @LastModifiedBy | ||
// private String updatedBy; | ||
// | ||
// @CreatedDate | ||
// private LocalDateTime created; | ||
// | ||
// @LastModifiedDate | ||
// private LocalDateTime updated; | ||
// | ||
// @NotBlank | ||
// @NotEmpty | ||
// private String environment; | ||
// | ||
// @NotNull | ||
// @Enumerated(EnumType.STRING) | ||
// private StatusRecord statusRecord = StatusRecord.ACTIVE; | ||
@CreatedBy | ||
@Column(name = "created_by") | ||
private String createdBy; | ||
|
||
@LastModifiedBy | ||
@Column(name = "updated_by") | ||
private String updatedBy; | ||
|
||
@CreatedDate | ||
@Column(name = "created_at") | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@Column(name = "updated_at") | ||
private LocalDateTime updatedAt; | ||
|
||
@NotBlank | ||
@NotEmpty | ||
private String environment; | ||
|
||
@NotNull | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "status_record") | ||
private StatusRecord statusRecord = StatusRecord.ACTIVE; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false; | ||
BaseEntity that = (BaseEntity) o; | ||
return getId() != null && Objects.equals(getId(), that.getId()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return getClass().hashCode(); | ||
} | ||
|
||
} |
Oops, something went wrong.