From 553de3e77067ce6090cf8edacdc697791e03a1a5 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 27 Jan 2020 05:33:15 +0100 Subject: 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 --- .../eu/mulk/mulkcms2/benki/accesscontrol/Role.java | 4 +- .../java/eu/mulk/mulkcms2/benki/generic/Post.java | 1 + .../java/eu/mulk/mulkcms2/benki/users/OpenId.java | 23 --------- .../java/eu/mulk/mulkcms2/benki/users/RsaKey.java | 14 +++-- .../java/eu/mulk/mulkcms2/benki/users/User.java | 46 ++++++++++++----- .../mulkcms2/benki/users/UserEmailAddress.java | 23 --------- .../java/eu/mulk/mulkcms2/benki/users/UserJid.java | 29 ----------- .../eu/mulk/mulkcms2/benki/users/UserJidPK.java | 59 ---------------------- .../eu/mulk/mulkcms2/benki/users/UserNickname.java | 23 --------- .../java/eu/mulk/mulkcms2/benki/users/WebId.java | 23 --------- .../eu/mulk/mulkcms2/benki/wiki/WikiResource.java | 1 - 11 files changed, 47 insertions(+), 199 deletions(-) delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/users/OpenId.java delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/users/UserEmailAddress.java delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/users/UserJid.java delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/users/UserJidPK.java delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/users/UserNickname.java delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/users/WebId.java (limited to 'src/main') 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 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 effectiveSubroles; @@ -67,7 +69,7 @@ public class Role extends PanacheEntityBase { public Collection 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 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 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 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 lazychatMessages; - @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) - public Collection openids; + @ElementCollection(fetch = FetchType.LAZY) + @CollectionTable(name = "openids", schema = "benki", joinColumns = @JoinColumn(name = "user")) + @Column(name = "openid") + public Collection openids; @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) public Collection pageKeys; @@ -64,27 +69,41 @@ public class User extends PanacheEntityBase { @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) public Collection defaultTargets; - @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) - public Collection emailAddresses; - - @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) - public Collection jids; - - @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) - public Collection nicknames; + @ElementCollection(fetch = FetchType.LAZY) + @CollectionTable( + name = "user_email_addresses", + schema = "benki", + joinColumns = @JoinColumn(name = "user")) + @Column(name = "email") + public Collection emailAddresses; + + @ElementCollection(fetch = FetchType.LAZY) + @CollectionTable(name = "user_jids", schema = "benki", joinColumns = @JoinColumn(name = "user")) + @Column(name = "jid") + public Collection jids; + + @ElementCollection(fetch = FetchType.LAZY) + @CollectionTable( + name = "user_nicknames", + schema = "benki", + joinColumns = @JoinColumn(name = "user")) + @Column(name = "nickname") + public Collection nicknames; @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) public Collection directRoles; @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) - public Collection rsaKeys; + public Collection rsaKeys; @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "role", referencedColumnName = "id", nullable = false) public Role ownedRole; - @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) - public Collection webids; + @ElementCollection(fetch = FetchType.LAZY) + @CollectionTable(name = "webids", schema = "benki", joinColumns = @JoinColumn(name = "user")) + @Column(name = "webid") + public Collection webids; @OneToMany(mappedBy = "author", fetch = FetchType.LAZY) public Collection 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 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 { -- cgit v1.2.3