import java.io.Serializable;
import java.util.List;
public interface CommonService {
public <T extends Serializable> T save(T model);
public <T extends Serializable> void saveOrUpdate(T model);
public <T extends Serializable> void update(T model);
public <T extends Serializable> void merge(T model);
public <T extends Serializable> void delete(T model);
public <T extends Serializable, PK extends Serializable> void delete(Class<T> entityClass, PK id);
public <T extends Serializable, PK extends Serializable> T get(Class<T> entityClass, PK id);
public <T extends Serializable> List<T> listAll(Class<T> entityClass);
}
import java.io.Serializable;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service("commonService")
@Transactional
public class CommonServiceImpl implements CommonService {
@Autowired
@Qualifier("commonDao")
private CommonDao commonDao;
@Override
@Transactional(rollbackFor=MyException.class)
public <T extends Serializable> T save(T model) {
T t = this.commonDao.save(model);
return t;
}
@Override
public <T extends Serializable> void saveOrUpdate(T model) {
this.commonDao.saveOrUpdate(model);
}
@Override
public <T extends Serializable> void update(T model) {
this.commonDao.update(model);
}
@Override
public <T extends Serializable> void merge(T model) {
this.commonDao.merge(model);
}
@Override
public <T extends Serializable> void delete(T model) {
this.commonDao.delete(model);
}
@Override
public <T extends Serializable, PK extends Serializable> void delete(
Class<T> entityClass, PK id) {
this.commonDao.delete(entityClass, id);
}
@Override
public <T extends Serializable, PK extends Serializable> T get(
Class<T> entityClass, PK id) {
return this.commonDao.get(entityClass, id);
}
@Override
public <T extends Serializable> List<T> listAll(Class<T> entityClass) {
return this.commonDao.listAll(entityClass);
}
}