use of org.keycloak.models.jpa.entities.UserGroupMembershipEntity in project keycloak by keycloak.
the class UserAdapter method createCountGroupsQuery.
private TypedQuery<Long> createCountGroupsQuery() {
// we query ids only as the group might be cached and following the @ManyToOne will result in a load
// even if we're getting just the id.
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> queryBuilder = builder.createQuery(Long.class);
Root<UserGroupMembershipEntity> root = queryBuilder.from(UserGroupMembershipEntity.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(root.get("user"), getEntity()));
queryBuilder.select(builder.count(root));
queryBuilder.where(predicates.toArray(new Predicate[0]));
return em.createQuery(queryBuilder);
}
use of org.keycloak.models.jpa.entities.UserGroupMembershipEntity in project keycloak by keycloak.
the class UserAdapter method leaveGroup.
@Override
public void leaveGroup(GroupModel group) {
if (user == null || group == null)
return;
TypedQuery<UserGroupMembershipEntity> query = getUserGroupMappingQuery(group);
query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
List<UserGroupMembershipEntity> results = query.getResultList();
if (results.size() == 0)
return;
for (UserGroupMembershipEntity entity : results) {
em.remove(entity);
}
em.flush();
}
Aggregations