Class AbstractAlpineQueryManager

  • All Implemented Interfaces:
    AutoCloseable
    Direct Known Subclasses:
    AlpineQueryManager

    public abstract class AbstractAlpineQueryManager
    extends Object
    implements AutoCloseable
    Base persistence manager that implements AutoCloseable so that the PersistenceManager will be automatically closed when used in a try-with-resource block.
    Since:
    1.0.0
    Author:
    Steve Springett
    • Field Detail

      • principal

        protected final Principal principal
      • filter

        protected final String filter
      • orderBy

        protected final String orderBy
      • pm

        protected final javax.jdo.PersistenceManager pm
    • Constructor Detail

      • AbstractAlpineQueryManager

        public AbstractAlpineQueryManager​(javax.jdo.PersistenceManager pm)
        Specifies a non-default PersistenceManager to use.
        Parameters:
        pm - the JDO PersistenceManager to use
        Since:
        1.4.3
      • AbstractAlpineQueryManager

        public AbstractAlpineQueryManager()
        Default constructor
      • AbstractAlpineQueryManager

        public AbstractAlpineQueryManager​(Principal principal,
                                          Pagination pagination,
                                          String filter,
                                          String orderBy,
                                          OrderDirection orderDirection)
        Constructs a new QueryManager with the following:
        Parameters:
        principal - a Principal, or null
        pagination - a Pagination request, or null
        filter - a String filter, or null
        orderBy - the field to order by
        orderDirection - the sorting direction
        Since:
        1.0.0
      • AbstractAlpineQueryManager

        public AbstractAlpineQueryManager​(AlpineRequest request)
        Constructs a new QueryManager. Deconstructs the specified AlpineRequest into its individual components including pagination and ordering.
        Parameters:
        request - an AlpineRequest object
        Since:
        1.0.0
    • Method Detail

      • execute

        public PaginatedResult execute​(javax.jdo.Query query)
        Wrapper around Query.execute() that adds transparent support for pagination and ordering of results via decorate(Query).
        Parameters:
        query - the JDO Query object to execute
        Returns:
        a PaginatedResult object
        Since:
        1.0.0
      • execute

        public PaginatedResult execute​(javax.jdo.Query query,
                                       Object p1)
        Wrapper around Query.execute(Object) that adds transparent support for pagination and ordering of results via decorate(Query).
        Parameters:
        query - the JDO Query object to execute
        p1 - the value of the first parameter declared.
        Returns:
        a PaginatedResult object
        Since:
        1.0.0
      • execute

        public PaginatedResult execute​(javax.jdo.Query query,
                                       Object p1,
                                       Object p2)
        Wrapper around Query.execute(Object, Object) that adds transparent support for pagination and ordering of results via decorate(Query).
        Parameters:
        query - the JDO Query object to execute
        p1 - the value of the first parameter declared.
        p2 - the value of the second parameter declared.
        Returns:
        a PaginatedResult object
        Since:
        1.0.0
      • execute

        public PaginatedResult execute​(javax.jdo.Query query,
                                       Object p1,
                                       Object p2,
                                       Object p3)
        Wrapper around Query.execute(Object, Object, Object) that adds transparent support for pagination and ordering of results via decorate(Query).
        Parameters:
        query - the JDO Query object to execute
        p1 - the value of the first parameter declared.
        p2 - the value of the second parameter declared.
        p3 - the value of the third parameter declared.
        Returns:
        a PaginatedResult object
        Since:
        1.0.0
      • execute

        public PaginatedResult execute​(javax.jdo.Query query,
                                       Object... parameters)
        Wrapper around Query.executeWithArray(Object...) that adds transparent support for pagination and ordering of results via decorate(Query).
        Parameters:
        query - the JDO Query object to execute
        parameters - the Object array with all of the parameters
        Returns:
        a PaginatedResult object
        Since:
        1.0.0
      • execute

        public PaginatedResult execute​(javax.jdo.Query query,
                                       Map parameters)
        Wrapper around Query.executeWithMap(Map) that adds transparent support for pagination and ordering of results via decorate(Query).
        Parameters:
        query - the JDO Query object to execute
        parameters - the Map containing all of the parameters.
        Returns:
        a PaginatedResult object
        Since:
        1.0.0
      • advancePagination

        public void advancePagination()
        Advances the pagination based on the previous pagination settings. This is purely a convenience method as the method by itself is not aware of the query being executed, the result count, etc.
        Since:
        1.0.0
      • decorate

        public javax.jdo.Query decorate​(javax.jdo.Query query)
        Given a query, this method will decorate that query with pagination, ordering, and sorting direction. Specific checks are performed to ensure the execution of the query is capable of being paged and that ordering can be securely performed.
        Parameters:
        query - the JDO Query object to execute
        Returns:
        a Collection of objects
        Since:
        1.0.0
      • getCount

        public long getCount​(javax.jdo.Query query)
        Returns the number of items that would have resulted from returning all object. This method is performant in that the objects are not actually retrieved, only the count.
        Parameters:
        query - the query to return a count from
        Returns:
        the number of items
        Since:
        1.0.0
      • getCount

        public long getCount​(javax.jdo.Query query,
                             Object p1)
        Returns the number of items that would have resulted from returning all object. This method is performant in that the objects are not actually retrieved, only the count.
        Parameters:
        query - the query to return a count from
        p1 - the value of the first parameter declared.
        Returns:
        the number of items
        Since:
        1.0.0
      • getCount

        public long getCount​(javax.jdo.Query query,
                             Object p1,
                             Object p2)
        Returns the number of items that would have resulted from returning all object. This method is performant in that the objects are not actually retrieved, only the count.
        Parameters:
        query - the query to return a count from
        p1 - the value of the first parameter declared.
        p2 - the value of the second parameter declared.
        Returns:
        the number of items
        Since:
        1.0.0
      • getCount

        public long getCount​(javax.jdo.Query query,
                             Object p1,
                             Object p2,
                             Object p3)
        Returns the number of items that would have resulted from returning all object. This method is performant in that the objects are not actually retrieved, only the count.
        Parameters:
        query - the query to return a count from
        p1 - the value of the first parameter declared.
        p2 - the value of the second parameter declared.
        p3 - the value of the third parameter declared.
        Returns:
        the number of items
        Since:
        1.0.0
      • getCount

        public long getCount​(javax.jdo.Query query,
                             Object... parameters)
        Returns the number of items that would have resulted from returning all object. This method is performant in that the objects are not actually retrieved, only the count.
        Parameters:
        query - the query to return a count from
        parameters - the Object array with all of the parameters
        Returns:
        the number of items
        Since:
        1.0.0
      • getCount

        public long getCount​(javax.jdo.Query query,
                             Map parameters)
        Returns the number of items that would have resulted from returning all object. This method is performant in that the objects are not actually retrieved, only the count.
        Parameters:
        query - the query to return a count from
        parameters - the Map containing all of the parameters.
        Returns:
        the number of items
        Since:
        1.0.0
      • getCount

        public <T> long getCount​(Class<T> cls)
        Returns the number of items that would have resulted from returning all object. This method is performant in that the objects are not actually retrieved, only the count.
        Type Parameters:
        T - candidate type for the query
        Parameters:
        cls - the persistence-capable class to query
        Returns:
        the number of items
        Since:
        1.0.0
      • persist

        public <T> T persist​(T object)
        Persists the specified PersistenceCapable object.
        Type Parameters:
        T - the type to return
        Parameters:
        object - a PersistenceCapable object
        Returns:
        the persisted object
      • persist

        public <T> T[] persist​(T... pcs)
        Persists the specified PersistenceCapable objects.
        Type Parameters:
        T - the type to return
        Parameters:
        pcs - an array of PersistenceCapable objects
        Returns:
        the persisted objects
      • persist

        public <T> Collection<T> persist​(Collection pcs)
        Persists the specified PersistenceCapable objects.
        Type Parameters:
        T - the type to return
        Parameters:
        pcs - a collection of PersistenceCapable objects
        Returns:
        the persisted objects
      • delete

        public void delete​(Object... objects)
        Deletes one or more PersistenceCapable objects.
        Parameters:
        objects - an array of one or more objects to delete
        Since:
        1.0.0
      • delete

        public void delete​(Collection collection)
        Deletes one or more PersistenceCapable objects.
        Parameters:
        collection - a collection of one or more objects to delete
        Since:
        1.0.0
      • detach

        public <T> T detach​(Class<T> clazz,
                            Object id)
        Refreshes and detaches an object by its ID.
        Type Parameters:
        T - A type parameter. This type will be returned
        Parameters:
        clazz - the persistence class to retrive the ID for
        id - the object id to retrieve
        Returns:
        an object of the specified type
        Since:
        1.3.0
      • detach

        public <T> List<T> detach​(List<T> pcs)
        Refreshes and detaches an objects.
        Type Parameters:
        T - the type to return
        Parameters:
        pcs - the instances to detach
        Returns:
        the detached instances
        Since:
        1.3.0
      • detach

        public <T> Set<T> detach​(Set<T> pcs)
        Refreshes and detaches an objects.
        Type Parameters:
        T - the type to return
        Parameters:
        pcs - the instances to detach
        Returns:
        the detached instances
        Since:
        1.3.0
      • getObjectById

        public <T> T getObjectById​(Class<T> clazz,
                                   Object id)
        Retrieves an object by its ID.
        Type Parameters:
        T - A type parameter. This type will be returned
        Parameters:
        clazz - the persistence class to retrive the ID for
        id - the object id to retrieve
        Returns:
        an object of the specified type
        Since:
        1.0.0
      • getObjectByUuid

        public <T> T getObjectByUuid​(Class<T> clazz,
                                     UUID uuid)
        Retrieves an object by its UUID.
        Type Parameters:
        T - A type parameter. This type will be returned
        Parameters:
        clazz - the persistence class to retrive the ID for
        uuid - the uuid of the object to retrieve
        Returns:
        an object of the specified type
        Since:
        1.0.0
      • getObjectByUuid

        public <T> T getObjectByUuid​(Class<T> clazz,
                                     String uuid)
        Retrieves an object by its UUID.
        Type Parameters:
        T - A type parameter. This type will be returned
        Parameters:
        clazz - the persistence class to retrive the ID for
        uuid - the uuid of the object to retrieve
        Returns:
        an object of the specified type
        Since:
        1.0.0
      • getObjectByUuid

        public <T> T getObjectByUuid​(Class<T> clazz,
                                     UUID uuid,
                                     String fetchGroup)
        Retrieves an object by its UUID.
        Type Parameters:
        T - A type parameter. This type will be returned
        Parameters:
        clazz - the persistence class to retrive the ID for
        uuid - the uuid of the object to retrieve
        fetchGroup - the JDO fetchgroup to use when making the query
        Returns:
        an object of the specified type
        Since:
        1.0.0
      • getObjectByUuid

        public <T> T getObjectByUuid​(Class<T> clazz,
                                     String uuid,
                                     String fetchGroup)
        Retrieves an object by its UUID.
        Type Parameters:
        T - A type parameter. This type will be returned
        Parameters:
        clazz - the persistence class to retrive the ID for
        uuid - the uuid of the object to retrieve
        fetchGroup - the JDO fetchgroup to use when making the query
        Returns:
        an object of the specified type
        Since:
        1.0.0
      • singleResult

        public <T> T singleResult​(Object object)
        Used to return the first record in a collection. This method is intended to be used to wrap Query.execute() and its derivatives.
        Type Parameters:
        T - the type of object returned, or null if object was null, not a collection, or collection was empty
        Parameters:
        object - a collection object (or anything that extends collection)
        Returns:
        A single results
        Since:
        1.4.4
      • close

        public void close()
        Closes the PersistenceManager instance.
        Specified by:
        close in interface AutoCloseable
        Since:
        1.0.0
      • getPersistenceManager

        public javax.jdo.PersistenceManager getPersistenceManager()