-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Avoid loading entire composite role collection to add/remove items or check presence (fixes #11796) #11799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Avoid loading entire composite role collection to add/remove items or check presence (fixes #11796) #11799
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
90 changes: 90 additions & 0 deletions
90
model/jpa/src/main/java/org/keycloak/models/jpa/entities/CompositeRoleEntity.java
This file contains hidden or 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,90 @@ | ||
| package org.keycloak.models.jpa.entities; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.IdClass; | ||
| import javax.persistence.NamedQueries; | ||
| import javax.persistence.NamedQuery; | ||
| import javax.persistence.QueryHint; | ||
| import javax.persistence.Table; | ||
| import javax.persistence.UniqueConstraint; | ||
|
|
||
| import org.hibernate.jpa.QueryHints; | ||
|
|
||
| @Entity | ||
| @IdClass(CompositeRoleEntityKey.class) | ||
| @Table(name="COMPOSITE_ROLE", uniqueConstraints = { | ||
| @UniqueConstraint(columnNames = { "COMPOSITE", "CHILD_ROLE" }) | ||
| }) | ||
| @NamedQueries({ | ||
| @NamedQuery(name="getChildrenRoleIds", hints = @QueryHint(name = QueryHints.HINT_READONLY, value = "true"), | ||
| query="select compositerole.childRoleId from CompositeRoleEntity compositerole where compositerole.compositeId = :roleId"), | ||
| @NamedQuery(name="getCompositeRolesByCompositeIds", hints = @QueryHint(name = QueryHints.HINT_READONLY, value = "true"), | ||
| query="select compositerole from CompositeRoleEntity compositerole where compositerole.compositeId in :roleIds"), | ||
| @NamedQuery(name="getChildRoleIdsForCompositeIds", hints = @QueryHint(name = QueryHints.HINT_READONLY, value = "true"), | ||
| query="select compositerole.childRoleId from CompositeRoleEntity compositerole where compositerole.compositeId in :roleIds"), | ||
| @NamedQuery(name="removeCompositeAndChildRoleEntry", | ||
| query="delete from CompositeRoleEntity compositerole where compositerole.compositeId = :compositeId and compositerole.childRoleId = :childId"), | ||
| }) | ||
| public class CompositeRoleEntity implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = 7375648337789837909L; | ||
|
|
||
| @Id | ||
| @Column(name="COMPOSITE", length = 36, nullable = false) | ||
| private String compositeId; | ||
|
|
||
| @Id | ||
| @Column(name="CHILD_ROLE", length = 36, nullable = false) | ||
| private String childRoleId; | ||
|
|
||
| public CompositeRoleEntity() { | ||
| super(); | ||
| } | ||
|
|
||
| public CompositeRoleEntity(CompositeRoleEntityKey key) { | ||
| super(); | ||
| setCompositeId(key.getCompositeId()); | ||
| setChildRoleId(key.getChildRoleId()); | ||
| } | ||
|
|
||
| public String getCompositeId() { | ||
| return compositeId; | ||
| } | ||
|
|
||
| public void setCompositeId(String compositeId) { | ||
| this.compositeId = compositeId; | ||
| } | ||
|
|
||
| public String getChildRoleId() { | ||
| return childRoleId; | ||
| } | ||
|
|
||
| public void setChildRoleId(String childRoleId) { | ||
| this.childRoleId = childRoleId; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null) return false; | ||
| if (!(o instanceof CompositeRoleEntity)) return false; | ||
|
|
||
| CompositeRoleEntity that = (CompositeRoleEntity) o; | ||
|
|
||
| if (!compositeId.equals(that.compositeId)) return false; | ||
| if (!childRoleId.equals(that.childRoleId)) return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(compositeId, childRoleId); | ||
| } | ||
|
|
||
| } |
64 changes: 64 additions & 0 deletions
64
model/jpa/src/main/java/org/keycloak/models/jpa/entities/CompositeRoleEntityKey.java
This file contains hidden or 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,64 @@ | ||
| package org.keycloak.models.jpa.entities; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * The composite primary key representation for {@link CompositeRoleEntity}. | ||
| * Required to perform lookup by primary key through JPA entity manager. | ||
| */ | ||
| public class CompositeRoleEntityKey implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = -6078479162595894390L; | ||
|
|
||
| private String compositeId; | ||
| private String childRoleId; | ||
|
|
||
| public CompositeRoleEntityKey() { | ||
| super(); | ||
| } | ||
|
|
||
| public CompositeRoleEntityKey(String compositeId, String childRoleId) { | ||
| super(); | ||
| this.compositeId = compositeId; | ||
| this.childRoleId = childRoleId; | ||
| } | ||
|
|
||
| public String getCompositeId() { | ||
| return compositeId; | ||
| } | ||
|
|
||
| public String getChildRoleId() { | ||
| return childRoleId; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null) return false; | ||
| if (!(o instanceof CompositeRoleEntityKey)) return false; | ||
|
|
||
| CompositeRoleEntityKey that = (CompositeRoleEntityKey) o; | ||
|
|
||
| if (!compositeId.equals(that.compositeId)) return false; | ||
| if (!childRoleId.equals(that.childRoleId)) return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(compositeId, childRoleId); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder builder = new StringBuilder(); | ||
| builder.append("CompositeRolePK [") | ||
| .append("compositeId=").append(compositeId) | ||
| .append(", childRoleId=").append(childRoleId) | ||
| .append("]"); | ||
| return builder.toString(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.