use of org.keycloak.models.map.storage.jpa.client.entity.JpaClientEntity in project keycloak by keycloak.
the class JpaClientDelegateProvider method getDelegate.
@Override
public MapClientEntity getDelegate(boolean isRead, Enum<? extends EntityField<MapClientEntity>> field, Object... parameters) {
if (getDelegate().isMetadataInitialized())
return getDelegate();
if (isRead) {
if (field instanceof MapClientEntityFields) {
switch((MapClientEntityFields) field) {
case ID:
case REALM_ID:
case CLIENT_ID:
case PROTOCOL:
case ENABLED:
return getDelegate();
case ATTRIBUTES:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<JpaClientEntity> query = cb.createQuery(JpaClientEntity.class);
Root<JpaClientEntity> root = query.from(JpaClientEntity.class);
root.fetch("attributes", JoinType.LEFT);
query.select(root).where(cb.equal(root.get("id"), UUID.fromString(getDelegate().getId())));
setDelegate(em.createQuery(query).getSingleResult());
break;
default:
setDelegate(em.find(JpaClientEntity.class, UUID.fromString(getDelegate().getId())));
}
} else {
throw new IllegalStateException("Not a valid client field: " + field);
}
} else {
setDelegate(em.find(JpaClientEntity.class, UUID.fromString(getDelegate().getId())));
}
return getDelegate();
}
Aggregations