Package ome.services.query
Class Query<T>
- java.lang.Object
-
- ome.services.query.Query<T>
-
- All Implemented Interfaces:
org.springframework.orm.hibernate3.HibernateCallback
- Direct Known Subclasses:
AbstractClassIdsOptionsQuery
,CollectionCountQueryDefinition
,IObjectClassQuery
,PojosFindAnnotationsQueryDefinition
,PojosGetImagesByOptionsQueryDefinition
,PojosGetUserImagesQueryDefinition
,PojosLoadHierarchyQueryDefinition
,StringQuery
public abstract class Query<T> extends java.lang.Object implements org.springframework.orm.hibernate3.HibernateCallback
base Query type to facilitate the creation of ORM queries. This class attempts to enforce a strict usage pattern. First, subclasses must define aDefinitions
instance, which can optionally (and perhaps preferably) be static, which must be passed into the super constructor along with theParameters
provided during lookup.Queries can optionally define a
enableFilters(Session)
method (perhaps using pre-defined filters likeownerOrGroupFilters(Session, String[], String[])
to limit the entities returned.- Since:
- OMERO 3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected Definitions
defs
container ofQueryParameterDef
instances.protected static org.hibernate.FetchMode
FETCH
imported constant for ease of useprotected static int
INNER_JOIN
imported constant for ease of useprotected static int
LEFT_JOIN
imported constant for ease of useprotected java.util.Set<java.lang.String>
newlyEnabledFilters
the set of filters that is being or has been enabled for this Query.protected ome.parameters.Parameters
params
container ofQueryParameter
instances.
-
Constructor Summary
Constructors Constructor Description Query(Definitions definitions, ome.parameters.Parameters parameters)
main constructor used by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
buildQuery(org.hibernate.Session session)
main point of entry for subclasses.boolean
check(java.lang.String name)
protected void
checkParameters()
check theParameters
instance against theDefinitions
instance for this Query.protected void
disableFilters(org.hibernate.Session session)
turns the filters off that are listed innewlyEnabledFilters
Query<T>
disableQueryCache()
Disable the Hibernate level 2 cache for this query.java.lang.Object
doInHibernate(org.hibernate.Session session)
template method defined byHibernateTemplate
.protected void
enableFilters(org.hibernate.Session session)
does nothing by default, but can be overridden by subclasses to enable particular filters.Query<T>
enableQueryCache()
Enable the Hibernate level 2 cache for this query.ome.parameters.QueryParameter
get(java.lang.String name)
get theQueryParameter
for this name argument.protected void
ownerOrGroupFilters(org.hibernate.Session session, java.lang.String[] ownerFilters, java.lang.String[] groupFilters)
standard filter used by many subclasses which uses theParameters.isExperimenter()
andParameters.isGroup()
booleans to see if a filter should be turned on.protected void
setCriteria(org.hibernate.Criteria criteria)
provide this Query instance with aCriteria
to be used for retrieving data.protected void
setQuery(org.hibernate.Query query)
provide this Query instance with aQuery
to be used for retrieving data.void
setTimeout(int seconds)
java.lang.Object
value(java.lang.String name)
get the Object value for this name argument.
-
-
-
Field Detail
-
FETCH
protected static final org.hibernate.FetchMode FETCH
imported constant for ease of use- See Also:
FetchMode.JOIN
-
LEFT_JOIN
protected static final int LEFT_JOIN
imported constant for ease of use- See Also:
CriteriaSpecification.LEFT_JOIN
, Constant Field Values
-
INNER_JOIN
protected static final int INNER_JOIN
imported constant for ease of use- See Also:
CriteriaSpecification.INNER_JOIN
, Constant Field Values
-
defs
protected final Definitions defs
container ofQueryParameterDef
instances. Typically created statically in Query subclasses and passed to theQuery(Definitions, Parameters)
constructor
-
params
protected final ome.parameters.Parameters params
container ofQueryParameter
instances. These must at least cover all theQueryParameterDef
s defined for thisQuery
but can define more. Other special fields ofParameters
, such as aFilter
instance can also be used byQuery
instances.
-
newlyEnabledFilters
protected java.util.Set<java.lang.String> newlyEnabledFilters
the set of filters that is being or has been enabled for this Query.
-
-
Constructor Detail
-
Query
public Query(Definitions definitions, ome.parameters.Parameters parameters)
main constructor used by subclasses. Both arguments must be provided.- Parameters:
definitions
- Not null.parameters
- Not null.
-
-
Method Detail
-
checkParameters
protected void checkParameters()
check theParameters
instance against theDefinitions
instance for this Query. Can be extended by subclasses, butsuper.checkParameters()
should most likely be called.
-
check
public boolean check(java.lang.String name)
-
get
public ome.parameters.QueryParameter get(java.lang.String name)
get theQueryParameter
for this name argument.
-
value
public java.lang.Object value(java.lang.String name)
get the Object value for this name argument. Returns null even if no QueryParameter is associated with the name (no exception).
-
doInHibernate
public java.lang.Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException, java.sql.SQLException
template method defined byHibernateTemplate
. This does not need to be overridden by subclasses, but ratherbuildQuery(Session)
. This ensures that the filters are set properly, thatbuildQuery(Session)
does its job, and that everything is cleaned up properly afterwards. It also enforces contracts established byParameters
andFilter
- Specified by:
doInHibernate
in interfaceorg.springframework.orm.hibernate3.HibernateCallback<T>
- Throws:
org.hibernate.HibernateException
java.sql.SQLException
-
buildQuery
protected abstract void buildQuery(org.hibernate.Session session) throws org.hibernate.HibernateException, java.sql.SQLException
main point of entry for subclasses. This method must build either aCriteria
or aQuery
instance and make it available viasetCriteria(org.hibernate.Criteria)
orsetQuery(org.hibernate.Query)
- Throws:
org.hibernate.HibernateException
java.sql.SQLException
-
setQuery
protected void setQuery(org.hibernate.Query query)
provide this Query instance with aQuery
to be used for retrieving data.setCriteria(org.hibernate.Criteria)
should not also be called with a non-null value.
-
setCriteria
protected void setCriteria(org.hibernate.Criteria criteria)
provide this Query instance with aCriteria
to be used for retrieving data.setQuery(org.hibernate.Query)
should not also be called with a non-null value.
-
setTimeout
public void setTimeout(int seconds)
- Parameters:
seconds
- the timeout to set
-
enableFilters
protected void enableFilters(org.hibernate.Session session)
does nothing by default, but can be overridden by subclasses to enable particular filters.
-
ownerOrGroupFilters
protected void ownerOrGroupFilters(org.hibernate.Session session, java.lang.String[] ownerFilters, java.lang.String[] groupFilters)
standard filter used by many subclasses which uses theParameters.isExperimenter()
andParameters.isGroup()
booleans to see if a filter should be turned on. If both booleans are active, group wins. The constantParameters.OWNER_ID
orParameters.GROUP_ID
is then used to define a filter.
-
disableFilters
protected void disableFilters(org.hibernate.Session session)
turns the filters off that are listed innewlyEnabledFilters
-
enableQueryCache
public Query<T> enableQueryCache()
Enable the Hibernate level 2 cache for this query.- Returns:
- this instance, for method chaining
-
-