summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-27 05:33:15 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-01-27 05:40:56 +0100
commit553de3e77067ce6090cf8edacdc697791e03a1a5 (patch)
treefb599f7cb1f1ae5a052b707717951e7524af8761
parentacaa0570c91a2048bab3c3786dbcc8eea6d2e4d0 (diff)
Benki: Clean up the data model mapping some more.
- Replaces user attribute table mappings with element collections and join table mappings. - Adds an explicit schema specifier to all join table specifiers. Change-Id: I0e251e1939faa895155cbe868220d98be2c1e70c
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java4
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java1
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/OpenId.java23
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/RsaKey.java14
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/User.java46
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/UserEmailAddress.java23
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/UserJid.java29
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/UserJidPK.java59
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/UserNickname.java23
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/users/WebId.java23
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java1
11 files changed, 47 insertions, 199 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java b/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java
index 73648dc..200997e 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java
@@ -37,6 +37,7 @@ public class Role extends PanacheEntityBase {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "role_subroles",
+ schema = "benki",
joinColumns = @JoinColumn(name = "superrole"),
inverseJoinColumns = @JoinColumn(name = "subrole"))
public Set<Role> directSubroles;
@@ -47,6 +48,7 @@ public class Role extends PanacheEntityBase {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "effective_role_subroles",
+ schema = "benki",
joinColumns = @JoinColumn(name = "superrole"),
inverseJoinColumns = @JoinColumn(name = "subrole"))
public Set<Role> effectiveSubroles;
@@ -67,7 +69,7 @@ public class Role extends PanacheEntityBase {
public Collection<User> effectiveUsers;
@ElementCollection(fetch = FetchType.LAZY)
- @CollectionTable(name = "role_tags", joinColumns = @JoinColumn(name = "role"))
+ @CollectionTable(name = "role_tags", schema = "benki", joinColumns = @JoinColumn(name = "role"))
@Column(name = "tag")
public Set<String> tags;
}
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 a9a5ebd..309fb67 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
@@ -35,6 +35,7 @@ public abstract class Post extends PanacheEntityBase {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "user_visible_posts",
+ schema = "benki",
joinColumns = @JoinColumn(name = "message"),
inverseJoinColumns = @JoinColumn(name = "user"))
public Set<User> visibleTo;
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/OpenId.java b/src/main/java/eu/mulk/mulkcms2/benki/users/OpenId.java
deleted file mode 100644
index bb41dda..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/OpenId.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package eu.mulk.mulkcms2.benki.users;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-@Entity(name = "BenkiOpenId")
-@Table(name = "openids", schema = "benki")
-public class OpenId extends PanacheEntityBase {
-
- @Id
- @Column(name = "openid", nullable = false, length = -1)
- public String openid;
-
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "user", referencedColumnName = "id", nullable = false)
- public User user;
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKey.java b/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKey.java
index 9dd7931..d03597b 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKey.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/users/RsaKey.java
@@ -2,13 +2,14 @@ package eu.mulk.mulkcms2.benki.users;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import java.math.BigInteger;
-import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
-import javax.persistence.OneToMany;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@@ -24,6 +25,11 @@ public class RsaKey extends PanacheEntityBase {
@Column(name = "exponent", nullable = false, precision = 0)
public BigInteger exponent;
- @OneToMany(mappedBy = "rsaKey", fetch = FetchType.LAZY)
- public Collection<UserRsaKey> users;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinTable(
+ name = "user_rsa_keys",
+ schema = "benki",
+ joinColumns = {@JoinColumn(name = "modulus"), @JoinColumn(name = "exponent")},
+ inverseJoinColumns = @JoinColumn(name = "user"))
+ public User user;
}
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 e16a111..40e5364 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/User.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/users/User.java
@@ -9,11 +9,14 @@ import eu.mulk.mulkcms2.benki.wiki.WikiPageRevision;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import java.util.Collection;
import java.util.Set;
+import javax.persistence.CollectionTable;
import javax.persistence.Column;
+import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
@@ -52,8 +55,10 @@ public class User extends PanacheEntityBase {
@OneToMany(mappedBy = "owner", fetch = FetchType.LAZY)
public Collection<LazychatMessage> lazychatMessages;
- @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
- public Collection<OpenId> openids;
+ @ElementCollection(fetch = FetchType.LAZY)
+ @CollectionTable(name = "openids", schema = "benki", joinColumns = @JoinColumn(name = "user"))
+ @Column(name = "openid")
+ public Collection<String> openids;
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
public Collection<PageKey> pageKeys;
@@ -64,27 +69,41 @@ public class User extends PanacheEntityBase {
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
public Collection<UserDefaultTarget> defaultTargets;
- @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
- public Collection<UserEmailAddress> emailAddresses;
-
- @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
- public Collection<UserJid> jids;
-
- @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
- public Collection<UserNickname> nicknames;
+ @ElementCollection(fetch = FetchType.LAZY)
+ @CollectionTable(
+ name = "user_email_addresses",
+ schema = "benki",
+ joinColumns = @JoinColumn(name = "user"))
+ @Column(name = "email")
+ public Collection<String> emailAddresses;
+
+ @ElementCollection(fetch = FetchType.LAZY)
+ @CollectionTable(name = "user_jids", schema = "benki", joinColumns = @JoinColumn(name = "user"))
+ @Column(name = "jid")
+ public Collection<String> jids;
+
+ @ElementCollection(fetch = FetchType.LAZY)
+ @CollectionTable(
+ name = "user_nicknames",
+ schema = "benki",
+ joinColumns = @JoinColumn(name = "user"))
+ @Column(name = "nickname")
+ public Collection<String> nicknames;
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
public Collection<UserRole> directRoles;
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
- public Collection<UserRsaKey> rsaKeys;
+ public Collection<RsaKey> rsaKeys;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role", referencedColumnName = "id", nullable = false)
public Role ownedRole;
- @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
- public Collection<WebId> webids;
+ @ElementCollection(fetch = FetchType.LAZY)
+ @CollectionTable(name = "webids", schema = "benki", joinColumns = @JoinColumn(name = "user"))
+ @Column(name = "webid")
+ public Collection<String> webids;
@OneToMany(mappedBy = "author", fetch = FetchType.LAZY)
public Collection<WikiPageRevision> wikiPageRevisions;
@@ -95,6 +114,7 @@ public class User extends PanacheEntityBase {
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "effective_user_roles",
+ schema = "benki",
joinColumns = @JoinColumn(name = "user"),
inverseJoinColumns = @JoinColumn(name = "role"))
public Set<Role> effectiveRoles;
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/UserEmailAddress.java b/src/main/java/eu/mulk/mulkcms2/benki/users/UserEmailAddress.java
deleted file mode 100644
index 383c382..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/UserEmailAddress.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package eu.mulk.mulkcms2.benki.users;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "user_email_addresses", schema = "benki")
-public class UserEmailAddress extends PanacheEntityBase {
-
- @Id
- @Column(name = "email", nullable = false, length = -1)
- public String email;
-
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "user", referencedColumnName = "id", nullable = false)
- public User user;
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/UserJid.java b/src/main/java/eu/mulk/mulkcms2/benki/users/UserJid.java
deleted file mode 100644
index 867583c..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/UserJid.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package eu.mulk.mulkcms2.benki.users;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.IdClass;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "user_jids", schema = "benki")
-@IdClass(UserJidPK.class)
-public class UserJid extends PanacheEntityBase {
-
- @Id
- @Column(name = "user", nullable = false)
- public int userId;
-
- @Id
- @Column(name = "jid", nullable = false, length = -1)
- public String jid;
-
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "user", referencedColumnName = "id", nullable = false)
- public User user;
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/UserJidPK.java b/src/main/java/eu/mulk/mulkcms2/benki/users/UserJidPK.java
deleted file mode 100644
index 19eeaeb..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/UserJidPK.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package eu.mulk.mulkcms2.benki.users;
-
-import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Id;
-
-public class UserJidPK implements Serializable {
-
- private int userId;
- private String jid;
-
- @Column(name = "user", nullable = false)
- @Id
- public int getUserId() {
- return userId;
- }
-
- public void setUserId(int userId) {
- this.userId = userId;
- }
-
- @Column(name = "jid", nullable = false, length = -1)
- @Id
- public String getJid() {
- return jid;
- }
-
- public void setJid(String jid) {
- this.jid = jid;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- UserJidPK userJidPK = (UserJidPK) o;
-
- if (userId != userJidPK.userId) {
- return false;
- }
- if (jid != null ? !jid.equals(userJidPK.jid) : userJidPK.jid != null) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = userId;
- result = 31 * result + (jid != null ? jid.hashCode() : 0);
- return result;
- }
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/UserNickname.java b/src/main/java/eu/mulk/mulkcms2/benki/users/UserNickname.java
deleted file mode 100644
index 05a8004..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/UserNickname.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package eu.mulk.mulkcms2.benki.users;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "user_nicknames", schema = "benki")
-public class UserNickname extends PanacheEntityBase {
-
- @Id
- @Column(name = "nickname", nullable = false, length = -1)
- public String nickname;
-
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "user", referencedColumnName = "id", nullable = false)
- public User user;
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/WebId.java b/src/main/java/eu/mulk/mulkcms2/benki/users/WebId.java
deleted file mode 100644
index 9a8728c..0000000
--- a/src/main/java/eu/mulk/mulkcms2/benki/users/WebId.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package eu.mulk.mulkcms2.benki.users;
-
-import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "webids", schema = "benki")
-public class WebId extends PanacheEntityBase {
-
- @Id
- @Column(name = "webid", nullable = false, length = -1)
- public String webid;
-
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "user", referencedColumnName = "id", nullable = false)
- public User user;
-}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
index 10112db..b5ece7e 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -24,7 +24,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jboss.logging.Logger;
-import org.jboss.resteasy.spi.NotImplementedYetException;
@Path("/wiki")
public class WikiResource {