Package play.db.jpa
Class GenericModel
- java.lang.Object
-
- play.db.jpa.JPABase
-
- play.db.jpa.GenericModel
-
- All Implemented Interfaces:
java.io.Serializable
,Model
- Direct Known Subclasses:
JPASupport
,Model
@MappedSuperclass public class GenericModel extends JPABase
A super class for JPA entities- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GenericModel.JPAQuery
A JPAQuery-
Nested classes/interfaces inherited from class play.db.jpa.JPABase
JPABase.JPAQueryException
-
Nested classes/interfaces inherited from interface play.db.Model
Model.BinaryField, Model.Choices, Model.Factory, Model.Manager, Model.Property
-
-
Field Summary
-
Fields inherited from class play.db.jpa.JPABase
willBeSaved
-
-
Constructor Summary
Constructors Constructor Description GenericModel()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
_saveAttachment()
void
_setupAttachment()
static GenericModel.JPAQuery
all()
Prepare a query to find *all* entities.static long
count()
Count entitiesstatic long
count(java.lang.String query, java.lang.Object... params)
Count entities with a special query.boolean
create()
store (ie insert) the entity.static <T extends JPABase>
Tcreate(java.lang.Class<?> type, java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params, java.lang.annotation.Annotation[] annotations)
Deprecated.use method {create(ParamNode, String, Class, Annotation[])
}static <T extends JPABase>
Tcreate(java.lang.String name, Scope.Params params)
Create the new entitystatic <T extends JPABase>
Tcreate(ParamNode rootParamNode, java.lang.String name, java.lang.Class<?> type, java.lang.annotation.Annotation[] annotations)
Create a new model<T extends JPABase>
Tdelete()
Delete the entity.static int
delete(java.lang.String query, java.lang.Object... params)
Batch delete of entitiesstatic int
deleteAll()
Delete all entitiesstatic <T extends JPABase>
Tedit(java.lang.Object o, java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params, java.lang.annotation.Annotation[] annotations)
Deprecated.use method {edit(ParamNode, String, Object, Annotation[])
}<T extends GenericModel>
Tedit(java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params)
Deprecated.use method {edit(ParamNode, String)
}<T extends GenericModel>
Tedit(java.lang.String dbName, ParamNode rootParamNode, java.lang.String name)
Edit a modelstatic <T extends JPABase>
Tedit(java.lang.String dbName, ParamNode rootParamNode, java.lang.String name, java.lang.Object o, java.lang.annotation.Annotation[] annotations)
Edit a model<T extends GenericModel>
Tedit(ParamNode rootParamNode, java.lang.String name)
Edit a modelstatic <T extends JPABase>
Tedit(ParamNode rootParamNode, java.lang.String name, java.lang.Object o, java.lang.annotation.Annotation[] annotations)
Edit a modelstatic GenericModel.JPAQuery
find(java.lang.String query, java.lang.Object... params)
Prepare a query to find entities.static <T extends JPABase>
java.util.List<T>findAll()
Find all entities of this typestatic <T extends JPABase>
TfindById(java.lang.Object id)
Find the entity with the corresponding id.<T extends JPABase>
Tmerge()
Merge this object to obtain a managed entity (useful when the object comes from the Cache).<T extends JPABase>
Trefresh()
Refresh the entity state.<T extends JPABase>
Tsave()
store (ie insert) the entity.boolean
validateAndCreate()
Validate and create the entityboolean
validateAndSave()
Validate and store the entity-
Methods inherited from class play.db.jpa.JPABase
_delete, _key, _save, em, em, equals, getEntityId, hashCode, isPersistent, isPersistent, toString
-
-
-
-
Method Detail
-
create
@Deprecated public static <T extends JPABase> T create(java.lang.Class<?> type, java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params, java.lang.annotation.Annotation[] annotations)
Deprecated.use method {create(ParamNode, String, Class, Annotation[])
}Create a new model- Type Parameters:
T
- The entity class- Parameters:
type
- the class of the objectname
- name of the objectparams
- parameters used to create the new objectannotations
- annotations on the model- Returns:
- The created entity
-
create
public static <T extends JPABase> T create(ParamNode rootParamNode, java.lang.String name, java.lang.Class<?> type, java.lang.annotation.Annotation[] annotations)
Create a new model- Type Parameters:
T
- The entity class- Parameters:
rootParamNode
- parameters used to create the new objectname
- name of the objecttype
- the class of the objectannotations
- annotations on the model- Returns:
- The created entity
-
edit
@Deprecated public static <T extends JPABase> T edit(java.lang.Object o, java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params, java.lang.annotation.Annotation[] annotations)
Deprecated.use method {edit(ParamNode, String, Object, Annotation[])
}Edit a model- Type Parameters:
T
- class of the entity- Parameters:
o
- Object to editname
- name of the objectparams
- list of parametersannotations
- annotations on the model- Returns:
- the entity
- See Also:
edit(ParamNode, String, Object, Annotation[])
-
edit
public static <T extends JPABase> T edit(ParamNode rootParamNode, java.lang.String name, java.lang.Object o, java.lang.annotation.Annotation[] annotations)
Edit a model- Type Parameters:
T
- class of the entity- Parameters:
rootParamNode
- parameters used to create the new objectname
- name of the objecto
- the entity to updateannotations
- annotations on the model- Returns:
- the entity
-
edit
public static <T extends JPABase> T edit(java.lang.String dbName, ParamNode rootParamNode, java.lang.String name, java.lang.Object o, java.lang.annotation.Annotation[] annotations)
Edit a model- Type Parameters:
T
- class of the entity- Parameters:
dbName
- the db namerootParamNode
- parameters used to create the new objectname
- name of the objecto
- the entity to updateannotations
- annotations on the model- Returns:
- the entity
-
edit
@Deprecated public <T extends GenericModel> T edit(java.lang.String name, java.util.Map<java.lang.String,java.lang.String[]> params)
Deprecated.use method {edit(ParamNode, String)
}Edit a model- Type Parameters:
T
- class of the entity- Parameters:
name
- name of the entityparams
- list of parameters- Returns:
- the entity
-
edit
public <T extends GenericModel> T edit(ParamNode rootParamNode, java.lang.String name)
Edit a model- Type Parameters:
T
- class of the entity- Parameters:
rootParamNode
- parameters used to create the new objectname
- name of the entity- Returns:
- the entity
-
edit
public <T extends GenericModel> T edit(java.lang.String dbName, ParamNode rootParamNode, java.lang.String name)
Edit a model- Type Parameters:
T
- class of the entity- Parameters:
dbName
- the db namerootParamNode
- parameters used to create the new objectname
- name of the entity- Returns:
- the entity
-
validateAndSave
public boolean validateAndSave()
Validate and store the entity- Returns:
- true if successful
-
validateAndCreate
public boolean validateAndCreate()
Validate and create the entity- Returns:
- true if successful
-
save
public <T extends JPABase> T save()
store (ie insert) the entity.- Type Parameters:
T
- class of the entity- Returns:
- true if successful
-
create
public boolean create()
store (ie insert) the entity.- Returns:
- true if successful
-
refresh
public <T extends JPABase> T refresh()
Refresh the entity state.- Type Parameters:
T
- class of the entity- Returns:
- The given entity
-
merge
public <T extends JPABase> T merge()
Merge this object to obtain a managed entity (useful when the object comes from the Cache).- Type Parameters:
T
- class of the entity- Returns:
- The given entity
-
delete
public <T extends JPABase> T delete()
Delete the entity.- Type Parameters:
T
- class of the entity- Returns:
- The deleted entity.
-
create
public static <T extends JPABase> T create(java.lang.String name, Scope.Params params)
Create the new entity- Type Parameters:
T
- class of the entity- Parameters:
name
- name of the modelparams
- list of parameters- Returns:
- The created entity.
-
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 shortcutparams
- Params to bind to the query- Returns:
- A long
-
findAll
public static <T extends JPABase> java.util.List<T> findAll()
Find all entities of this type- Type Parameters:
T
- the type of the entity- Returns:
- All entities of this type
-
findById
public static <T extends JPABase> T findById(java.lang.Object id)
Find the entity with the corresponding id.- Type Parameters:
T
- the type of the entity- Parameters:
id
- The entity id- Returns:
- The entity
-
find
public static GenericModel.JPAQuery find(java.lang.String query, java.lang.Object... params)
Prepare a query to find entities.- Parameters:
query
- HQL query or shortcutparams
- Params to bind to the query- Returns:
- A JPAQuery
-
all
public static GenericModel.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 shortcutparams
- Params to bind to the query- Returns:
- Number of entities deleted
-
deleteAll
public static int deleteAll()
Delete all entities- Returns:
- Number of entities deleted
-
_setupAttachment
public void _setupAttachment()
-
_saveAttachment
public void _saveAttachment()
-
-