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

com.github.ydespreaux.spring.data.elasticsearch.repository.ReactiveElasticsearchRepository Maven / Gradle / Ivy

/*
 * Copyright (C) 2018 Yoann Despréaux
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING . If not, write to the
 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Please send bugreports with examples or suggestions to [email protected]
 */

package com.github.ydespreaux.spring.data.elasticsearch.repository;

import com.github.ydespreaux.spring.data.elasticsearch.core.query.Criteria;
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.Repository;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Collection;
import java.util.List;

/**
 * @param  entity generic class
 * @param  key generic class
 * @author Yoann Despréaux
 * @since 1.0.0
 */
public interface ReactiveElasticsearchRepository extends Repository {

    /**
     * Retrieves an entity by its id.
     *
     * @param id must not be {@literal null}.
     * @return the entity with the given id or {@literal Optional#empty()} if none found
     * @throws IllegalArgumentException if {@code id} is {@literal null}.
     */
    Mono findById(K id);

    /**
     * @param id the identifier
     * @return true if the document exists
     */
    Mono existsById(K id);

    /**
     * @return
     */
    Mono count();

    /**
     * @param query
     * @return
     */
    Mono count(QueryBuilder query);

    /**
     * @param criteria
     * @return
     */
    Mono count(Criteria criteria);

    /**
     * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
     * entity instance completely.
     *
     * @param entity must not be {@literal null}.
     * @return the saved entity will never be {@literal null}.
     */
    Mono save(T entity);

    /**
     * Saves all given entities.
     *
     * @param entities must not be {@literal null}.
     * @return the saved entities will never be {@literal null}.
     * @throws IllegalArgumentException in case the given entity is {@literal null}.
     */
    Flux save(List entities);

    /**
     * @param entities
     * @return
     */
    Flux save(Flux entities);

    /**
     * Deletes the entity with the given id.
     *
     * @param id must not be {@literal null}.
     * @throws IllegalArgumentException in case the given {@code id} is {@literal null}
     */
    Mono deleteById(K id);

    /**
     * Deletes a given entity.
     *
     * @param entity the entity
     * @throws IllegalArgumentException in case the given entity is {@literal null}.
     */
    Mono delete(T entity);

    /**
     * Deletes the given entities.
     *
     * @param entities the entities
     * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
     */
    Mono deleteAll(Collection entities);

    /**
     * @param entities
     * @return
     */
    Mono deleteAll(Flux entities);

    /**
     * Deletes all entities managed by the repository.
     */
    Mono deleteAll();

    /**
     *
     */
    Mono refresh();

    /**
     * @return
     */
    Flux findAll();

    /**
     * @param query the query
     * @param sort  the sort
     * @return items for the query
     */
     Flux findByQuery(QueryBuilder query, @Nullable Sort sort);

    /**
     * @param criteria the query
     * @param sort     the sort
     * @return items for the query
     */
     Flux findByQuery(Criteria criteria, @Nullable Sort sort);

    /**
     * @param query
     * @param sort
     * @return
     */
     Flux findByQuery(QueryBuilder query, @Nullable Sort sort, Class domainClass);

    /**
     * @param criteria
     * @param sort
     * @return
     */
     Flux findByQuery(Criteria criteria, @Nullable Sort sort, Class domainClass);

    /**
     * @param query
     * @return
     */
    Flux suggest(String query);

    /**
     * @param query
     * @return
     */
     Flux suggest(String query, Class domainClass);

    /**
     * Returns all parents
     *
     * @return
     */
    Flux hasChild();

    /**
     * Returns parent documents which associated children have matched with query.
     *
     * @param query
     * @return
     */
    Flux hasChildByQuery(@NonNull QueryBuilder query);

    /**
     * Returns parent documents which associated children have matched with query.
     *
     * @param criteria
     * @return
     */
    Flux hasChildByQuery(@NonNull Criteria criteria);

    /**
     * Returns all children
     *
     * @param 
     * @return
     */
     Flux hasParent();

    /**
     * Returns child documents which associated parents have matched with query.
     *
     * @param query
     * @param 
     * @return
     */
     Flux hasParentByQuery(@NonNull QueryBuilder query);

    /**
     * Returns child documents which associated parents have matched with query.
     *
     * @param criteria
     * @param 
     * @return
     */
     Flux hasParentByQuery(@NonNull Criteria criteria);

    /**
     * Return child documents which associated parent id
     *
     * @param parentId
     * @return
     */
    Flux hasParentId(@NonNull String parentId);

    /**
     * Return child documents which associated parent id and children have matched with query.
     *
     * @param parentId
     * @param criteria
     * @return
     */
    Flux hasParentId(@NonNull String parentId, @Nullable Criteria criteria);

    /**
     * Return child documents which associated parent id and children have matched with query.
     *
     * @param parentId
     * @param query
     * @return
     */
    Flux hasParentId(@NonNull String parentId, @Nullable QueryBuilder query);
}