package com.ssj.framework.core.common.service;

import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

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

/***
 * 
 * 类名称：BaseServiceImpl<br>
 * 类描述： BaseService的抽象实现，实体非配置事物
 * @version v1.0
 * @param <T>
 * @param <ID>
 */
public abstract class BaseV1ServiceImpl<T, ID extends Serializable> implements BaseService<T, ID> {

    public abstract PagingAndSortingRepository<T, ID> getDao();

    @Override
    @Transactional
    public T save(T t) {
        T nt = getDao().save(t);
        return nt;
    }

    @Override
    @Transactional
    public void save(List<T> t) {
        getDao().save(t);
    }

    @Override
    @Transactional
    public void delete(ID id) {
        getDao().delete(id);
    }

    @Override
    @Transactional
    public void delete(T t) {
        getDao().delete(t);
    }

    @Override
    public T getById(ID id) {
        return getDao().findOne(id);
    }

    @Override
    public List<T> findAll() {
        return (List<T>) getDao().findAll();
    }

    @Override
    public List<T> findAll(Sort sort) {
        return (List<T>) getDao().findAll(sort);
    }
}
