org.scala_libs.jpa

ScalaEntityManager

trait ScalaEntityManager extends AnyRef

This trait represents a Scalafied version of the standard EntityManager in JPA. In particular, queries are more type-safe and the find method returns an Option instead of possibly throwing an exception if the entity isn't found.

If you wish to provide a concrete implementation of this trait, you only need to provide the em method and factory val.

known subclasses: ThreadLocalEM
    authors:
  1. Derek Chen-Becker

Inherited
  1. Hide All
  2. Show all
  1. AnyRef
  2. Any
Visibility
  1. Public
  2. All

Value Members

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

    attributes: final
    definition classes: AnyRef
  2. def !=(arg0: Any): Boolean

    o != arg0 is the same as !(o == (arg0)).

    o != arg0 is the same as !(o == (arg0)).

    arg0

    the object to compare against this object for dis-equality.

    returns

    false if the receiver object is equivalent to the argument; true otherwise.

    attributes: final
    definition classes: Any
  3. def ##(): Int

    attributes: final
    definition classes: AnyRef → Any
  4. def $asInstanceOf[T0](): T0

    attributes: final
    definition classes: AnyRef
  5. def $isInstanceOf[T0](): Boolean

    attributes: final
    definition classes: AnyRef
  6. def ==(arg0: AnyRef): Boolean

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    attributes: final
    definition classes: AnyRef
  7. def ==(arg0: Any): Boolean

    o == arg0 is the same as o.equals(arg0).

    o == arg0 is the same as o.equals(arg0).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    attributes: final
    definition classes: Any
  8. def asInstanceOf[T0]: T0

    This method is used to cast the receiver object to be of type T0.

    This method is used to cast the receiver object to be of type T0.

    Note that the success of a cast at runtime is modulo Scala's erasure semantics. Therefore the expression1.asInstanceOf[String] will throw a ClassCastException at runtime, while the expressionList(1).asInstanceOf[List[String]] will not. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested typed.

    returns

    the receiver object.

    attributes: final
    definition classes: Any
  9. 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.

  10. def clone(): AnyRef

    This method creates and returns a copy of the receiver object.

    This method creates and returns a copy of the receiver object.

    The default implementation of the clone method is platform dependent.

    returns

    a copy of the receiver object.

    attributes: protected
    definition classes: AnyRef
  11. def close(): Unit

    Closes the EntityManager.

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

  12. 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

  13. 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

  14. 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]

  15. 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

  16. 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

  17. 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

  18. 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. Seehttp://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

  19. 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.

    attributes: protected abstract
  20. def eq(arg0: AnyRef): Boolean

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

    The eq method implements an [http://en.wikipedia.org/wiki/Equivalence_relation equivalence relation] on non-null instances of AnyRef: * It is reflexive: for any non-null instance x of type AnyRef, x.eq(x) returns true. * It is symmetric: for any non-null instances x and y of type AnyRef, x.eq(y) returns true if and only if y.eq(x) returns true. * It is transitive: for any non-null instances x, y, and z of type AnyRef if x.eq(y) returns true and y.eq(z) returns true, then x.eq(z) returns true.

    Additionally, the eq method has three other properties. * It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of x.eq(y) consistently returns true or consistently returns false. * For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false. * null.eq(null) returns true.

    When overriding the equals or hashCode methods, it is important to ensure that their behavior is consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

    arg0

    the object to compare against this object for reference equality.

    returns

    true if the argument is a reference to the receiver object; false otherwise.

    attributes: final
    definition classes: AnyRef
  21. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

    The default implementations of this method is an [http://en.wikipedia.org/wiki/Equivalence_relation equivalence relation]: * It is reflexive: for any instance x of type Any, x.equals(x) should return true. * It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true. * It is transitive: for any instances x, y, and z of type AnyRef if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

    If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is often necessary to override hashCode to ensure that objects that are "equal" (o1.equals(o2) returns true) hash to the same scala.Int (o1.hashCode.equals(o2.hashCode)).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    definition classes: AnyRef → Any
  22. val factory: ScalaEMFactory

    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.

    attributes: abstract
  23. def finalize(): Unit

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object.

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object.

    The details of when and if the finalize method are invoked, as well as the interaction between finalizeand non-local returns and exceptions, are all platform dependent.

    attributes: protected
    definition classes: AnyRef
  24. 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

  25. def findAll[A](queryName: String, params: (String, Any)*): Buffer[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

  26. 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.

  27. def getClass(): java.lang.Class[_]

    Returns a representation that corresponds to the dynamic class of the receiver object.

    Returns a representation that corresponds to the dynamic class of the receiver object.

    The nature of the representation is platform dependent.

    returns

    a representation that corresponds to the dynamic class of the receiver object.

    attributes: final
    definition classes: AnyRef
  28. 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

  29. def getFlushMode(): FlushModeType

    Returns the current flush mode for the EntityManager

    Returns the current flush mode for the EntityManager

      see also:
    1. javax.persistence.FlushModeType

  30. 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

  31. 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

  32. def hashCode(): Int

    Returns a hash code value for the object.

    Returns a hash code value for the object.

    The default hashing algorithm is platform dependent.

    Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

    returns

    the hash code value for the object.

    definition classes: AnyRef → Any
  33. def isInstanceOf[T0]: Boolean

    This method is used to test whether the dynamic type of the receiver object is T0.

    This method is used to test whether the dynamic type of the receiver object is T0.

    Note that the test result of the test is modulo Scala's erasure semantics. Therefore the expression1.isInstanceOf[String] will return false, while the expression List(1).isInstanceOf[List[String]] will return true. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested typed.

    returns

    true if the receiver object is an instance of erasure of type T0; false otherwise.

    attributes: final
    definition classes: Any
  34. 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

  35. 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.

  36. 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

      see also:
    1. javax.persistence.LockModeType

  37. 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

  38. 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.

  39. def ne(arg0: AnyRef): Boolean

    o.ne(arg0) is the same as !(o.eq(arg0)).

    o.ne(arg0) is the same as !(o.eq(arg0)).

    arg0

    the object to compare against this object for reference dis-equality.

    returns

    false if the argument is not a reference to the receiver object; true otherwise.

    attributes: final
    definition classes: AnyRef
  40. def notify(): Unit

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Wakes up a single thread that is waiting on the receiver object's monitor.

    attributes: final
    definition classes: AnyRef
  41. def notifyAll(): Unit

    Wakes up all threads that are waiting on the receiver object's monitor.

    Wakes up all threads that are waiting on the receiver object's monitor.

    attributes: final
    definition classes: AnyRef
  42. def persist(entity: AnyRef): Unit

    Persists the given entity.

    Persists the given entity.

    entity

    The entity to persist

  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.

  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

  45. def remove(entity: AnyRef): Unit

    Removes the given entity.

    Removes the given entity.

    entity

    The entity to remove

  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.

  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

      see also:
    1. javax.persistence.FlushModeType

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

    attributes: final
    definition classes: AnyRef
  49. def toString(): String

    Returns a string representation of the object.

    Returns a string representation of the object.

    The default representation is platform dependent.

    returns

    a string representation of the object.

    definition classes: AnyRef → Any
  50. def wait(): Unit

    attributes: final
    definition classes: AnyRef
  51. def wait(arg0: Long, arg1: Int): Unit

    attributes: final
    definition classes: AnyRef
  52. def wait(arg0: Long): Unit

    attributes: final
    definition classes: AnyRef