play.db.jpa
Class JPASupport

java.lang.Object
  extended by play.db.jpa.JPASupport
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
JPAModel

public class JPASupport
extends java.lang.Object
implements java.io.Serializable

A super class for JPA entities

See Also:
Serialized Form

Nested Class Summary
static class JPASupport.JPAQuery
          A JPAQuery
 
Field Summary
 boolean willBeSaved
           
 
Constructor Summary
JPASupport()
           
 
Method Summary
static JPASupport.JPAQuery all()
          Prepare a query to find *all* entities.
static long count()
          Count entities
static long count(java.lang.String query, java.lang.Object... params)
          Count entities with a special query.
static
<T extends JPASupport>
T
create(java.lang.Class type, java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params)
           
static
<T extends JPASupport>
T
create(java.lang.String name, Scope.Params params)
           
<T extends JPASupport>
T
delete()
          Delete the entity.
static int delete(java.lang.String query, java.lang.Object... params)
          Batch delete of entities
static int deleteAll()
          Delete all entities
static
<T extends JPASupport>
T
edit(java.lang.Object o, java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params)
           
<T extends JPASupport>
T
edit(java.lang.String name, Scope.Params params)
           
static javax.persistence.EntityManager em()
          Retrieve the current entityManager
 boolean equals(java.lang.Object other)
          JPASupport instances a and b are equals if either a == b or a and b have same id and class
static JPASupport.JPAQuery find()
          Deprecated. 
static JPASupport.JPAQuery find(java.lang.String query, java.lang.Object... params)
          Prepare a query to find entities.
static
<T extends JPASupport>
java.util.List<T>
findAll()
          Find all entities of this type
static
<T extends JPASupport>
java.util.List<T>
findBy(java.lang.String query, java.lang.Object... params)
          Deprecated. 
static
<T extends JPASupport>
T
findById(java.lang.Object id)
          Find the entity with the corresponding id.
static java.lang.Object findKey(java.lang.Object entity)
           
static java.lang.Class findKeyType(java.lang.Class c)
           
static
<T extends JPASupport>
T
findOneBy(java.lang.String query, java.lang.Object... params)
          Deprecated. 
 java.lang.Object getEntityId()
           
static javax.persistence.EntityManager getEntityManager()
          Deprecated. 
 int hashCode()
           
<T extends JPASupport>
T
merge()
          Merge this object to obtain a managed entity (usefull when the object comes from the Cache).
 void onLoad()
           
 void onSave()
           
<T extends JPASupport>
T
refresh()
          Refresh the entity state.
<T extends JPASupport>
T
save()
          store (ie insert) the entity.
 void saveAttachment()
           
 void setupAttachment()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

willBeSaved

public transient boolean willBeSaved
Constructor Detail

JPASupport

public JPASupport()
Method Detail

create

public static <T extends JPASupport> T create(java.lang.Class type,
                                              java.lang.String name,
                                              java.util.Map<java.lang.String,java.lang.String[]> params)

edit

public <T extends JPASupport> T edit(java.lang.String name,
                                     Scope.Params params)

edit

public static <T extends JPASupport> T edit(java.lang.Object o,
                                            java.lang.String name,
                                            java.util.Map<java.lang.String,java.lang.String[]> params)

save

public <T extends JPASupport> T save()
store (ie insert) the entity.


refresh

public <T extends JPASupport> T refresh()
Refresh the entity state.


merge

public <T extends JPASupport> T merge()
Merge this object to obtain a managed entity (usefull when the object comes from the Cache).


delete

public <T extends JPASupport> T delete()
Delete the entity.

Returns:
The deleted entity.

create

public static <T extends JPASupport> T create(java.lang.String name,
                                              Scope.Params params)

count

public static long count()
Count entities

Returns:
number of entities of this class

count

public static long count(java.lang.String query,
                         java.lang.Object... params)
Count entities with a special query. Example : Long moderatedPosts = Post.count("moderated", true);

Parameters:
query - HQL query or shortcut
params - Params to bind to the query
Returns:
A long

findAll

public static <T extends JPASupport> java.util.List<T> findAll()
Find all entities of this type


findById

public static <T extends JPASupport> T findById(java.lang.Object id)
Find the entity with the corresponding id.

Parameters:
id - The entity id
Returns:
The entity

find

public static JPASupport.JPAQuery find(java.lang.String query,
                                       java.lang.Object... params)
Prepare a query to find entities.

Parameters:
query - HQL query or shortcut
params - Params to bind to the query
Returns:
A JPAQuery

find

@Deprecated
public static JPASupport.JPAQuery find()
Deprecated. 

Try all()


all

public static JPASupport.JPAQuery all()
Prepare a query to find *all* entities.

Returns:
A JPAQuery

delete

public static int delete(java.lang.String query,
                         java.lang.Object... params)
Batch delete of entities

Parameters:
query - HQL query or shortcut
params - Params to bind to the query
Returns:
Number of entities deleted

deleteAll

public static int deleteAll()
Delete all entities

Returns:
Number of entities deleted

findOneBy

@Deprecated
public static <T extends JPASupport> T findOneBy(java.lang.String query,
                                                            java.lang.Object... params)
Deprecated. 

find one item matching the parametrized query

Type Parameters:
T -
Parameters:
query - the parametrized query expressed in OQL
params - parameters of the query
Returns:
the first item matching the query or null

findBy

@Deprecated
public static <T extends JPASupport> java.util.List<T> findBy(java.lang.String query,
                                                                         java.lang.Object... params)
Deprecated. 

find all items matching a parametrized query

Type Parameters:
T -
Parameters:
query - the parametrized query expressed in OQL
params - parameters of the query
Returns:
a list of items matching the query

em

public static javax.persistence.EntityManager em()
Retrieve the current entityManager

Returns:
the current entityManager

getEntityManager

@Deprecated
public static javax.persistence.EntityManager getEntityManager()
Deprecated. 

Try em();


equals

public boolean equals(java.lang.Object other)
JPASupport instances a and b are equals if either a == b or a and b have same id and class

Overrides:
equals in class java.lang.Object
Parameters:
other -
Returns:
true if equality condition above is verified

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setupAttachment

public void setupAttachment()

saveAttachment

public void saveAttachment()

findKey

public static java.lang.Object findKey(java.lang.Object entity)

findKeyType

public static java.lang.Class findKeyType(java.lang.Class c)

getEntityId

public java.lang.Object getEntityId()

onLoad

public void onLoad()

onSave

public void onSave()


Guillaume Bort & zenexity - Distributed under Apache 2 licence, without any warrantly