Class AbstractJpaCrudServiceImpl<P extends UniquePojo<ID>,E extends UniqueEntity<ID>,ID extends java.io.Serializable>
- java.lang.Object
-
- org.drdeesw.commons.services.impl.AbstractService
-
- org.drdeesw.commons.services.impl.AbstractJpaCrudServiceImpl<P,E,ID>
-
- Type Parameters:
P- the POJO classE- the entity classID- the ID class
- All Implemented Interfaces:
BusinessService,CrudService<P,ID>
- Direct Known Subclasses:
AbstractComposerJpaCrudServiceImpl,AbstractUserServiceImpl
public abstract class AbstractJpaCrudServiceImpl<P extends UniquePojo<ID>,E extends UniqueEntity<ID>,ID extends java.io.Serializable> extends AbstractService implements CrudService<P,ID>
- Author:
- gary_kephart
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractJpaCrudServiceImpl(java.lang.Class<P> pojoClass, java.lang.Class<E> entityClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PconvertEntityToPojo(E entity)protected QueryResults<P>convertEntityToPojo(QueryResults<E> entityQueryResults)protected EconvertPojoToEntity(P pojo)java.util.List<P>create(java.util.Collection<P> pojos)Pcreate(P obj)java.util.List<P>createAndFlush(java.util.Collection<P> pojos)PcreateAndFlush(P obj)voidcreateOrUpdateAll(java.util.List<P> allPojos, java.util.function.Function<P,? extends java.lang.Object> pojoKeyMapper, java.util.function.Function<E,? extends java.lang.Object> entityKeyMapper, java.lang.String idFieldName)Used when importing many objects, some of them which might already exist in the system and need updating.protected voidcustomizeModelMapper(org.modelmapper.ModelMapper modelMapper)Allows subclasses to customize the ModelMapper.voiddelete(P obj)java.util.Optional<P>findById(ID id)QueryResults<P>findByQuery(org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> parameterMap)<Q extends JpqlQuery<P>>
QueryResults<P>findByQuery(Q query)QueryResults<E>findEntities(JpqlQuery<E> query)Pget(ID id)QueryResults<P>get(java.util.Set<ID> ids)java.util.Map<ID,P>getMap(java.util.Set<ID> ids)protected org.modelmapper.ModelMappergetModelMapper()protected <R extends org.springframework.data.jpa.repository.JpaRepository<E,ID> & QueryRepository<E,ID>>
voidinit(R repository)protected booleanisNotEmpty(java.util.Collection<?> ids)booleanisNotEmpty(java.util.Map<?,?> map)Pupdate(P obj)protected PupdateEntity(E entity)This is only used to update a Reaction, so expect this to disappear.protected voidupdateEntity(E entity, P pojo)Update the existing entity's properties using the pojo's properties.
-
-
-
Method Detail
-
customizeModelMapper
protected void customizeModelMapper(org.modelmapper.ModelMapper modelMapper)
Allows subclasses to customize the ModelMapper.- Parameters:
modelMapper-
-
convertEntityToPojo
protected QueryResults<P> convertEntityToPojo(QueryResults<E> entityQueryResults)
- Parameters:
entityQueryResults-- Returns:
-
create
public java.util.List<P> create(java.util.Collection<P> pojos)
- Specified by:
createin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
create
public P create(P obj) throws java.lang.Exception
- Specified by:
createin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
- Throws:
java.lang.Exception
-
createAndFlush
public java.util.List<P> createAndFlush(java.util.Collection<P> pojos)
- Specified by:
createAndFlushin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
createAndFlush
public P createAndFlush(P obj)
- Specified by:
createAndFlushin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
createOrUpdateAll
public void createOrUpdateAll(java.util.List<P> allPojos, java.util.function.Function<P,? extends java.lang.Object> pojoKeyMapper, java.util.function.Function<E,? extends java.lang.Object> entityKeyMapper, java.lang.String idFieldName) throws java.lang.Exception
Used when importing many objects, some of them which might already exist in the system and need updating. This method first creates a map of POJOs by their key. It queries the existing entities based on the provided keys. It updates existing entities with the corresponding POJOs and removes the updated POJOs from the map. It then saves all updated entities. Any remaining POJOs in the map are new and need to be saved as new entities.- Parameters:
allPojos- POJOs that have been fetched/updated from an outside sourcepojoKeyMapper- maps to the getId() method of pojosentityKeyMapper- maps to the getId() method of entitiesidFieldName- the name of the field for the ID property. Usually "id".- Throws:
java.lang.Exception
-
delete
public void delete(P obj)
- Specified by:
deletein interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>
-
findById
public java.util.Optional<P> findById(ID id)
- Specified by:
findByIdin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
findByQuery
public QueryResults<P> findByQuery(org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> parameterMap)
- Specified by:
findByQueryin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
findByQuery
public <Q extends JpqlQuery<P>> QueryResults<P> findByQuery(Q query)
- Specified by:
findByQueryin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
findEntities
public QueryResults<E> findEntities(JpqlQuery<E> query)
- Parameters:
query-- Returns:
-
get
public P get(ID id)
- Specified by:
getin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
get
public QueryResults<P> get(java.util.Set<ID> ids)
- Specified by:
getin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
getMap
public java.util.Map<ID,P> getMap(java.util.Set<ID> ids)
- Specified by:
getMapin interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Parameters:
ids-- Returns:
-
getModelMapper
protected org.modelmapper.ModelMapper getModelMapper()
- Returns:
- the modelMapper
-
init
protected <R extends org.springframework.data.jpa.repository.JpaRepository<E,ID> & QueryRepository<E,ID>> void init(R repository)
- Type Parameters:
R-- Parameters:
repository-
-
isNotEmpty
protected boolean isNotEmpty(java.util.Collection<?> ids)
- Parameters:
ids-- Returns:
-
isNotEmpty
public boolean isNotEmpty(java.util.Map<?,?> map)
- Parameters:
map-- Returns:
-
update
public P update(P obj)
- Specified by:
updatein interfaceCrudService<P extends UniquePojo<ID>,E extends UniqueEntity<ID>>- Returns:
-
updateEntity
protected P updateEntity(E entity)
This is only used to update a Reaction, so expect this to disappear.- Parameters:
entity-- Returns:
-
-