com.github.tomschi.commons.springdatajpa.controller.AbstractJpaController Maven / Gradle / Ivy
package com.github.tomschi.commons.springdatajpa.controller;
import com.github.tomschi.commons.data.dbo.DatabaseObject;
import com.github.tomschi.commons.springdatajpa.service.JpaService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;
public abstract class AbstractJpaController, ID extends Serializable, S extends JpaService>
implements JpaController {
private final S service;
public AbstractJpaController(S service) {
Assert.notNull(service);
this.service = service;
}
protected S getService() {
return this.service;
}
@Override
public T newInstance() {
return getService().newInstance();
}
@Override
@Transactional(readOnly = true)
public List findAll() {
return getService().findAll();
}
@Override
@Transactional(readOnly = true)
public List findAll(Iterable ids) {
return getService().findAll(ids);
}
@Override
@Transactional(readOnly = true)
public List findAll(Sort sort) {
return getService().findAll(sort);
}
@Override
@Transactional(readOnly = true)
public Page findAll(Pageable pageable) {
return getService().findAll(pageable);
}
@Override
@Transactional(readOnly = true)
public Optional findOne(ID id) {
return getService().findOne(id);
}
@Override
@Transactional
public Optional save(T entity) {
return getService().save(entity);
}
@Override
@Transactional
public List save(Iterable entities) {
return getService().save(entities);
}
@Override
@Transactional(readOnly = true)
public boolean exists(ID id) {
return getService().exists(id);
}
@Override
@Transactional(readOnly = true)
public long count() {
return getService().count();
}
@Override
@Transactional
public void delete(ID id) {
getService().delete(id);
}
@Override
@Transactional
public void delete(T entity) {
getService().delete(entity);
}
@Override
@Transactional
public void delete(Iterable entities) {
getService().delete(entities);
}
@Override
@Transactional
public void deleteAll() {
getService().deleteAll();
}
}