ome.logic
Class QueryImpl

java.lang.Object
  extended by ome.logic.AbstractLevel1Service
      extended by ome.logic.QueryImpl
All Implemented Interfaces:
IQuery, LocalQuery, ServiceInterface, SelfConfigurableService

@Transactional(readOnly=true)
public class QueryImpl
extends AbstractLevel1Service
implements LocalQuery

Provides methods for directly querying object graphs.

Since:
3.0
Version:
3.0 (Internal version: $Rev: 7319 $ $Date: 2010-06-24 12:02:54 +0100 (Thu, 24 Jun 2010) $)
Author:
Josh Moore      josh.moore@gmx.de

Field Summary
protected  Class<? extends Analyzer> analyzer
           
 
Fields inherited from class ome.logic.AbstractLevel1Service
queryFactory, sessionFactory
 
Constructor Summary
QueryImpl()
           
 
Method Summary
 Long aggByQuery(String agg, String field, String query, ome.parameters.Parameters params)
           
 Map<String,Long> aggMapByQuery(String agg, String mapKey, String field, String query, ome.parameters.Parameters params)
           
 boolean checkProperty(String type, String property)
          Checks if a property is defined on a mapped Hibernate type.
 boolean checkType(String type)
          Checks if a type has been mapped in Hibernate.
 void clear()
           
 boolean contains(Object obj)
          Tests if an object is currently contained in the session.
 void evict(Object obj)
          Removes an object graph from the session.
<T> T
execute(org.springframework.orm.hibernate3.HibernateCallback callback)
          Executes a HibernateCallback
<T> T
execute(Query<T> query)
          Executes a locally defined Query.
 ome.model.IObject find(Class klass, long id)
          lookup an entity by class and id.
<T extends ome.model.IObject>
List<T>
findAll(Class<T> klass, ome.parameters.Filter filter)
          lookup all entities that belong to this class and match filter.
<T extends ome.model.IObject>
List<T>
findAllByExample(T example, ome.parameters.Filter filter)
          search based on provided example entity.
<T extends ome.model.IObject>
List<T>
findAllByFullText(Class<T> type, String query, ome.parameters.Parameters params)
          executes a full text search based on Lucene.
<T extends ome.model.IObject>
List<T>
findAllByQuery(String queryName, ome.parameters.Parameters params)
          executes the stored query with the given name.
<T extends ome.model.IObject>
List<T>
findAllByString(Class<T> klass, String fieldName, String value, boolean caseSensitive, ome.parameters.Filter filter)
          search a given field matching against a String.
<T extends ome.model.IObject>
T
findByExample(T example)
          search based on provided example entity.
<T extends ome.model.IObject>
T
findByQuery(String queryName, ome.parameters.Parameters params)
          executes the stored query with the given name.
<T extends ome.model.IObject>
T
findByString(Class<T> klass, String fieldName, String value)
          search a given field matching against a String.
 ome.model.IObject get(Class klass, long id)
          lookup an entity by class and id.
 Class<? extends ServiceInterface> getServiceInterface()
           
 void initialize(Object obj)
          Uses the Hibernate static method initialize to prepare an object for shipping over the wire.
protected  void parseFilter(org.hibernate.Criteria c, ome.parameters.Filter f)
          responsible for applying the information provided in a Filter to a org.hibernate.Critieria instance.
 List<Object[]> projection(String query, ome.parameters.Parameters p)
          Return a list of Java Object instances (not IObject instances).
<T extends ome.model.IObject>
T
refresh(T iObject)
          refreshes an entire IObject graph, recursive loading all data for the managed instances in the graph from the database.
 void setAnalyzer(Class<? extends Analyzer> analyzer)
           
 
Methods inherited from class ome.logic.AbstractLevel1Service
getBeanHelper, getQueryFactory, getSessionFactory, selfConfigure, setQueryFactory, setSessionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

analyzer

protected Class<? extends Analyzer> analyzer
Constructor Detail

QueryImpl

public QueryImpl()
Method Detail

setAnalyzer

public void setAnalyzer(Class<? extends Analyzer> analyzer)

getServiceInterface

public Class<? extends ServiceInterface> getServiceInterface()
Specified by:
getServiceInterface in interface SelfConfigurableService

contains

@Transactional(readOnly=false)
public boolean contains(Object obj)
Description copied from interface: LocalQuery
Tests if an object is currently contained in the session.

Specified by:
contains in interface LocalQuery

evict

@Transactional(readOnly=false)
public void evict(Object obj)
Description copied from interface: LocalQuery
Removes an object graph from the session. This allows for non-permanent, mutable calls on the graph.

Specified by:
evict in interface LocalQuery

clear

@Transactional(readOnly=false)
public void clear()
Specified by:
clear in interface LocalQuery

initialize

public void initialize(Object obj)
Description copied from interface: LocalQuery
Uses the Hibernate static method initialize to prepare an object for shipping over the wire. It is better to do this in your queries.

Specified by:
initialize in interface LocalQuery
See Also:
Hibernate

checkType

@Transactional(propagation=SUPPORTS)
public boolean checkType(String type)
Description copied from interface: LocalQuery
Checks if a type has been mapped in Hibernate.

Specified by:
checkType in interface LocalQuery
Parameters:
type - String representation of a full-qualified Hibernate-mapped type.
Returns:
yes or no.

checkProperty

@Transactional(propagation=SUPPORTS)
public boolean checkProperty(String type,
                                           String property)
Description copied from interface: LocalQuery
Checks if a property is defined on a mapped Hibernate type.

Specified by:
checkProperty in interface LocalQuery
Parameters:
type - String representation of a full-qualified Hibernate-mapped type.
property - Property as defined in Hibernate NOT the public final static Strings on our IObject classes.
Returns:
yes or no.

execute

public <T> T execute(org.springframework.orm.hibernate3.HibernateCallback callback)
Description copied from interface: LocalQuery
Executes a HibernateCallback

Specified by:
execute in interface LocalQuery
Parameters:
callback - An implementation of the HibernateCallback interface.
See Also:
LocalQuery.execute(HibernateCallback)

execute

public <T> T execute(Query<T> query)
Description copied from interface: LocalQuery
Executes a locally defined Query.

Specified by:
execute in interface LocalQuery
Parameters:
query - A subclass of the Query interface.
Returns:
result of the query See document for the query for the return type.
See Also:
LocalQuery.execute(Query)

get

public ome.model.IObject get(Class klass,
                             long id)
                      throws ome.conditions.ValidationException
Description copied from interface: IQuery
lookup an entity by class and id. If no such object exists, an exception will be thrown.

Specified by:
get in interface IQuery
Parameters:
klass - the type of the entity. Not null.
id - the entity's id
Returns:
an initialized entity
Throws:
ome.conditions.ValidationException - if the id doesn't exist.
See Also:
IQuery.get(java.lang.Class, long), Session.load(java.lang.Class, java.io.Serializable)
To do:
weirdness here; learn more about CGLIB initialization.

find

public ome.model.IObject find(Class klass,
                              long id)
Description copied from interface: IQuery
lookup an entity by class and id. If no such objects exists, return a null.

Specified by:
find in interface IQuery
Parameters:
klass - klass the type of the entity. Not null.
id - the entity's id
Returns:
an initialized entity or null if id doesn't exist.
See Also:
IQuery.find(java.lang.Class, long), Session.get(java.lang.Class, java.io.Serializable)
To do:
weirdness here; learn more about CGLIB initialization.

findAll

public <T extends ome.model.IObject> List<T> findAll(Class<T> klass,
                                                     ome.parameters.Filter filter)
Description copied from interface: IQuery
lookup all entities that belong to this class and match filter.

Specified by:
findAll in interface IQuery
Parameters:
klass - entity type to be searched. Not null.
filter - filters the result set. Can be null.
Returns:
a collection if initialized entities or an empty List if none exist.
See Also:
ome.api.IQuery#getByClass(java.lang.Class)

findByExample

public <T extends ome.model.IObject> T findByExample(T example)
                                          throws ome.conditions.ApiUsageException
Description copied from interface: IQuery
search based on provided example entity. The example entity should uniquely specify the entity or an exception will be thrown. Note: findByExample does not operate on the id field. For that, use IQuery.find(Class, long), IQuery.get(Class, long), IQuery.findByQuery(String, Parameters), or IQuery.findAllByQuery(String, Parameters)

Specified by:
findByExample in interface IQuery
Parameters:
example - Non-null example object.
Returns:
Possibly null IObject result.
Throws:
ome.conditions.ApiUsageException - if more than one result is return.
See Also:
IQuery.findByExample(ome.model.IObject)

findAllByExample

public <T extends ome.model.IObject> List<T> findAllByExample(T example,
                                                              ome.parameters.Filter filter)
Description copied from interface: IQuery
search based on provided example entity. The returned entities will be limited by the Filter object. Note: findAllbyExample does not operate on the id field. For that, use IQuery.find(Class, long), IQuery.get(Class, long), IQuery.findByQuery(String, Parameters), or IQuery.findAllByQuery(String, Parameters)

Specified by:
findAllByExample in interface IQuery
Parameters:
example - Non-null example object.
filter - filters the result set. Can be null.
Returns:
Possibly empty List of IObject results.
See Also:
IQuery.findAllByExample(ome.model.IObject, ome.parameters.Filter)

findByString

public <T extends ome.model.IObject> T findByString(Class<T> klass,
                                                    String fieldName,
                                                    String value)
                                         throws ome.conditions.ApiUsageException
Description copied from interface: IQuery
search a given field matching against a String. Method does not allow for case sensitive or insensitive searching since this is essentially a lookup. The existence of more than one result will result in an exception.

Specified by:
findByString in interface IQuery
Parameters:
klass - type of entity to be searched
fieldName - the name of the field, either as simple string or as public final static from the entity class, e.g. Project.NAME
value - String used for search.
Returns:
found entity or possibly null.
Throws:
ome.conditions.ApiUsageException - if more than one result.
See Also:
IQuery.findByString(java.lang.Class, java.lang.String, java.lang.String)

findAllByString

public <T extends ome.model.IObject> List<T> findAllByString(Class<T> klass,
                                                             String fieldName,
                                                             String value,
                                                             boolean caseSensitive,
                                                             ome.parameters.Filter filter)
                                                  throws ome.conditions.ApiUsageException
Description copied from interface: IQuery
search a given field matching against a String. Method allows for case sensitive or insensitive searching using the (I)LIKE comparators. Result set will be reduced by the Filter instance.

Specified by:
findAllByString in interface IQuery
Parameters:
klass - type of entity to be searched. Not null.
fieldName - the name of the field, either as simple string or as public final static from the entity class, e.g. Project.NAME. Not null.
caseSensitive - whether to use LIKE or ILIKE
filter - filters the result set. Can be null.
Returns:
A list (possibly empty) with the results.
Throws:
ome.conditions.ApiUsageException
See Also:
IQuery.findAllByString(java.lang.Class, java.lang.String, java.lang.String, boolean, ome.parameters.Filter)

findByQuery

public <T extends ome.model.IObject> T findByQuery(String queryName,
                                                   ome.parameters.Parameters params)
                                        throws ome.conditions.ValidationException
Description copied from interface: IQuery
executes the stored query with the given name. If a query with the name cannot be found, an exception will be thrown. The queryName parameter can be an actualy query String if the StringQuerySource is configured on the server and the user running the query has proper permissions.

Specified by:
findByQuery in interface IQuery
Parameters:
queryName - String identifier of the query to execute
params - array of QueryParameter. Not null. The QueryParameter.name field maps to a field-name which is then matched against the QueryParameter.value
Returns:
Possibly null IObject result.
Throws:
ome.conditions.ValidationException
See Also:
IQuery.findByQuery(java.lang.String, ome.parameters.Parameters)

findAllByQuery

public <T extends ome.model.IObject> List<T> findAllByQuery(String queryName,
                                                            ome.parameters.Parameters params)
Description copied from interface: IQuery
executes the stored query with the given name. If a query with the name cannot be found, an exception will be thrown. The queryName parameter can be an actual query String if the StringQuerySource is configured on the server and the user running the query has proper permissions. Queries can only return lists of IObject instances. This means all must be of the form:
 select this from SomeModelClass this ...
 
though the alias "this" is unimportant. Do not try to return multiple classes in one call like:
 select this, that from SomeClass this, SomeOtherClass that ...
 
nor to project values out of an object:
 select this.name from SomeClass this ...
 
If a Page is desired, add it to the query parameters.

Specified by:
findAllByQuery in interface IQuery
Parameters:
queryName - String identifier of the query to execute. Not null.
params - array of QueryParameter. The QueryParameter.name field maps to a field-name which is then matched against the QueryParameter.value
Returns:
Possibly empty List of IObject results.
See Also:
IQuery.findAllByQuery(java.lang.String, ome.parameters.Parameters)

findAllByFullText

public <T extends ome.model.IObject> List<T> findAllByFullText(Class<T> type,
                                                               String query,
                                                               ome.parameters.Parameters params)
Description copied from interface: IQuery
executes a full text search based on Lucene. Each term in the query can also be prefixed by the name of the field to which is should be restricted. Examples: For more information, see Query Parser Synax The return values are first filtered by the security system.

Specified by:
findAllByFullText in interface IQuery
Parameters:
type - A non-null class specification of which type should be searched.
query - A non-null query string. An empty string will return no results.
params - Currently the parameters themselves are unusued. But the Parameters#getFilter() can be used to limit the number of results returned (Filter#maxResults()) or the user for who the results will be found (Filter.owner()).
Returns:
A list of loaded IObject instances. Never null.
See Also:
ome.api.IQuery#findAllByFullText(java.lang.String, ome.parameters.Parameteres)

projection

public List<Object[]> projection(String query,
                                 ome.parameters.Parameters p)
Description copied from interface: IQuery
Return a list of Java Object instances (not IObject instances). These are the column names as specified in the HQL select statement (more than one is required). If an aggregation statement is used, a group by clause must be added. Examples:

Specified by:
projection in interface IQuery

aggByQuery

public Long aggByQuery(String agg,
                       String field,
                       String query,
                       ome.parameters.Parameters params)

aggMapByQuery

public Map<String,Long> aggMapByQuery(String agg,
                                      String mapKey,
                                      String field,
                                      String query,
                                      ome.parameters.Parameters params)

refresh

public <T extends ome.model.IObject> T refresh(T iObject)
                                    throws ome.conditions.ApiUsageException
Description copied from interface: IQuery
refreshes an entire IObject graph, recursive loading all data for the managed instances in the graph from the database. If any non-managed entities are detected (e.g. without ids), an ApiUsageException will be thrown.

Specified by:
refresh in interface IQuery
Parameters:
iObject - Non-null managed IObject graph which should have all values re-assigned from the database
Returns:
a similar IObject graph (with possible additions and deletions) which is in-sync with the database.
Throws:
ome.conditions.ApiUsageException - if any non-managed entities are found.
See Also:
IQuery.refresh(IObject)

parseFilter

protected void parseFilter(org.hibernate.Criteria c,
                           ome.parameters.Filter f)
responsible for applying the information provided in a Filter to a org.hibernate.Critieria instance.



OmeroJava Api

Version: Beta-4.2.0-r7571-b29

Copyright © 2009 The University of Dundee. All Rights Reserved.