KEYCLOAK-3989: Replacing COMPOSITE_ROLE Collection with Set.
- Hibernate optimization that avoids deleting/re-inserting all composite roles when adding/removing a composite.
This commit is contained in:
parent
cb4f856ab6
commit
4910b35d69
2 changed files with 6 additions and 9 deletions
|
@ -107,10 +107,7 @@ public class RoleAdapter implements RoleModel, JpaModel<RoleEntity> {
|
|||
@Override
|
||||
public void removeCompositeRole(RoleModel role) {
|
||||
RoleEntity entity = RoleAdapter.toRoleEntity(role, em);
|
||||
Iterator<RoleEntity> it = getEntity().getCompositeRoles().iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().equals(entity)) it.remove();
|
||||
}
|
||||
getEntity().getCompositeRoles().remove(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,8 +31,8 @@ import javax.persistence.NamedQueries;
|
|||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
|
||||
|
@ -89,7 +89,7 @@ public class RoleEntity {
|
|||
|
||||
@ManyToMany(fetch = FetchType.LAZY, cascade = {})
|
||||
@JoinTable(name = "COMPOSITE_ROLE", joinColumns = @JoinColumn(name = "COMPOSITE"), inverseJoinColumns = @JoinColumn(name = "CHILD_ROLE"))
|
||||
private Collection<RoleEntity> compositeRoles = new ArrayList<RoleEntity>();
|
||||
private Set<RoleEntity> compositeRoles = new HashSet<>();
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -133,11 +133,11 @@ public class RoleEntity {
|
|||
this.scopeParamRequired = scopeParamRequired;
|
||||
}
|
||||
|
||||
public Collection<RoleEntity> getCompositeRoles() {
|
||||
public Set<RoleEntity> getCompositeRoles() {
|
||||
return compositeRoles;
|
||||
}
|
||||
|
||||
public void setCompositeRoles(Collection<RoleEntity> compositeRoles) {
|
||||
public void setCompositeRoles(Set<RoleEntity> compositeRoles) {
|
||||
this.compositeRoles = compositeRoles;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue