use of org.keycloak.models.map.storage.criteria.DefaultModelCriteria in project keycloak by keycloak.
the class ConcurrentHashMapStorage method delete.
@Override
public long delete(QueryParameters<M> queryParameters) {
DefaultModelCriteria<M> criteria = queryParameters.getModelCriteriaBuilder();
if (criteria == null) {
long res = store.size();
store.clear();
return res;
}
@SuppressWarnings("unchecked") MapModelCriteriaBuilder<K, V, M> mcb = criteria.flashToModelCriteriaBuilder(createCriteriaBuilder());
Predicate<? super K> keyFilter = mcb.getKeyFilter();
Predicate<? super V> entityFilter = mcb.getEntityFilter();
Stream<Entry<K, V>> storeStream = store.entrySet().stream();
final AtomicLong res = new AtomicLong(0);
if (!queryParameters.getOrderBy().isEmpty()) {
Comparator<V> comparator = MapFieldPredicates.getComparator(queryParameters.getOrderBy().stream());
storeStream = storeStream.sorted((entry1, entry2) -> comparator.compare(entry1.getValue(), entry2.getValue()));
}
paginatedStream(storeStream.filter(next -> keyFilter.test(next.getKey()) && entityFilter.test(next.getValue())), queryParameters.getOffset(), queryParameters.getLimit()).peek(item -> {
res.incrementAndGet();
}).map(Entry::getKey).forEach(store::remove);
return res.get();
}
use of org.keycloak.models.map.storage.criteria.DefaultModelCriteria in project keycloak by keycloak.
the class ConcurrentHashMapStorageProviderFactory method storeMap.
@SuppressWarnings("unchecked")
private void storeMap(String mapName, ConcurrentHashMapStorage<?, ?, ?> store) {
if (mapName != null) {
File f = getFile(mapName);
try {
if (storageDirectory != null) {
LOG.debugf("Storing contents to %s", f.getCanonicalPath());
final DefaultModelCriteria readAllCriteria = criteria();
Serialization.MAPPER.writeValue(f, store.read(withCriteria(readAllCriteria)));
} else {
LOG.debugf("Not storing contents of %s because directory not set", mapName);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
Aggregations