-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
f0b3882
commit 5860cbc
Showing
7 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
...ql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/entities/PostTag.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,52 @@ | ||
package com.example.graphql.querydsl.entities; | ||
|
||
import jakarta.persistence.*; | ||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Entity(name = "PostTag") | ||
@Table(name = "post_tags") | ||
@Setter | ||
@Getter | ||
public class PostTag { | ||
|
||
@EmbeddedId | ||
private PostTagId id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@MapsId("postId") | ||
private Post post; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@MapsId("tagId") | ||
private Tag tag; | ||
|
||
@Column(name = "created_on") | ||
private LocalDateTime createdOn = LocalDateTime.now(); | ||
|
||
public PostTag(Post post, Tag tag) { | ||
this.post = post; | ||
this.tag = tag; | ||
this.id = new PostTagId(post.getId(), tag.getId()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
PostTag that = (PostTag) o; | ||
return Objects.equals(this.post, that.post) && Objects.equals(this.tag, that.tag); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.post, this.tag); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/entities/PostTagId.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,45 @@ | ||
package com.example.graphql.querydsl.entities; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Embeddable | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PostTagId implements Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Column(name = "post_id") | ||
private Long postId; | ||
|
||
@Column(name = "tag_id") | ||
private Long tagId; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
PostTagId that = (PostTagId) o; | ||
return Objects.equals(this.postId, that.postId) && Objects.equals(this.tagId, that.tagId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.postId, this.tagId); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
...-graphql-querydsl/src/main/resources/db/changelog/migration/05-create_post_tags_table.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- https://docs.liquibase.com/concepts/changelogs/xml-format.html --> | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.20.xsd"> | ||
|
||
<property name="string.type" value="varchar(255)" dbms="!postgresql"/> | ||
<property name="string.type" value="text" dbms="postgresql"/> | ||
|
||
<changeSet author="app" id="createTable-post_tags"> | ||
<createTable tableName="post_tags"> | ||
<column name="created_on" type="DATETIME"/> | ||
<column name="post_id" type="BIGINT"> | ||
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_post_tag"/> | ||
</column> | ||
<column name="tag_id" type="BIGINT"> | ||
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_post_tag"/> | ||
</column> | ||
</createTable> | ||
|
||
<addForeignKeyConstraint baseColumnNames="post_id" baseTableName="post_tags" constraintName="FK_POST_TAG_ON_POST" | ||
referencedColumnNames="id" referencedTableName="posts"/> | ||
<addForeignKeyConstraint baseColumnNames="tag_id" baseTableName="post_tags" constraintName="FK_POST_TAG_ON_TAG" | ||
referencedColumnNames="id" referencedTableName="tags"/> | ||
</changeSet> | ||
</databaseChangeLog> |
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