org.opendaylight.persistence.common.query.PagedFindQuery Maven / Gradle / Ivy
/**
* Copyright (c) 2015 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.persistence.common.query;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.persistence.DataStore;
import org.opendaylight.persistence.PersistenceException;
import org.opendaylight.persistence.Query;
import org.opendaylight.persistence.dao.PagedDao;
import org.opendaylight.persistence.util.common.type.Sort;
import org.opendaylight.persistence.util.common.type.page.Page;
import org.opendaylight.persistence.util.common.type.page.PageRequest;
import org.opendaylight.yangtools.concepts.Identifiable;
/**
* Query to get a page of objects from the data store that match the given filter.
*
* @param type of the identifiable object (object to store in the data store)
* @param type of the associated filter
* @param type of the associated sort attribute or sort key used to construct sort
* specifications
* @param type of the page request
* @param type of the page
* @param type of the query's execution context; the context managed by the {@link DataStore}
* @author Fabiel Zuniga
* @author Nachiket Abhyankar
*/
public final class PagedFindQuery, F, S, R extends PageRequest, D extends Page, C>
implements Query {
private F filter;
private List> sort;
private R pageRequest;
private PagedDao, T, F, S, R, D, C> dao;
private PagedFindQuery(@Nonnull F filter, @Nullable List> sort, @Nonnull R pageRequest,
@Nonnull PagedDao, T, F, S, R, D, C> dao) {
this.filter = filter;
this.sort = sort;
this.pageRequest = pageRequest;
this.dao = dao;
}
/**
* Creates a query.
*
* This method is a convenience to infer the generic types.
*
* @param filter filter
* @param sort sort specification
* @param pageRequest page request
* @param dao DAO to assist the query
* @return the query
*/
public static , F, S, R extends PageRequest, D extends Page, C> Query createQuery(
@Nonnull F filter, @Nullable List> sort, @Nonnull R pageRequest,
@Nonnull PagedDao, T, F, S, R, D, C> dao) {
return new PagedFindQuery(filter, sort, pageRequest, dao);
}
@Override
public D execute(C context) throws PersistenceException {
return this.dao.find(this.filter, this.sort, this.pageRequest, context);
}
}