Package play.db.jpa

Class 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
    • Constructor Detail

      • GenericModel

        public GenericModel()
    • 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)
        Create a new model
        Type Parameters:
        T - The entity class
        Parameters:
        type - the class of the object
        name - name of the object
        params - parameters used to create the new object
        annotations - 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 object
        name - name of the object
        type - the class of the object
        annotations - 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)
        Edit a model
        Type Parameters:
        T - class of the entity
        Parameters:
        o - Object to edit
        name - name of the object
        params - list of parameters
        annotations - 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 object
        name - name of the object
        o - the entity to update
        annotations - 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 name
        rootParamNode - parameters used to create the new object
        name - name of the object
        o - the entity to update
        annotations - 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.
        Edit a model
        Type Parameters:
        T - class of the entity
        Parameters:
        name - name of the entity
        params - 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 object
        name - 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 name
        rootParamNode - parameters used to create the new object
        name - 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 model
        params - 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 shortcut
        params - 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 shortcut
        params - 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 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
      • _setupAttachment

        public void _setupAttachment()
      • _saveAttachment

        public void _saveAttachment()