summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-24 11:51:35 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-24 11:51:35 +0100
commitf9c742762bc08db7c3518e7d44cf7382b353d560 (patch)
treea1a08cf5a3c624489c4cac1a18eea54b75785686 /src/main
parentd9b9588f03ec77d05e5651a88d672184c8b351a5 (diff)
Replace UserVisible{Bookmark,Post,LazychatMessage} with a @ManyToMany.
Change-Id: Ie807f3eed9da1e5bcaefb10104d989f3b3ddbf7b
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/bookmarx/UserVisibleBookmark.java41
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java11
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/generic/UserVisiblePost.java41
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lafargue/UserVisibleLazychatMessage.java41
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/User.java4
5 files changed, 15 insertions, 123 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarx/UserVisibleBookmark.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarx/UserVisibleBookmark.java
deleted file mode 100644
index 589e62a..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarx/UserVisibleBookmark.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package eu.mulk.mulkcms2.benki.bookmarx;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import java.io.Serializable;
-import java.util.Objects;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import org.hibernate.annotations.Immutable;
-
-@Entity
-@Immutable
-@Table(name = "user_visible_bookmarks", schema = "public", catalog = "benki")
-public class UserVisibleBookmark extends PanacheEntityBase implements Serializable {
-
- @Id
- @Column(name = "user", nullable = true)
- public Integer userId;
-
- @Id
- @Column(name = "message", nullable = true)
- public Integer messageId;
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof UserVisibleBookmark)) {
- return false;
- }
- UserVisibleBookmark that = (UserVisibleBookmark) o;
- return Objects.equals(userId, that.userId) && Objects.equals(messageId, that.messageId);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(userId, messageId);
- }
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
index 050cdcb..bfa02d2 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
@@ -3,12 +3,16 @@ package eu.mulk.mulkcms2.benki.generic;
import eu.mulk.mulkcms2.benki.users.User;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import java.time.OffsetDateTime;
+import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@@ -27,4 +31,11 @@ public abstract class Post extends PanacheEntityBase {
@ManyToOne
@JoinColumn(name = "owner", referencedColumnName = "id")
public User owner;
+
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(
+ name = "user_visible_posts",
+ joinColumns = @JoinColumn(name = "message"),
+ inverseJoinColumns = @JoinColumn(name = "user"))
+ public Set<User> visibleTo;
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/generic/UserVisiblePost.java b/src/main/java/eu/mulk/mulkcms2/benki/generic/UserVisiblePost.java
deleted file mode 100644
index 2b09120..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/generic/UserVisiblePost.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package eu.mulk.mulkcms2.benki.generic;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import java.io.Serializable;
-import java.util.Objects;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import org.hibernate.annotations.Immutable;
-
-@Entity
-@Immutable
-@Table(name = "user_visible_posts", schema = "public", catalog = "benki")
-public class UserVisiblePost extends PanacheEntityBase implements Serializable {
-
- @Id
- @Column(name = "user", nullable = true)
- public Integer userId;
-
- @Id
- @Column(name = "message", nullable = true)
- public Integer messageId;
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof UserVisiblePost)) {
- return false;
- }
- UserVisiblePost that = (UserVisiblePost) o;
- return Objects.equals(userId, that.userId) && Objects.equals(messageId, that.messageId);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(userId, messageId);
- }
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lafargue/UserVisibleLazychatMessage.java b/src/main/java/eu/mulk/mulkcms2/benki/lafargue/UserVisibleLazychatMessage.java
deleted file mode 100644
index 0570aae..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/lafargue/UserVisibleLazychatMessage.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package eu.mulk.mulkcms2.benki.lafargue;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import java.io.Serializable;
-import java.util.Objects;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import org.hibernate.annotations.Immutable;
-
-@Entity
-@Immutable
-@Table(name = "user_visible_lazychat_messages", schema = "public", catalog = "benki")
-public class UserVisibleLazychatMessage extends PanacheEntityBase implements Serializable {
-
- @Id
- @Column(name = "user", nullable = true)
- public Integer userId;
-
- @Id
- @Column(name = "message", nullable = true)
- public Integer messageId;
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof UserVisibleLazychatMessage)) {
- return false;
- }
- UserVisibleLazychatMessage that = (UserVisibleLazychatMessage) o;
- return Objects.equals(userId, that.userId) && Objects.equals(messageId, that.messageId);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(userId, messageId);
- }
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/User.java b/src/main/java/eu/mulk/mulkcms2/benki/users/User.java
index fb1ed3b..11c01fb 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/User.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/users/User.java
@@ -12,6 +12,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@@ -84,4 +85,7 @@ public class User extends PanacheEntityBase {
@OneToMany(mappedBy = "author")
public Collection<WikiPageRevision> wikiPageRevisions;
+
+ @ManyToMany(mappedBy = "visibleTo")
+ public Collection<Post> visiblePosts;
}