org.opendaylight.persistence.common.query.FindQuery 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.Dao;
import org.opendaylight.persistence.util.common.type.Sort;
import org.opendaylight.yangtools.concepts.Identifiable;
/**
* Query to get the 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 query's execution context; the context managed by the {@link DataStore}
* @author Fabiel Zuniga
* @author Nachiket Abhyankar
*/
public final class FindQuery, F, S, C> implements Query, C> {
private F filter;
private List> sort;
private Dao, T, F, S, C> dao;
private FindQuery(@Nonnull F filter, @Nullable List> sort, @Nonnull Dao, T, F, S, C> dao) {
this.filter = filter;
this.sort = sort;
this.dao = dao;
}
/**
* Creates a query.
*
* This method is a convenience to infer the generic types.
*
* @param filter filter
* @param sort sort specification
* @param dao DAO to assist the query
* @return the query
*/
public static , F, S, C> Query, C> createQuery(@Nonnull F filter,
@Nullable List> sort, @Nonnull Dao, T, F, S, C> dao) {
return new FindQuery(filter, sort, dao);
}
/*public static , F, S, C> Query, C> createQuery(F filter,
SortSpecification sortSpecification, Dao, T, F, S, C> dao) {
return new FindQuery(filter, sortSpecification, dao);
}*/
@Override
public List execute(C context) throws PersistenceException {
return this.dao.find(this.filter, this.sort, context);
}
}