Updated crud service and base entity impl
This commit is contained in:
parent
40cffea983
commit
950f2efaaf
@ -1,8 +1,8 @@
|
||||
package com.cubetiqs.data.service;
|
||||
|
||||
import com.cubetiqs.data.domain.BaseEntity;
|
||||
import com.cubetiqs.data.repository.BaseRepository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -12,7 +12,7 @@ import java.util.List;
|
||||
* @since 1.0
|
||||
*/
|
||||
@NoServiceBean
|
||||
public class CrudServiceImpl<T, ID extends BaseEntity<ID>> implements CrudService<T, ID> {
|
||||
public abstract class AbstractCrudServiceImpl<T extends BaseEntity<ID>, ID extends Serializable> implements CrudService<T, ID> {
|
||||
@Override
|
||||
public List<T> findAll() {
|
||||
return getRepository().findAll();
|
||||
@ -35,12 +35,12 @@ public class CrudServiceImpl<T, ID extends BaseEntity<ID>> implements CrudServic
|
||||
|
||||
@Override
|
||||
public T update(ID id, T entity) {
|
||||
T update = read(id);
|
||||
if (update == null) {
|
||||
return null;
|
||||
}
|
||||
if (existsById(id)) {
|
||||
entity.setId(id);
|
||||
return getRepository().save(entity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(ID id) {
|
||||
@ -53,7 +53,7 @@ public class CrudServiceImpl<T, ID extends BaseEntity<ID>> implements CrudServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseRepository<T, ID> getRepository() {
|
||||
throw new ServiceNotImplementException("service must be implement!");
|
||||
public boolean existsById(ID id) {
|
||||
return getRepository().existsById(id);
|
||||
}
|
||||
}
|
@ -64,4 +64,6 @@ public interface CrudService<T, ID> extends BaseService<T, ID> {
|
||||
* @param ids List of IDs
|
||||
*/
|
||||
void deleteAll(List<ID> ids);
|
||||
|
||||
boolean existsById(ID id);
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ import java.util.List;
|
||||
* @author sombochea
|
||||
* @see CrudService
|
||||
* @see PagingCrudService
|
||||
* @see CrudServiceImpl
|
||||
* @see AbstractCrudServiceImpl
|
||||
* @since 1.0
|
||||
*/
|
||||
@NoServiceBean
|
||||
public class PagingCrudServiceImpl<T, ID> extends CrudServiceImpl<T, ID> implements PagingCrudService<T, ID> {
|
||||
public class PagingCrudServiceImpl<T, ID> extends AbstractCrudServiceImpl<T, ID> implements PagingCrudService<T, ID> {
|
||||
@Override
|
||||
public Page<T> findAll(Pageable pageable) {
|
||||
return getRepository().findAll(pageable);
|
||||
|
Loading…
Reference in New Issue
Block a user