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

io.micronaut.data.jpa.repository.JpaRepository Maven / Gradle / Ivy

There is a newer version: 4.10.5
Show newest version
/*
 * 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.jpa.repository;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.data.annotation.QueryHint;
import io.micronaut.data.intercept.annotation.DataMethod;
import io.micronaut.data.jpa.repository.intercept.FlushInterceptor;
import io.micronaut.data.jpa.repository.intercept.LoadInterceptor;
import io.micronaut.data.jpa.repository.intercept.MergeInterceptor;
import io.micronaut.data.model.Sort;
import io.micronaut.data.repository.CrudRepository;
import io.micronaut.data.repository.PageableRepository;

import java.util.List;

/**
 * Simple composed repository interface that includes {@link CrudRepository} and {@link PageableRepository}.
 *
 * @param   The entity type
 * @param  The ID type
 * @author graemerocher
 * @since 1.0.0
 */
public interface JpaRepository extends CrudRepository, PageableRepository {
    @NonNull
    @Override
     List saveAll(@NonNull Iterable entities);

    @NonNull
    @Override
    List findAll();

    @NonNull
    @Override
    List findAll(@NonNull Sort sort);

    /**
     * Save and perform a flush() of any pending operations.
     *
     * @param entity The entity
     * @param     The entity generic type
     * @return The entity, possibly mutated
     */
    @QueryHint(name = "jakarta.persistence.FlushModeType", value = "AUTO")
     S saveAndFlush(@NonNull S entity);

    /**
     * Adds a flush method.
     */
    @DataMethod(interceptor = FlushInterceptor.class)
    void flush();

    /**
     * Adds a load method.
     *
     * @param id  the entity ID
     * @param  the entity type
     * @return An uninitialized proxy
     */
    @DataMethod(interceptor = LoadInterceptor.class)
     S load(@NonNull Object id);

    /**
     * Merge the state of the given entity into the
     * current persistence context.
     *
     * @param entity entity instance
     * @param     The entity type
     * @return the managed instance that the state was merged to
     */
    @DataMethod(interceptor = MergeInterceptor.class)
     S merge(@NonNull S entity);
}