Class MutinySessionDelegator

    • Constructor Detail

      • MutinySessionDelegator

        public MutinySessionDelegator()
    • Method Detail

      • find

        public <T> io.smallrye.mutiny.Uni<T> find​(Class<T> entityClass,
                                                  Object id)
        Description copied from interface: Mutiny.Session
        Asynchronously return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. If the instance is already associated with the session, return the associated instance. This method never returns an uninitialized instance.
         session.find(Book.class, id).map(book -> print(book.getTitle()));
         
        Specified by:
        find in interface Mutiny.Session
        Parameters:
        entityClass - The entity type
        id - an identifier
        Returns:
        a persistent instance or null via a Uni
        See Also:
        EntityManager.find(Class, Object)
      • find

        public <T> io.smallrye.mutiny.Uni<T> find​(Class<T> entityClass,
                                                  Object id,
                                                  jakarta.persistence.LockModeType lockModeType)
        Description copied from interface: Mutiny.Session
        Asynchronously return the persistent instance of the given entity class with the given identifier, requesting the given LockModeType.
        Specified by:
        find in interface Mutiny.Session
        Parameters:
        entityClass - The entity type
        id - an identifier
        lockModeType - the requested LockModeType
        Returns:
        a persistent instance or null via a Uni
        See Also:
        Mutiny.Session.find(Class, Object), this discussion of lock modes
      • find

        public <T> io.smallrye.mutiny.Uni<T> find​(jakarta.persistence.EntityGraph<T> entityGraph,
                                                  Object id)
        Description copied from interface: Mutiny.Session
        Asynchronously return the persistent instance with the given identifier of an entity class, using the given EntityGraph as a fetch plan.
        Specified by:
        find in interface Mutiny.Session
        Parameters:
        entityGraph - an EntityGraph specifying the entity and associations to be fetched
        id - an identifier
        See Also:
        Mutiny.Session.find(Class, Object)
      • find

        public <T> io.smallrye.mutiny.Uni<List<T>> find​(Class<T> entityClass,
                                                        Object... ids)
        Description copied from interface: Mutiny.Session
        Asynchronously return the persistent instances of the given entity class with the given identifiers, or null if there is no such persistent instance.
        Specified by:
        find in interface Mutiny.Session
        Parameters:
        entityClass - The entity type
        ids - the identifiers
        Returns:
        a list of persistent instances and nulls via a Uni
      • createNativeQuery

        public <R> Mutiny.SelectionQuery<R> createNativeQuery​(String queryString,
                                                              Class<R> resultType,
                                                              AffectedEntities affectedEntities)
        Description copied from interface: Mutiny.Session
        Create an instance of Mutiny.SelectionQuery for the given SQL query string, using the given resultType to interpret the results.
        • If the given result type is Object, or a built-in type such as String or Integer, the result set must have a single column, which will be returned as a scalar.
        • If the given result type is Object[], then the result set must have multiple columns, which will be returned in arrays.
        • Otherwise, the given result type must be an entity class, in which case the result set column aliases must map to the fields of the entity, and the query will return instances of the entity.

        Any affected entities are synchronized with the database before execution of the query.

        Specified by:
        createNativeQuery in interface Mutiny.Session
        Parameters:
        queryString - The SQL query
        resultType - the Java type returned in each row of query results
        affectedEntities - The entities which are affected by the query
        Returns:
        The Mutiny.Query instance for manipulation and execution
        See Also:
        EntityManager.createNativeQuery(String, Class)
      • isDefaultReadOnly

        public boolean isDefaultReadOnly()
        Specified by:
        isDefaultReadOnly in interface Mutiny.Session
        Returns:
        the default read-only mode for entities and proxies loaded in this session
      • unproxy

        public <T> io.smallrye.mutiny.Uni<T> unproxy​(T association)
        Description copied from interface: Mutiny.Session
        Asynchronously fetch an association that's configured for lazy loading, and unwrap the underlying entity implementation from any proxy.
         session.unproxy(author.getBook()).thenAccept(book -> print(book.getTitle()));
         
        Specified by:
        unproxy in interface Mutiny.Session
        Parameters:
        association - a lazy-loaded association
        Returns:
        the fetched association, via a Uni
        See Also:
        Hibernate.unproxy(Object)
      • refresh

        public io.smallrye.mutiny.Uni<Void> refresh​(Object entity,
                                                    jakarta.persistence.LockModeType lockModeType)
        Description copied from interface: Mutiny.Session
        Re-read the state of the given instance from the underlying database, requesting the given LockModeType.
        Specified by:
        refresh in interface Mutiny.Session
        Parameters:
        entity - a managed persistent entity instance
        lockModeType - the requested lock mode
        See Also:
        Mutiny.Session.refresh(Object)
      • lock

        public io.smallrye.mutiny.Uni<Void> lock​(Object entity,
                                                 jakarta.persistence.LockModeType lockModeType)
        Description copied from interface: Mutiny.Session
        Obtain the specified lock level upon the given object. For example, this operation may be used to:
        • perform a version check with LockModeType.PESSIMISTIC_READ,
        • upgrade to a pessimistic lock with LockModeType.PESSIMISTIC_WRITE,
        • force a version increment with LockModeType.PESSIMISTIC_FORCE_INCREMENT,
        • schedule a version check just before the end of the transaction with LockModeType.OPTIMISTIC, or
        • schedule a version increment just before the end of the transaction with LockModeType.OPTIMISTIC_FORCE_INCREMENT.

        This operation cascades to associated instances if the association is mapped with CascadeType.LOCK.

        Specified by:
        lock in interface Mutiny.Session
        Parameters:
        entity - a managed persistent instance
        lockModeType - the lock level
      • find

        @Incubating
        public <T> io.smallrye.mutiny.Uni<T> find​(Class<T> entityClass,
                                                  Identifier<T> naturalId)
        Description copied from interface: Mutiny.Session
        Asynchronously return the persistent instance of the given entity class with the given natural identifier, or null if there is no such persistent instance.
        Specified by:
        find in interface Mutiny.Session
        Parameters:
        entityClass - The entity type
        naturalId - the natural identifier
        Returns:
        a persistent instance or null via a Uni
      • withTransaction

        public <T> io.smallrye.mutiny.Uni<T> withTransaction​(Function<Mutiny.Transaction,​io.smallrye.mutiny.Uni<T>> work)
        Description copied from interface: Mutiny.Session
        Performs the given work within the scope of a database transaction, automatically flushing the session. The transaction will be rolled back if the work completes with an uncaught exception, or if Mutiny.Transaction.markForRollback() is called.

        The resulting Mutiny.Transaction object may also be obtained via Mutiny.Session.currentTransaction().

      • If there is already a transaction associated with this session, the work is executed in the context of the existing transaction, and no new transaction is initiated.
      • If there is no transaction associated with this session, a new transaction is started, and the work is executed in the context of the new transaction.
Specified by:
withTransaction in interface Mutiny.Session
Parameters:
work - a function which accepts Mutiny.Transaction and returns the result of the work as a Uni.
See Also:
Mutiny.SessionFactory.withTransaction(BiFunction)