org.scala_libs.jpa

ThreadLocalEM

trait ThreadLocalEM extends ScalaEntityManager with ScalaEMFactory

This trait can be mixed in so that an object may provide access to EntityManager instances on a thread-local basis. An example would be:

object MyEM extends LocalEMF("test") with ThreadLocalEM

...
MyEM.createNamedQuery(...)

MyEM.cleanup()
...

Best practice for this code is to ensure that when the thread exits it calls the cleanup method so that the EM is properly closed.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. ThreadLocalEM
  2. ScalaEMFactory
  3. ScalaEntityManager
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def closeEM(em: EntityManager): Unit

    Handles closing a previously opened EntityManager.

    Handles closing a previously opened EntityManager. Subclasses must provide a concrete implementation.

    em

    The EntityManager to close

    Attributes
    protected[org.scala_libs.jpa]
    Definition Classes
    ScalaEMFactory
  2. abstract def getUnitName: String

    Return the name of the configured persistence unit name

    Return the name of the configured persistence unit name

    Attributes
    protected
    Definition Classes
    ScalaEMFactory
  3. abstract def openEM(): EntityManager

    Handles the actual opening of an EntityManager.

    Handles the actual opening of an EntityManager. Subclasses must provide a concrete implementation.

    returns

    An appropriately configured EntityManager

    Attributes
    protected
    Definition Classes
    ScalaEMFactory

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def cleanup(): Unit

    Cleans up the current thread's EntityManager by closing it and removing the em from the thread-local storage.

  8. def clear(): Unit

    Clears the persistence context.

    Clears the persistence context. Changes made to any entities that have not been flushed to the database will not be persisted.

    Definition Classes
    ScalaEntityManager
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  10. def close(): Unit

    Closes the EntityManager.

    Closes the EntityManager. Subclasses may override this if they desire different behavior.

    Definition Classes
    ScalaEntityManager
  11. def contains(entity: AnyRef): Boolean

    Tests to see if the given entity is attached to the current EntityManager

    Tests to see if the given entity is attached to the current EntityManager

    entity

    The entity to check

    returns

    true if attached, false otherwise

    Definition Classes
    ScalaEntityManager
  12. def createNamedQuery[A](queryName: String): ScalaQuery[A]

    Creates a new ScalaQuery[A] using the given named query.

    Creates a new ScalaQuery[A] using the given named query. The results of the named query should be of type A.

    queryName

    The named query to use

    returns

    A new ScalaQuery[A] that uses the given named query

    Definition Classes
    ScalaEntityManager
  13. def createNamedQuery[A](queryName: String, params: (String, Any)*): ScalaQuery[A]

    Creates a ScalaQuery representing the given named query with the given parameters set.

    Creates a ScalaQuery representing the given named query with the given parameters set. This can be used if you want to use some of the extended functionality of ScalaQuery, such as pagination or using query hints. An example would be:

    val query = EM.createNamedQuery[Book]("findAllBooks") query.setFirstResult(20).setMaxResults(100)

    queryName

    The name of the query to execute

    params

    Zero or more pairs of (paramName,paramValue)

    returns

    The created ScalaQuery[A]

    Definition Classes
    ScalaEntityManager
  14. def createNativeQuery[A](sqlString: String, resultSetMapping: String): ScalaQuery[A]

    Creates a new ScalaQuery[A] using the given native SQL query.

    Creates a new ScalaQuery[A] using the given native SQL query. For more details on using native queries, see http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/query_native.html.

    sqlString

    The query string to use

    resultSetMapping

    The name of the mapping from the result set to entities

    returns

    A new ScalaQuery[A] that uses the given native SQL

    Definition Classes
    ScalaEntityManager
  15. def createNativeQuery[A](sqlString: String, clazz: Class[A]): ScalaQuery[A]

    Creates a new ScalaQuery[A] using the given native SQL query.

    Creates a new ScalaQuery[A] using the given native SQL query. For more details on using native queries, see http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/query_native.html.

    sqlString

    The query string to use

    clazz

    The class of the returned entities

    returns

    A new ScalaQuery[A] that uses the given native SQL

    Definition Classes
    ScalaEntityManager
  16. def createNativeQuery[A](sqlString: String): ScalaQuery[A]

    Creates a new ScalaQuery[A] using the given native SQL query.

    Creates a new ScalaQuery[A] using the given native SQL query. For more details on using native queries, see http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/query_native.html.

    sqlString

    The query string to use

    returns

    A new ScalaQuery[A] that uses the given native SQL

    Definition Classes
    ScalaEntityManager
  17. def createQuery[A](queryString: String): ScalaQuery[A]

    Creates a new ScalaQuery[A] using the given query string.

    Creates a new ScalaQuery[A] using the given query string. The results of the query should be of type A. See http://www.hibernate.org/hib_docs/entitymanager/reference/en/html/queryhql.html for an EJB-QL reference.

    queryString

    The query string (EJBQL)

    returns

    A new ScalaQuery[A] that uses the given query string

    Definition Classes
    ScalaEntityManager
  18. def em: EntityManager

    Returns the current EntityManager instance.

    Returns the current EntityManager instance. This leaves the implementor free to choose how they want to manage instances. For example, the implementor could use a ThreadLocal to allow for a singleton instance of ScalaEntityManager, or they could simply set up a val to hold the current instance.

    Definition Classes
    ThreadLocalEMScalaEntityManager
  19. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  21. val factory: ThreadLocalEM

    This val should hold a reference to the factory that created this instance, so that the proper closeEM method can be called on shutdown.

    This val should hold a reference to the factory that created this instance, so that the proper closeEM method can be called on shutdown.

    Definition Classes
    ThreadLocalEMScalaEntityManager
  22. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  23. def find[A](clazz: Class[A], id: Any): Option[A]

    Attempts to load a given entity based on its ID.

    Attempts to load a given entity based on its ID. Returns an Option, with None indicating that no entity exists with the given ID.

    clazz

    The class of the entity to load

    id

    The ID of the entity to load

    returns

    An Option with the loaded entity (Some) or None to indicate that an entity could not be loaded

    Definition Classes
    ScalaEntityManager
  24. def findAll[A](queryName: String, params: (String, Any)*): scala.collection.convert.Wrappers.JListWrapper[A]

    Returns a List[A] of the results of excuting the given query.

    Returns a List[A] of the results of excuting the given query. Named parameters may be provided to refine the query. Using Scala's syntax sugar for Pairs and varargs, an example query might look like:

    EM.findAll[User]("byUsername", "username" -> "fred")

    queryName

    The name of the query to execute

    params

    Zero or more pairs of (paramName,paramValue)

    returns

    A List[A] representing the results of the query

    Definition Classes
    ScalaEntityManager
  25. def flush(): Unit

    Forces a flush of the current entity state to the database.

    Forces a flush of the current entity state to the database.

    Definition Classes
    ScalaEntityManager
  26. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  27. def getDelegate(): AnyRef

    Returns the underlying provider object for the EntityManager.

    Returns the underlying provider object for the EntityManager. Implementation-specific.

    returns

    The underlying provider

    Definition Classes
    ScalaEntityManager
  28. def getFlushMode(): FlushModeType

    Returns the current flush mode for the EntityManager

    Returns the current flush mode for the EntityManager

    Definition Classes
    ScalaEntityManager
    See also

    javax.persistence.FlushModeType

  29. def getReference[A](clazz: Class[A], primaryKey: Any): A

    Get an instance, whose state may be lazily fetched.

    Get an instance, whose state may be lazily fetched. An EntityNotFoundException will be thrown when the instance is accessed if no corresponding instance exists in the database. The exception may be thrown when getReference is called.

    clazz

    The class of the instance

    primaryKey

    The primary key of the instance

    returns

    A lazily fetched instance

    Definition Classes
    ScalaEntityManager
  30. def getTransaction(): EntityTransaction

    Returns the current EM's transaction.

    Returns the current EM's transaction. Note that this will throw an exception if you're using JTA for transactions.

    returns

    The current transaction

    Definition Classes
    ScalaEntityManager
  31. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  32. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  33. def isOpen(): Boolean

    Returns a boolean indicating whether the EntityManager is open.

    Returns a boolean indicating whether the EntityManager is open.

    returns

    true if the EntityManager is open, false otherwise

    Definition Classes
    ScalaEntityManager
  34. def joinTransaction(): Unit

    Joins the EM to the currently open JTA transaction.

    Joins the EM to the currently open JTA transaction. Note that this throws and exception if no JTA transaction exists.

    Definition Classes
    ScalaEntityManager
  35. def lock(entity: AnyRef, lockMode: LockModeType): Unit

    Locks the given entity using the given lock mode.

    Locks the given entity using the given lock mode.

    entity

    The entity to lock

    lockMode

    The mode of the lock

    Definition Classes
    ScalaEntityManager
    See also

    javax.persistence.LockModeType

  36. def merge[T](entity: T): T

    Merges the given entity and returns the newly merged copy.

    Merges the given entity and returns the newly merged copy.

    entity

    The entity to merge

    returns

    The newly merged copy

    Definition Classes
    ScalaEntityManager
  37. def mergeAndFlush[T](entity: T): T

    Handles a merge and flush in a single method.

    Handles a merge and flush in a single method. This is useful if your merge should check for constraint violations, since otherwise the merge won't occur until the transaction closes.

    entity

    The entity to merge.

    returns

    A newly merged copy of the entity. The original entity should be discarded.

    Definition Classes
    ScalaEntityManager
  38. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  39. def newEM: ScalaEntityManager

    Returns a newly created ScalaEntityManager.

    Returns a newly created ScalaEntityManager. This is the method that clients would typically use to obtain their EM.

    returns

    A new ScalaEntityManager instance.

    Definition Classes
    ScalaEMFactory
  40. final def notify(): Unit

    Definition Classes
    AnyRef
  41. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  42. def persist(entity: AnyRef): Unit

    Persists the given entity.

    Persists the given entity.

    entity

    The entity to persist

    Definition Classes
    ScalaEntityManager
  43. def persistAndFlush(entity: AnyRef): Unit

    Handles a persist and flush in a single method.

    Handles a persist and flush in a single method. This is useful if your persist should check for constraint violations, since otherwise the persist won't occur until the transaction closes.

    entity

    The entity to persist.

    Definition Classes
    ScalaEntityManager
  44. def refresh(entity: AnyRef): Unit

    Reloads a given entity's state from the database, effectively discarding any local changes.

    Reloads a given entity's state from the database, effectively discarding any local changes.

    entity

    The entity to refresh

    Definition Classes
    ScalaEntityManager
  45. def remove(entity: AnyRef): Unit

    Removes the given entity.

    Removes the given entity.

    entity

    The entity to remove

    Definition Classes
    ScalaEntityManager
  46. def removeAndFlush(entity: AnyRef): Unit

    Handles a remove and flush in a single method.

    Handles a remove and flush in a single method. This is useful if your remove should check for constraint violations, since otherwise the remove won't occur until the transaction closes.

    entity

    The entity to remove.

    Definition Classes
    ScalaEntityManager
  47. def setFlushMode(flushModeType: FlushModeType): Unit

    Sets the flush mode for the EntityManager.

    Sets the flush mode for the EntityManager.

    flushModeType

    The desired flush mode

    Definition Classes
    ScalaEntityManager
    See also

    javax.persistence.FlushModeType

  48. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  49. def toString(): String

    Definition Classes
    AnyRef → Any
  50. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  51. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  52. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from ScalaEMFactory

Inherited from ScalaEntityManager

Inherited from AnyRef

Inherited from Any

Ungrouped