/*
 * Copyright 2008-2016 the original author or 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
 *
 *      http://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 org.springframework.data.ebean.repository;

import io.ebean.EbeanServer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.io.Serializable;
import java.util.List;

/**
 * Ebean specific extension of {@link org.springframework.data.repository.Repository}.
 *
 * @author Xuegui Yuan
 */
@NoRepositoryBean
public interface EbeanRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {

    EbeanServer db();

    EbeanServer db(EbeanServer db);


    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#findAll()
     */
    List<T> findAll();

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
     */
    List<T> findAll(Sort sort);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
     */
    List<T> findAll(Iterable<ID> ids);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
     */
    <S extends T> List<S> save(Iterable<S> entities);

    T findOne(ID id, String selects);

    List<T> findAll(String selects);

    List<T> findAll(Iterable<ID> ids, String selects);

    List<T> findAll(Sort sort, String selects);

    Page<T> findAll(Pageable pageable, String selects);

}

/*
 * Copyright 2008-2016 the original author or 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
 *
 *      http://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 org.springframework.data.ebean.repository;

import io.ebean.EbeanServer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.io.Serializable;
import java.util.List;

/**
 * Ebean specific extension of {@link org.springframework.data.repository.Repository}.
 *
 * @author Xuegui Yuan
 */
@NoRepositoryBean
public interface EbeanRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {

    /**
     * Return the current EbeanServer
     *
     * @return the current EbeanServer
     */
    EbeanServer db();

    /**
     * Set the current EbeanServer
     *
     * @param db current EbeanServer
     * @return the current EbeanServer
     */
    EbeanServer db(EbeanServer db);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#findAll()
     */
    List<T> findAll();

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
     */
    List<T> findAll(Sort sort);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
     */
    List<T> findAll(Iterable<ID> ids);

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
     */
    <S extends T> List<S> save(Iterable<S> entities);

    /**
     * Retrieves an entity by its id and select return entity properties with FetchPath string
     * @param id ID
     * @param selects FetchPath string
     * @return the entity only select/fetch with FetchPath string
     */
    T findOne(ID id, String selects);

    /**
     * Returns all entities and select return entity properties with FetchPath string
     * @param selects FetchPath string
     * @return all entities only select/fetch with FetchPath string
     */
    List<T> findAll(String selects);

    /**
     * Returns all entities in ids and select return entity properties with FetchPath string
     * @param ids ID list
     * @param selects FetchPath string
     * @return all entities by id in ids and select/fetch with FetchPath string
     */
    List<T> findAll(Iterable<ID> ids, String selects);

    /**
     * Returns all entities sorted by the given options and select return entity properties with FetchPath string.
     * @param sort
     * @param selects
     * @return all entities sorted and select/fetch with FetchPath string
     */
    List<T> findAll(Sort sort, String selects);

    /**
     * Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object
     * and select return entity properties with FetchPath string.
     * @param pageable
     * @param selects
     * @return a page of entities select/fetch with FetchPath string
     */
    Page<T> findAll(Pageable pageable, String selects);

}

add comment on EbeanRepository