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

com.github.developframework.resource.spring.SpringDataResourceHandler Maven / Gradle / Ivy

The newest version!
package com.github.developframework.resource.spring;

import com.github.developframework.resource.Entity;
import com.github.developframework.resource.ResourceDefinition;
import com.github.developframework.resource.ResourceHandler;
import com.github.developframework.resource.Search;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;

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

/**
 *
 * spring-data资源操作器
 * @author qiushui on 2019-08-15.
 */
public abstract class SpringDataResourceHandler<
        ENTITY extends Entity,
        ID extends Serializable,
        REPOSITORY extends PagingAndSortingRepository
        > implements ResourceHandler {

    protected final REPOSITORY repository;

    protected final ResourceDefinition resourceDefinition;

    public SpringDataResourceHandler(REPOSITORY repository, ResourceDefinition resourceDefinition) {
        this.repository = repository;
        this.resourceDefinition = resourceDefinition;
    }

    @Override
    public boolean existsById(ID id) {
        return repository.existsById(id);
    }

    @Override
    public void insert(ENTITY entity) {
        repository.save(entity);
    }

    @Override
    public void insertAll(Collection entities) {
        repository.saveAll(entities);
    }

    @Override
    public boolean update(ENTITY entity) {
        repository.save(entity);
        return true;
    }

    @Override
    public void deleteById(ID id) {
        repository.deleteById(id);
    }

    @Override
    public void delete(ENTITY entity) {
        repository.delete(entity);
    }

    @Override
    public Optional queryById(ID id) {
        return repository.findById(id);
    }

    public abstract > Page queryPager(Pageable pageable, SEARCH search);

    public abstract > List query(Sort sort, SEARCH search);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy