All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.atom.spring.cqs.query.DefaultQueryBus Maven / Gradle / Ivy

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));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy