Package alpine.persistence
Class AbstractAlpineQueryManager
- java.lang.Object
-
- alpine.persistence.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 Summary
Fields Modifier and Type Field Description protected Stringfilterprotected StringorderByprotected OrderDirectionorderDirectionprotected Paginationpaginationprotected javax.jdo.PersistenceManagerpmprotected Principalprincipal
-
Constructor Summary
Constructors Constructor Description AbstractAlpineQueryManager()Default constructorAbstractAlpineQueryManager(AlpineRequest request)Constructs a new QueryManager.AbstractAlpineQueryManager(Principal principal, Pagination pagination, String filter, String orderBy, OrderDirection orderDirection)Constructs a new QueryManager with the following:AbstractAlpineQueryManager(javax.jdo.PersistenceManager pm)Specifies a non-default PersistenceManager to use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvancePagination()Advances the pagination based on the previous pagination settings.voidclose()Closes the PersistenceManager instance.javax.jdo.Querydecorate(javax.jdo.Query query)Given a query, this method will decorate that query with pagination, ordering, and sorting direction.voiddelete(Object... objects)Deletes one or more PersistenceCapable objects.voiddelete(Collection collection)Deletes one or more PersistenceCapable objects.<T> Tdetach(Class<T> clazz, Object id)Refreshes and detaches an object by its ID.<T> List<T>detach(List<T> pcs)Refreshes and detaches an objects.<T> Set<T>detach(Set<T> pcs)Refreshes and detaches an objects.PaginatedResultexecute(javax.jdo.Query query)Wrapper aroundQuery.execute()that adds transparent support for pagination and ordering of results viadecorate(Query).PaginatedResultexecute(javax.jdo.Query query, Object p1)Wrapper aroundQuery.execute(Object)that adds transparent support for pagination and ordering of results viadecorate(Query).PaginatedResultexecute(javax.jdo.Query query, Object... parameters)Wrapper aroundQuery.executeWithArray(Object...)that adds transparent support for pagination and ordering of results viadecorate(Query).PaginatedResultexecute(javax.jdo.Query query, Object p1, Object p2)Wrapper aroundQuery.execute(Object, Object)that adds transparent support for pagination and ordering of results viadecorate(Query).PaginatedResultexecute(javax.jdo.Query query, Object p1, Object p2, Object p3)Wrapper aroundQuery.execute(Object, Object, Object)that adds transparent support for pagination and ordering of results viadecorate(Query).PaginatedResultexecute(javax.jdo.Query query, Map parameters)Wrapper aroundQuery.executeWithMap(Map)that adds transparent support for pagination and ordering of results viadecorate(Query).<T> longgetCount(Class<T> cls)Returns the number of items that would have resulted from returning all object.longgetCount(javax.jdo.Query query)Returns the number of items that would have resulted from returning all object.longgetCount(javax.jdo.Query query, Object p1)Returns the number of items that would have resulted from returning all object.longgetCount(javax.jdo.Query query, Object... parameters)Returns the number of items that would have resulted from returning all object.longgetCount(javax.jdo.Query query, Object p1, Object p2)Returns the number of items that would have resulted from returning all object.longgetCount(javax.jdo.Query query, Object p1, Object p2, Object p3)Returns the number of items that would have resulted from returning all object.longgetCount(javax.jdo.Query query, Map parameters)Returns the number of items that would have resulted from returning all object.<T> TgetObjectById(Class<T> clazz, Object id)Retrieves an object by its ID.<T> TgetObjectByUuid(Class<T> clazz, String uuid)Retrieves an object by its UUID.<T> TgetObjectByUuid(Class<T> clazz, String uuid, String fetchGroup)Retrieves an object by its UUID.<T> TgetObjectByUuid(Class<T> clazz, UUID uuid)Retrieves an object by its UUID.<T> TgetObjectByUuid(Class<T> clazz, UUID uuid, String fetchGroup)Retrieves an object by its UUID.javax.jdo.PersistenceManagergetPersistenceManager()<T> Collection<T>persist(Collection pcs)Persists the specified PersistenceCapable objects.<T> Tpersist(T object)Persists the specified PersistenceCapable object.<T> T[]persist(T... pcs)Persists the specified PersistenceCapable objects.<T> TsingleResult(Object object)Used to return the first record in a collection.
-
-
-
Field Detail
-
principal
protected final Principal principal
-
pagination
protected Pagination pagination
-
filter
protected final String filter
-
orderBy
protected final String orderBy
-
orderDirection
protected final OrderDirection orderDirection
-
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 nullpagination- a Pagination request, or nullfilter- a String filter, or nullorderBy- the field to order byorderDirection- 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 aroundQuery.execute()that adds transparent support for pagination and ordering of results viadecorate(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 aroundQuery.execute(Object)that adds transparent support for pagination and ordering of results viadecorate(Query).- Parameters:
query- the JDO Query object to executep1- 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 aroundQuery.execute(Object, Object)that adds transparent support for pagination and ordering of results viadecorate(Query).- Parameters:
query- the JDO Query object to executep1- 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 aroundQuery.execute(Object, Object, Object)that adds transparent support for pagination and ordering of results viadecorate(Query).- Parameters:
query- the JDO Query object to executep1- 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 aroundQuery.executeWithArray(Object...)that adds transparent support for pagination and ordering of results viadecorate(Query).- Parameters:
query- the JDO Query object to executeparameters- theObjectarray with all of the parameters- Returns:
- a PaginatedResult object
- Since:
- 1.0.0
-
execute
public PaginatedResult execute(javax.jdo.Query query, Map parameters)
Wrapper aroundQuery.executeWithMap(Map)that adds transparent support for pagination and ordering of results viadecorate(Query).- Parameters:
query- the JDO Query object to executeparameters- theMapcontaining 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 fromp1- 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 fromp1- 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 fromp1- 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 fromparameters- theObjectarray 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 fromparameters- theMapcontaining 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 forid- 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 forid- 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 foruuid- 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 foruuid- 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 foruuid- the uuid of the object to retrievefetchGroup- 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 foruuid- the uuid of the object to retrievefetchGroup- 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 wrapQuery.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:
closein interfaceAutoCloseable- Since:
- 1.0.0
-
getPersistenceManager
public javax.jdo.PersistenceManager getPersistenceManager()
-
-