io.micronaut.data.repository.async.AsyncCrudRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-data-model Show documentation
Show all versions of micronaut-data-model Show documentation
Data Repository Support for Micronaut
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.data.repository.async;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.NonBlocking;
import io.micronaut.data.repository.GenericRepository;
import java.util.concurrent.CompletableFuture;
/**
* Asynchronous variation of {@link io.micronaut.data.repository.CrudRepository}.
*
* @param The entity type
* @param The ID type
* @author graemerocher
* @since 1.0.0
*/
@NonBlocking
public interface AsyncCrudRepository extends GenericRepository {
/**
* Saves the given valid entity, returning a possibly new entity representing the saved state.
*
* @param entity The entity to save. Must not be {@literal null}.
* @return The saved entity will never be {@literal null}.
* @param The generic type
*/
@NonNull
CompletableFuture save(@NonNull S entity);
/**
* This method issues an explicit update for the given entity. The method differs from {@link #save(Object)} in that an update will be generated regardless if the entity has been saved previously or not. If the entity has no assigned ID then an exception will be thrown.
*
* @param entity The entity to updated. Must not be {@literal null}.
* @return The updated entity will never be {@literal null}.
* @param The generic type
*/
@NonNull
CompletableFuture update(@NonNull S entity);
/**
* This method issues an explicit update for the given entities. The method differs from {@link #saveAll(Iterable)} in that an update will be generated regardless if the entity has been saved previously or not. If the entity has no assigned ID then an exception will be thrown.
*
* @param entities The entities to update. Must not be {@literal null}.
* @return The updating entity will never be {@literal null}.
* @param The generic type
*/
@NonNull
CompletableFuture extends Iterable> updateAll(@NonNull Iterable entities);
/**
* Saves all given entities, possibly returning new instances representing the saved state.
*
* @param entities The entities to saved. Must not be {@literal null}.
* @param The generic type
* @return The saved entities objects. will never be {@literal null}.
*/
@NonNull
CompletableFuture extends Iterable> saveAll(@NonNull Iterable entities);
/**
* Retrieves an entity by its id.
*
* @param id The ID of the entity to retrieve. Must not be {@literal null}.
* @return the entity with the given id or null
* @throws io.micronaut.data.exceptions.EmptyResultException if no entity exists for the ID
*/
@NonNull
CompletableFuture findById(@NonNull ID id);
/**
* Returns whether an entity with the given id exists.
*
* @param id must not be {@literal null}.
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
*/
@NonNull CompletableFuture existsById(@NonNull ID id);
/**
* Returns all instances of the type.
*
* @return all entities
*/
@NonNull CompletableFuture extends Iterable> findAll();
/**
* Returns the number of entities available.
*
* @return the number of entities
*/
@NonNull CompletableFuture count();
/**
* Deletes the entity with the given id.
*
* @param id must not be {@literal null}.
* @return A future that executes the delete operation
*/
@NonNull CompletableFuture deleteById(@NonNull ID id);
/**
* Deletes a given entity.
*
* @param entity The entity to delete
* @return A future that executes the delete operation
*/
@NonNull CompletableFuture delete(@NonNull E entity);
/**
* Deletes the given entities.
*
* @param entities The entities to delete
* @return A future that executes the delete operation
*/
@NonNull CompletableFuture deleteAll(@NonNull Iterable extends E> entities);
/**
* Deletes all entities managed by the repository.
* @return A future that executes the delete operation
*/
@NonNull CompletableFuture deleteAll();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy