@Override public GroupModel getGroupById(String id, RealmModel realm) { CachedGroup cached = cache.get(id, CachedGroup.class); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { Long loaded = cache.getCurrentRevision(id); GroupModel model = getRealmDelegate().getGroupById(id, realm); if (model == null) return null; if (invalidations.contains(id)) return model; cached = new CachedGroup(loaded, realm, model); cache.addRevisioned(cached, startupRevision); } else if (invalidations.contains(id)) { return getRealmDelegate().getGroupById(id, realm); } else if (managedGroups.containsKey(id)) { return managedGroups.get(id); } GroupAdapter adapter = new GroupAdapter(cached, this, session, realm); managedGroups.put(id, adapter); return adapter; }
@Override public ClientScopeModel getClientScopeById(String id, RealmModel realm) { CachedClientScope cached = cache.get(id, CachedClientScope.class); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { Long loaded = cache.getCurrentRevision(id); ClientScopeModel model = getRealmDelegate().getClientScopeById(id, realm); if (model == null) return null; if (invalidations.contains(id)) return model; cached = new CachedClientScope(loaded, realm, model); cache.addRevisioned(cached, startupRevision); } else if (invalidations.contains(id)) { return getRealmDelegate().getClientScopeById(id, realm); } else if (managedClientScopes.containsKey(id)) { return managedClientScopes.get(id); } ClientScopeAdapter adapter = new ClientScopeAdapter(realm, cached, this); managedClientScopes.put(id, adapter); return adapter; }
@Override public ClientModel getClientById(String id, RealmModel realm) { CachedClient cached = cache.get(id, CachedClient.class); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached != null) { logger.tracev("client by id cache hit: {0}", cached.getClientId()); } if (cached == null) { Long loaded = cache.getCurrentRevision(id); ClientModel model = getClientDelegate().getClientById(id, realm); if (model == null) return null; ClientModel adapter = cacheClient(realm, model, loaded); managedApplications.put(id, adapter); return adapter; } else if (invalidations.contains(id)) { return getRealmDelegate().getClientById(id, realm); } else if (managedApplications.containsKey(id)) { return managedApplications.get(id); } ClientModel adapter = validateCache(realm, cached); managedApplications.put(id, adapter); return adapter; }
@Override public RoleModel getRoleById(String id, RealmModel realm) { CachedRole cached = cache.get(id, CachedRole.class); if (cached != null && !cached.getRealm().equals(realm.getId())) { cached = null; } if (cached == null) { Long loaded = cache.getCurrentRevision(id); RoleModel model = getRealmDelegate().getRoleById(id, realm); if (model == null) return null; if (invalidations.contains(id)) return model; if (model.isClientRole()) { cached = new CachedClientRole(loaded, model.getContainerId(), model, realm); } else { cached = new CachedRealmRole(loaded, model, realm); } cache.addRevisioned(cached, startupRevision); } else if (invalidations.contains(id)) { return getRealmDelegate().getRoleById(id, realm); } else if (managedRoles.containsKey(id)) { return managedRoles.get(id); } RoleAdapter adapter = new RoleAdapter(cached,this, realm); managedRoles.put(id, adapter); return adapter; }
@Override public RealmModel getRealm(String id) { CachedRealm cached = cache.get(id, CachedRealm.class); if (cached != null) { logger.tracev("by id cache hit: {0}", cached.getName());
GroupListQuery query = cache.get(cacheKey, GroupListQuery.class); if (Objects.nonNull(query)) { logger.tracev("getTopLevelGroups cache hit: {0}", realm.getName());
@Override public RealmModel getRealmByName(String name) { String cacheKey = getRealmByNameCacheKey(name); RealmListQuery query = cache.get(cacheKey, RealmListQuery.class); if (query != null) { logger.tracev("realm by name cache hit: {0}", name); } if (query == null) { Long loaded = cache.getCurrentRevision(cacheKey); RealmModel model = getRealmDelegate().getRealmByName(name); if (model == null) return null; if (invalidations.contains(model.getId())) return model; query = new RealmListQuery(loaded, cacheKey, model.getId()); cache.addRevisioned(query, startupRevision); return model; } else if (invalidations.contains(cacheKey)) { return getRealmDelegate().getRealmByName(name); } else { String realmId = query.getRealms().iterator().next(); if (invalidations.contains(realmId)) { return getRealmDelegate().getRealmByName(name); } return getRealm(realmId); } }
GroupListQuery query = cache.get(cacheKey, GroupListQuery.class); if (query != null) { logger.tracev("getTopLevelGroups cache hit: {0}", realm.getName());
GroupListQuery query = cache.get(cacheKey, GroupListQuery.class); if (query != null) { logger.tracev("getGroups cache hit: {0}", realm.getName());
@Override public ClientModel getClientByClientId(String clientId, RealmModel realm) { String cacheKey = getClientByClientIdCacheKey(clientId, realm.getId()); ClientListQuery query = cache.get(cacheKey, ClientListQuery.class); String id = null; if (query != null) { logger.tracev("client by name cache hit: {0}", clientId); } if (query == null) { Long loaded = cache.getCurrentRevision(cacheKey); ClientModel model = getClientDelegate().getClientByClientId(clientId, realm); if (model == null) return null; if (invalidations.contains(model.getId())) return model; id = model.getId(); query = new ClientListQuery(loaded, cacheKey, realm, id); logger.tracev("adding client by name cache miss: {0}", clientId); cache.addRevisioned(query, startupRevision); } else if (invalidations.contains(cacheKey)) { return getClientDelegate().getClientByClientId(clientId, realm); } else { id = query.getClients().iterator().next(); if (invalidations.contains(id)) { return getClientDelegate().getClientByClientId(clientId, realm); } } return getClientById(id, realm); }
RoleListQuery query = cache.get(cacheKey, RoleListQuery.class); if (query != null) { logger.tracev("getRealmRoles cache hit: {0}", realm.getName());
ClientListQuery query = cache.get(cacheKey, ClientListQuery.class); if (query != null) { logger.tracev("getClients cache hit: {0}", realm.getName());
@Override public RoleModel getRealmRole(RealmModel realm, String name) { String cacheKey = getRoleByNameCacheKey(realm.getId(), name); boolean queryDB = invalidations.contains(cacheKey) || listInvalidations.contains(realm.getId()); if (queryDB) { return getRealmDelegate().getRealmRole(realm, name); } RoleListQuery query = cache.get(cacheKey, RoleListQuery.class); if (query != null) { logger.tracev("getRealmRole cache hit: {0}.{1}", realm.getName(), name); } if (query == null) { Long loaded = cache.getCurrentRevision(cacheKey); RoleModel model = getRealmDelegate().getRealmRole(realm, name); if (model == null) return null; query = new RoleListQuery(loaded, cacheKey, realm, model.getId()); logger.tracev("adding realm role cache miss: client {0} key {1}", realm.getName(), cacheKey); cache.addRevisioned(query, startupRevision); return model; } RoleModel role = getRoleById(query.getRoles().iterator().next(), realm); if (role == null) { invalidations.add(cacheKey); return getRealmDelegate().getRealmRole(realm, name); } return role; }
RoleListQuery query = cache.get(cacheKey, RoleListQuery.class); if (query != null) { logger.tracev("getClientRoles cache hit: {0}", client.getClientId());
@Override public RoleModel getClientRole(RealmModel realm, ClientModel client, String name) { String cacheKey = getRoleByNameCacheKey(client.getId(), name); boolean queryDB = invalidations.contains(cacheKey) || listInvalidations.contains(client.getId()); if (queryDB) { return getRealmDelegate().getClientRole(realm, client, name); } RoleListQuery query = cache.get(cacheKey, RoleListQuery.class); if (query != null) { logger.tracev("getClientRole cache hit: {0}.{1}", client.getClientId(), name); } if (query == null) { Long loaded = cache.getCurrentRevision(cacheKey); RoleModel model = getRealmDelegate().getClientRole(realm, client, name); if (model == null) return null; query = new RoleListQuery(loaded, cacheKey, realm, model.getId(), client.getClientId()); logger.tracev("adding client role cache miss: client {0} key {1}", client.getClientId(), cacheKey); cache.addRevisioned(query, startupRevision); return model; } RoleModel role = getRoleById(query.getRoles().iterator().next(), realm); if (role == null) { invalidations.add(cacheKey); return getRealmDelegate().getClientRole(realm, client, name); } return role; }