Interface CrudWriteService

All Known Implementing Classes:
AbstractCrudService, AbstractCrudServiceEnvers

public interface CrudWriteService
Generic interface for write operations on entities
Author:
eduard
  • Method Details

    • create

      <T> T create(T t)
    • update

      <T> T update(T t)
    • save

      <T extends EntityInterface> T save(T t)
      create or update depending on EntityInterface.isTransient().
      Type Parameters:
      T -
      Parameters:
      t -
      Returns:
    • delete

      void delete(EntityInterface t)
    • refresh

      <T> T refresh(T t)
      refresh an entity from the database
      Type Parameters:
      T -
      Parameters:
      t -
      Returns:
    • batchSave

      <T extends EntityInterface> Stream<T> batchSave(Collection<T> entities, Integer flushCount)
      save multiple entities, NOTE that normally only after commit or flush entitymanagers will reflect changes caused by saving all entities, this may cause entitylisteners to fail. You may need to perform checks on the collection before calling this method. Also note that entitylisteners will execute within the batch transaction, you may need to specify Transactional.TxType on the bean that you use in your listeners, use isolation level 0 (not recommended) or use XA when you need to access resources from your listeners. When flushCount != null flushes and clears the entitymanager every flushCount entities. NOTE that this method executes in one (possibly big) sql transaction! You can use EntityException in for example your listeners to find out in case of failure which enitity caused it.
      Parameters:
      entities -
      flushCount - when not null try to optimize (flush/clear) every so many entities
      Returns:
      the saved entities
    • batchDelete

      int batchDelete(Collection<? extends EntityInterface> entities, Integer flushCount)
      save multiple entities, NOTE that normally only after commit or flush entitymanagers will reflect changes caused by saving all entities, this may cause entitylisteners to fail. You may need to perform checks on the collection before calling this method. Also note that entitylisteners will execute within the batch transaction, you may need to specify Transactional.TxType on the bean that you use in your listeners, use isolation level 0 (not recommended) or use XA when you need to access resources from your listeners. When flushCount != null flushes and clears the entitymanager every flushCount entities. NOTE that this method executes in one (possibly big) sql transaction! You can use EntityException in for example your listeners to find out in case of failure which enitity caused it.
      Parameters:
      entities -
      flushCount - when not null try to optimize (flush/clear) every so many entities
      Returns:
      number of entities deleted
    • getEntityManager

      jakarta.persistence.EntityManager getEntityManager()