Package play.db.jpa

Class DefaultJPAApi

java.lang.Object
play.db.jpa.DefaultJPAApi
All Implemented Interfaces:
JPAApi

public class DefaultJPAApi extends Object implements JPAApi
Default implementation of the JPA API.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    jakarta.persistence.EntityManager
    em(String name)
    Get a newly created EntityManager for the specified persistence unit name.
    void
    Close all entity manager factories.
    Initialise JPA entity manager factories.
    void
    withTransaction(String name, boolean readOnly, Consumer<jakarta.persistence.EntityManager> block)
    Run a block of code with a newly created EntityManager for the named Persistence Unit.
    <T> T
    withTransaction(String name, boolean readOnly, Function<jakarta.persistence.EntityManager,T> block)
    Run a block of code with a newly created EntityManager for the named Persistence Unit.
    void
    withTransaction(String name, Consumer<jakarta.persistence.EntityManager> block)
    Run a block of code with a newly created EntityManager for the named Persistence Unit.
    <T> T
    withTransaction(String name, Function<jakarta.persistence.EntityManager,T> block)
    Run a block of code with a newly created EntityManager for the named Persistence Unit.
    void
    withTransaction(Consumer<jakarta.persistence.EntityManager> block)
    Run a block of code with a newly created EntityManager for the default Persistence Unit.
    <T> T
    withTransaction(Function<jakarta.persistence.EntityManager,T> block)
    Run a block of code with a newly created EntityManager for the default Persistence Unit.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultJPAApi

      public DefaultJPAApi(JPAConfig jpaConfig)
  • Method Details

    • start

      public JPAApi start()
      Initialise JPA entity manager factories.
      Specified by:
      start in interface JPAApi
      Returns:
      JPAApi instance
    • em

      public jakarta.persistence.EntityManager em(String name)
      Get a newly created EntityManager for the specified persistence unit name.
      Specified by:
      em in interface JPAApi
      Parameters:
      name - The persistence unit name
      Returns:
      EntityManager for the specified persistence unit name
    • withTransaction

      public <T> T withTransaction(Function<jakarta.persistence.EntityManager,T> block)
      Run a block of code with a newly created EntityManager for the default Persistence Unit.
      Specified by:
      withTransaction in interface JPAApi
      Type Parameters:
      T - type of result
      Parameters:
      block - Block of code to execute
      Returns:
      code execution result
    • withTransaction

      public void withTransaction(Consumer<jakarta.persistence.EntityManager> block)
      Run a block of code with a newly created EntityManager for the default Persistence Unit.
      Specified by:
      withTransaction in interface JPAApi
      Parameters:
      block - Block of code to execute
    • withTransaction

      public <T> T withTransaction(String name, Function<jakarta.persistence.EntityManager,T> block)
      Run a block of code with a newly created EntityManager for the named Persistence Unit.
      Specified by:
      withTransaction in interface JPAApi
      Type Parameters:
      T - type of result
      Parameters:
      name - The persistence unit name
      block - Block of code to execute
      Returns:
      code execution result
    • withTransaction

      public void withTransaction(String name, Consumer<jakarta.persistence.EntityManager> block)
      Run a block of code with a newly created EntityManager for the named Persistence Unit.
      Specified by:
      withTransaction in interface JPAApi
      Parameters:
      name - The persistence unit name
      block - Block of code to execute
    • withTransaction

      public <T> T withTransaction(String name, boolean readOnly, Function<jakarta.persistence.EntityManager,T> block)
      Run a block of code with a newly created EntityManager for the named Persistence Unit.
      Specified by:
      withTransaction in interface JPAApi
      Type Parameters:
      T - type of result
      Parameters:
      name - The persistence unit name
      readOnly - Is the transaction read-only?
      block - Block of code to execute
      Returns:
      code execution result
    • withTransaction

      public void withTransaction(String name, boolean readOnly, Consumer<jakarta.persistence.EntityManager> block)
      Run a block of code with a newly created EntityManager for the named Persistence Unit.
      Specified by:
      withTransaction in interface JPAApi
      Parameters:
      name - The persistence unit name
      readOnly - Is the transaction read-only?
      block - Block of code to execute
    • shutdown

      public void shutdown()
      Close all entity manager factories.
      Specified by:
      shutdown in interface JPAApi