Package alpine.persistence
Class AbstractAlpineQueryManager
java.lang.Object
alpine.persistence.AbstractAlpineQueryManager
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
AlpineQueryManager
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
FieldsModifier and TypeFieldDescriptionprotected final Stringprotected final Stringprotected final OrderDirectionprotected Paginationprotected final javax.jdo.PersistenceManagerprotected final Principal -
Constructor Summary
ConstructorsConstructorDescriptionDefault 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.AbstractAlpineQueryManager(javax.jdo.PersistenceManager pm, AlpineRequest request) Constructs a new QueryManager. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdvances 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.voidDeletes one or more PersistenceCapable objects.voiddelete(Collection collection) Deletes one or more PersistenceCapable objects.<T> TRefreshes and detaches an object by its ID.<T> List<T>Refreshes and detaches an objects.<T> Set<T>Refreshes and detaches an objects.execute(javax.jdo.Query query) Wrapper aroundQuery.execute()that adds transparent support for pagination and ordering of results viadecorate(Query).Wrapper aroundQuery.execute(Object)that adds transparent support for pagination and ordering of results viadecorate(Query).Wrapper aroundQuery.executeWithArray(Object...)that adds transparent support for pagination and ordering of results viadecorate(Query).Wrapper aroundQuery.execute(Object, Object)that adds transparent support for pagination and ordering of results viadecorate(Query).Wrapper aroundQuery.execute(Object, Object, Object)that adds transparent support for pagination and ordering of results viadecorate(Query).Wrapper aroundQuery.executeWithMap(Map)that adds transparent support for pagination and ordering of results viadecorate(Query).<T> longReturns 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.longReturns the number of items that would have resulted from returning all object.longReturns the number of items that would have resulted from returning all object.longReturns the number of items that would have resulted from returning all object.longReturns the number of items that would have resulted from returning all object.longReturns 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.PersistenceManagerstatic Optional<IPersistenceManagerFactory><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 Details
-
principal
-
pagination
-
filter
-
orderBy
-
orderDirection
-
pm
protected final javax.jdo.PersistenceManager pm
-
-
Constructor Details
-
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
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
-
AbstractAlpineQueryManager
Constructs a new QueryManager. Deconstructs the specified AlpineRequest into its individual components including pagination and ordering.- Parameters:
pm- the JDO PersistenceManager to userequest- an AlpineRequest object- Since:
- 1.9.3
-
-
Method Details
-
getPersistenceManagerFactory
-
execute
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
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
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
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
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
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
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
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
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
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
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
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
Persists the specified PersistenceCapable objects.- Type Parameters:
T- the type to return- Parameters:
pcs- a collection of PersistenceCapable objects- Returns:
- the persisted objects
-
delete
Deletes one or more PersistenceCapable objects.- Parameters:
objects- an array of one or more objects to delete- Since:
- 1.0.0
-
delete
Deletes one or more PersistenceCapable objects.- Parameters:
collection- a collection of one or more objects to delete- Since:
- 1.0.0
-
detach
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
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
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
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
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
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
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
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
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()
-