Class AbstractJpaCrudServiceImpl<P extends UniquePojo<ID>,​E extends UniqueEntity<ID>,​ID extends java.io.Serializable>

    • Constructor Detail

      • AbstractJpaCrudServiceImpl

        protected AbstractJpaCrudServiceImpl​(java.lang.Class<P> pojoClass,
                                             java.lang.Class<E> entityClass)
        Parameters:
        pojoClass -
        entityClass -
    • Method Detail

      • customizeModelMapper

        protected void customizeModelMapper​(org.modelmapper.ModelMapper modelMapper)
        Allows subclasses to customize the ModelMapper.
        Parameters:
        modelMapper -
      • convertEntityToPojo

        protected P convertEntityToPojo​(E entity)
        Parameters:
        entity -
        Returns:
      • convertEntityToPojo

        protected QueryResults<P> convertEntityToPojo​(QueryResults<E> entityQueryResults)
        Parameters:
        entityQueryResults -
        Returns:
      • convertPojoToEntity

        protected E convertPojoToEntity​(P pojo)
        Parameters:
        pojo -
        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 source
        pojoKeyMapper - maps to the getId() method of pojos
        entityKeyMapper - maps to the getId() method of entities
        idFieldName - the name of the field for the ID property. Usually "id".
        Throws:
        java.lang.Exception
      • 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:
      • updateEntity

        protected P updateEntity​(E entity)
        This is only used to update a Reaction, so expect this to disappear.
        Parameters:
        entity -
        Returns:
      • updateEntity

        protected void updateEntity​(E entity,
                                    P pojo)
        Update the existing entity's properties using the pojo's properties. Used in saveOrUpdateAll() when we're updating some entities and creating others.
        Parameters:
        entity -
        pojo -