Package 

Class DBKt


  • 
    public final class DBKt
    
                        
    • Method Detail

      • getExtendedEntityManager

         final EntityManager getExtendedEntityManager()

        The extended entity manager, which stays valid even after the transaction is committed and the servlet request finishes. Automatically allocates and releases a delegate EntityManager.

        Can only be used from Vaadin/web servlet thread - cannot be used from async threads.

      • withTransactionControlDisabled

         final EntityManager withTransactionControlDisabled(EntityManager $self)

        Returns a new EntityManager which delegates all calls this, with the following exceptions:

      • db

         final <R extends Any> R db(Function1<PersistenceContext, R> block)

        Makes sure given block is executed in a DB transaction. When the block finishes normally, the transaction commits; if the block throws any exception, the transaction is rolled back.

        Example of use: db { em.persist() }

        Parameters:
        block - the block to run in the transaction.
      • findAll

         final <T extends Any> List<T> findAll(EntityManager $self)

        Returns all JPA entities of given type.

      • get

         final <T extends Any> T get(EntityManager $self, Object id)

        Retrieves given JPA entity. Fails if there is no such entity.

        Parameters:
        id - the entity id
      • deleteById

         final <T extends Any> Boolean deleteById(EntityManager $self, Object id)

        Deletes given entity. Triggers the CascadeType.REMOVE properly.

        Parameters:
        id - entity id
      • delete

         final Boolean delete(EntityManager $self, Object entity)

        Deletes given entity, regardless of whether it is detached or attached. If the entity was detached and meanwhile deleted from the database, does nothing and return false.

        Triggers the CascadeType.REMOVE properly.

      • deleteAll

         final <T extends Any> Integer deleteAll(EntityManager $self)

        Deletes all instances of given JPA entity.

      • singleOrNull

         final <T extends Any> T singleOrNull(TypedQuery<T> $self)

        TypedQuery.getSingleResult works only for simple types such as Long - it does not work when retrieving a single JPA entity and will fail with NoResultException: No entity found for query when no entities are found. Often, null is a better alternative.