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