pl.atom.spring.cqs.query.DefaultQueryBus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cqs-spring-boot-starter Show documentation
Show all versions of cqs-spring-boot-starter Show documentation
Easy way to follow CQS principle with spring-boot
The newest version!
package pl.atom.spring.cqs.query;
class DefaultQueryBus implements QueryBus {
private final QueryHandlerProvider queryHandlerProvider;
public DefaultQueryBus(QueryHandlerProvider queryHandlerProvider) {
this.queryHandlerProvider = queryHandlerProvider;
}
@Override
@SuppressWarnings("unchecked")
public > R execute(Q query) {
return queryHandlerProvider.getQueryHandler(query)
.map(handler -> handler.handle(query))
.map(result -> (R) result)
.orElseThrow(() -> new NoSuitableQueryHandlerException(query));
}
}