org.opendaylight.persistence.common.query.DeleteQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-common Show documentation
Show all versions of persistence-common Show documentation
Abstractions of the persistence API that are common to any database or datastore implementation
/**
* 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.io.Serializable;
import javax.annotation.Nonnull;
import org.opendaylight.persistence.DataStore;
import org.opendaylight.persistence.PersistenceException;
import org.opendaylight.persistence.Query;
import org.opendaylight.persistence.dao.Dao;
import com.google.common.base.Preconditions;
/**
* Query to delete all objects from the data store that match the given filter.
*
* @param type of the associated filter
* @param type of the query's execution context; the context managed by the {@link DataStore}
* @author Fabiel Zuniga
* @author Nachiket Abhyankar
*/
public final class DeleteQuery implements Query {
private F filter;
private Dao, ?, F, ?, C> dao;
private DeleteQuery(@Nonnull F filter, @Nonnull Dao, ?, F, ?, C> dao) {
Preconditions.checkNotNull(dao, "dao");
this.filter = filter;
this.dao = dao;
}
/**
* Creates a query.
*
* This method is a convenience to infer the generic types.
*
* @param filter filter
* @param dao DAO to assist the query
* @return the query
*/
public static Query createQuery(@Nonnull F filter,
@Nonnull Dao dao) {
return new DeleteQuery(filter, dao);
}
@Override
public Void execute(C context) throws PersistenceException {
this.dao.delete(this.filter, context);
return null;
}
}