org.hibernate.shards.query
Class ShardedQueryImpl

java.lang.Object
  extended by org.hibernate.shards.query.ShardedQueryImpl
All Implemented Interfaces:
org.hibernate.Query, ShardedQuery

public class ShardedQueryImpl
extends Object
implements ShardedQuery

Concrete implementation of ShardedQuery provided by Hibernate Shards. This implementation introduces limits to the HQL language; mostly around limits and aggregation. Its approach is simply to execute the query on each shard and compile the results in a list, or if a unique result is desired, the fist non-null result is returned. The setFoo methods are implemented using a set of classes that implement the QueryEvent interface and are called SetFooEvent. These query events are used to call setFoo with the appropriate arguments on each Query that is executed on a shard.

Author:
Maulik Shah
See Also:
{@inheritDoc}

Constructor Summary
ShardedQueryImpl(QueryId queryId, List<Shard> shards, QueryFactory queryFactory, ShardAccessStrategy shardAccessStrategy)
          Constructor for ShardedQueryImpl
 
Method Summary
 int executeUpdate()
          ExecuteUpdate is not supported and throws an UnsupportedOperationException.
 String[] getNamedParameters()
           
 QueryFactory getQueryFactory()
           
 QueryId getQueryId()
           
 String getQueryString()
           
 String[] getReturnAliases()
           
 org.hibernate.type.Type[] getReturnTypes()
           
 Iterator iterate()
          This method currently wraps list().
 List list()
          The implementation executes the query on each shard and concatenates the results.
 org.hibernate.ScrollableResults scroll()
          Scrolling is unsupported.
 org.hibernate.ScrollableResults scroll(org.hibernate.ScrollMode scrollMode)
          Scrolling is unsupported.
 org.hibernate.Query setBigDecimal(int position, BigDecimal number)
           
 org.hibernate.Query setBigDecimal(String name, BigDecimal number)
           
 org.hibernate.Query setBigInteger(int position, BigInteger number)
           
 org.hibernate.Query setBigInteger(String name, BigInteger number)
           
 org.hibernate.Query setBinary(int position, byte[] val)
           
 org.hibernate.Query setBinary(String name, byte[] val)
           
 org.hibernate.Query setBoolean(int position, boolean val)
           
 org.hibernate.Query setBoolean(String name, boolean val)
           
 org.hibernate.Query setByte(int position, byte val)
           
 org.hibernate.Query setByte(String name, byte val)
           
 org.hibernate.Query setCacheable(boolean cacheable)
           
 org.hibernate.Query setCacheMode(org.hibernate.CacheMode cacheMode)
           
 org.hibernate.Query setCacheRegion(String cacheRegion)
           
 org.hibernate.Query setCalendar(int position, Calendar calendar)
           
 org.hibernate.Query setCalendar(String name, Calendar calendar)
           
 org.hibernate.Query setCalendarDate(int position, Calendar calendar)
           
 org.hibernate.Query setCalendarDate(String name, Calendar calendar)
           
 org.hibernate.Query setCharacter(int position, char val)
           
 org.hibernate.Query setCharacter(String name, char val)
           
 org.hibernate.Query setComment(String comment)
           
 org.hibernate.Query setDate(int position, Date date)
           
 org.hibernate.Query setDate(String name, Date date)
           
 org.hibernate.Query setDouble(int position, double val)
           
 org.hibernate.Query setDouble(String name, double val)
           
 org.hibernate.Query setEntity(int position, Object val)
           
 org.hibernate.Query setEntity(String name, Object val)
           
 org.hibernate.Query setFetchSize(int fetchSize)
           
 org.hibernate.Query setFirstResult(int firstResult)
           
 org.hibernate.Query setFloat(int position, float val)
           
 org.hibernate.Query setFloat(String name, float val)
           
 org.hibernate.Query setFlushMode(org.hibernate.FlushMode flushMode)
           
 org.hibernate.Query setInteger(int position, int val)
           
 org.hibernate.Query setInteger(String name, int val)
           
 org.hibernate.Query setLocale(int position, Locale locale)
           
 org.hibernate.Query setLocale(String name, Locale locale)
           
 org.hibernate.Query setLockMode(String alias, org.hibernate.LockMode lockMode)
           
 org.hibernate.Query setLong(int position, long val)
           
 org.hibernate.Query setLong(String name, long val)
           
 org.hibernate.Query setMaxResults(int maxResults)
           
 org.hibernate.Query setParameter(int position, Object val)
           
 org.hibernate.Query setParameter(int position, Object val, org.hibernate.type.Type type)
           
 org.hibernate.Query setParameter(String name, Object val)
           
 org.hibernate.Query setParameter(String name, Object val, org.hibernate.type.Type type)
           
 org.hibernate.Query setParameterList(String name, Collection vals)
           
 org.hibernate.Query setParameterList(String name, Collection vals, org.hibernate.type.Type type)
           
 org.hibernate.Query setParameterList(String name, Object[] vals)
           
 org.hibernate.Query setParameterList(String name, Object[] vals, org.hibernate.type.Type type)
           
 org.hibernate.Query setParameters(Object[] values, org.hibernate.type.Type[] types)
           
 org.hibernate.Query setProperties(Map map)
           
 org.hibernate.Query setProperties(Object bean)
           
 org.hibernate.Query setReadOnly(boolean readOnly)
           
 org.hibernate.Query setResultTransformer(org.hibernate.transform.ResultTransformer transformer)
           
 org.hibernate.Query setSerializable(int position, Serializable val)
           
 org.hibernate.Query setSerializable(String name, Serializable val)
           
 org.hibernate.Query setShort(int position, short val)
           
 org.hibernate.Query setShort(String name, short val)
           
 org.hibernate.Query setString(int position, String val)
           
 org.hibernate.Query setString(String name, String val)
           
 org.hibernate.Query setText(int position, String val)
           
 org.hibernate.Query setText(String name, String val)
           
 org.hibernate.Query setTime(int position, Date date)
           
 org.hibernate.Query setTime(String name, Date date)
           
 org.hibernate.Query setTimeout(int timeout)
           
 org.hibernate.Query setTimestamp(int position, Date date)
           
 org.hibernate.Query setTimestamp(String name, Date date)
           
 Object uniqueResult()
          The implementation executes the query on each shard and returns the first non-null result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShardedQueryImpl

public ShardedQueryImpl(QueryId queryId,
                        List<Shard> shards,
                        QueryFactory queryFactory,
                        ShardAccessStrategy shardAccessStrategy)
Constructor for ShardedQueryImpl

Parameters:
queryId - the id of the query
shards - list of shards on which this query will be executed
queryFactory - factory that knows how to create the actual query we'll execute
shardAccessStrategy - the shard strategy for this query
Method Detail

getQueryId

public QueryId getQueryId()
Specified by:
getQueryId in interface ShardedQuery

getQueryFactory

public QueryFactory getQueryFactory()
Specified by:
getQueryFactory in interface ShardedQuery

getQueryString

public String getQueryString()
Specified by:
getQueryString in interface org.hibernate.Query

getReturnTypes

public org.hibernate.type.Type[] getReturnTypes()
                                         throws org.hibernate.HibernateException
Specified by:
getReturnTypes in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

getReturnAliases

public String[] getReturnAliases()
                          throws org.hibernate.HibernateException
Specified by:
getReturnAliases in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

getNamedParameters

public String[] getNamedParameters()
                            throws org.hibernate.HibernateException
Specified by:
getNamedParameters in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

iterate

public Iterator iterate()
                 throws org.hibernate.HibernateException
This method currently wraps list().

Specified by:
iterate in interface org.hibernate.Query
Returns:
an iterator over the results of the query
Throws:
org.hibernate.HibernateException

scroll

public org.hibernate.ScrollableResults scroll()
                                       throws org.hibernate.HibernateException
Scrolling is unsupported. Current implementation throws an UnsupportedOperationException. A dumb implementation of scroll might be possible; however it would provide no performance benefit. An intelligent implementation would require re-querying shards frequently and a deterministic way to complie results.

Specified by:
scroll in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

scroll

public org.hibernate.ScrollableResults scroll(org.hibernate.ScrollMode scrollMode)
                                       throws org.hibernate.HibernateException
Scrolling is unsupported. Current implementation throws an UnsupportedOperationException. A dumb implementation of scroll might be possible; however it would provide no performance benefit. An intelligent implementation would require re-querying shards frequently and a deterministic way to complie results.

Specified by:
scroll in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

list

public List list()
          throws org.hibernate.HibernateException
The implementation executes the query on each shard and concatenates the results.

Specified by:
list in interface org.hibernate.Query
Returns:
a list containing the concatenated results of executing the query on all shards
Throws:
org.hibernate.HibernateException

uniqueResult

public Object uniqueResult()
                    throws org.hibernate.HibernateException
The implementation executes the query on each shard and returns the first non-null result.

Specified by:
uniqueResult in interface org.hibernate.Query
Returns:
the first non-null result, or null if no non-null result found
Throws:
org.hibernate.HibernateException

executeUpdate

public int executeUpdate()
                  throws org.hibernate.HibernateException
ExecuteUpdate is not supported and throws an UnsupportedOperationException.

Specified by:
executeUpdate in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setMaxResults

public org.hibernate.Query setMaxResults(int maxResults)
Specified by:
setMaxResults in interface org.hibernate.Query

setFirstResult

public org.hibernate.Query setFirstResult(int firstResult)
Specified by:
setFirstResult in interface org.hibernate.Query

setReadOnly

public org.hibernate.Query setReadOnly(boolean readOnly)
Specified by:
setReadOnly in interface org.hibernate.Query

setCacheable

public org.hibernate.Query setCacheable(boolean cacheable)
Specified by:
setCacheable in interface org.hibernate.Query

setCacheRegion

public org.hibernate.Query setCacheRegion(String cacheRegion)
Specified by:
setCacheRegion in interface org.hibernate.Query

setTimeout

public org.hibernate.Query setTimeout(int timeout)
Specified by:
setTimeout in interface org.hibernate.Query

setFetchSize

public org.hibernate.Query setFetchSize(int fetchSize)
Specified by:
setFetchSize in interface org.hibernate.Query

setLockMode

public org.hibernate.Query setLockMode(String alias,
                                       org.hibernate.LockMode lockMode)
Specified by:
setLockMode in interface org.hibernate.Query

setComment

public org.hibernate.Query setComment(String comment)
Specified by:
setComment in interface org.hibernate.Query

setFlushMode

public org.hibernate.Query setFlushMode(org.hibernate.FlushMode flushMode)
Specified by:
setFlushMode in interface org.hibernate.Query

setCacheMode

public org.hibernate.Query setCacheMode(org.hibernate.CacheMode cacheMode)
Specified by:
setCacheMode in interface org.hibernate.Query

setParameter

public org.hibernate.Query setParameter(int position,
                                        Object val,
                                        org.hibernate.type.Type type)
Specified by:
setParameter in interface org.hibernate.Query

setParameter

public org.hibernate.Query setParameter(String name,
                                        Object val,
                                        org.hibernate.type.Type type)
Specified by:
setParameter in interface org.hibernate.Query

setParameter

public org.hibernate.Query setParameter(int position,
                                        Object val)
                                 throws org.hibernate.HibernateException
Specified by:
setParameter in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setParameter

public org.hibernate.Query setParameter(String name,
                                        Object val)
                                 throws org.hibernate.HibernateException
Specified by:
setParameter in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setParameters

public org.hibernate.Query setParameters(Object[] values,
                                         org.hibernate.type.Type[] types)
                                  throws org.hibernate.HibernateException
Specified by:
setParameters in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setParameterList

public org.hibernate.Query setParameterList(String name,
                                            Collection vals,
                                            org.hibernate.type.Type type)
                                     throws org.hibernate.HibernateException
Specified by:
setParameterList in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setParameterList

public org.hibernate.Query setParameterList(String name,
                                            Collection vals)
                                     throws org.hibernate.HibernateException
Specified by:
setParameterList in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setParameterList

public org.hibernate.Query setParameterList(String name,
                                            Object[] vals,
                                            org.hibernate.type.Type type)
                                     throws org.hibernate.HibernateException
Specified by:
setParameterList in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setParameterList

public org.hibernate.Query setParameterList(String name,
                                            Object[] vals)
                                     throws org.hibernate.HibernateException
Specified by:
setParameterList in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setProperties

public org.hibernate.Query setProperties(Object bean)
                                  throws org.hibernate.HibernateException
Specified by:
setProperties in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

setString

public org.hibernate.Query setString(int position,
                                     String val)
Specified by:
setString in interface org.hibernate.Query

setCharacter

public org.hibernate.Query setCharacter(int position,
                                        char val)
Specified by:
setCharacter in interface org.hibernate.Query

setBoolean

public org.hibernate.Query setBoolean(int position,
                                      boolean val)
Specified by:
setBoolean in interface org.hibernate.Query

setByte

public org.hibernate.Query setByte(int position,
                                   byte val)
Specified by:
setByte in interface org.hibernate.Query

setShort

public org.hibernate.Query setShort(int position,
                                    short val)
Specified by:
setShort in interface org.hibernate.Query

setInteger

public org.hibernate.Query setInteger(int position,
                                      int val)
Specified by:
setInteger in interface org.hibernate.Query

setLong

public org.hibernate.Query setLong(int position,
                                   long val)
Specified by:
setLong in interface org.hibernate.Query

setFloat

public org.hibernate.Query setFloat(int position,
                                    float val)
Specified by:
setFloat in interface org.hibernate.Query

setDouble

public org.hibernate.Query setDouble(int position,
                                     double val)
Specified by:
setDouble in interface org.hibernate.Query

setBinary

public org.hibernate.Query setBinary(int position,
                                     byte[] val)
Specified by:
setBinary in interface org.hibernate.Query

setText

public org.hibernate.Query setText(int position,
                                   String val)
Specified by:
setText in interface org.hibernate.Query

setSerializable

public org.hibernate.Query setSerializable(int position,
                                           Serializable val)
Specified by:
setSerializable in interface org.hibernate.Query

setLocale

public org.hibernate.Query setLocale(int position,
                                     Locale locale)
Specified by:
setLocale in interface org.hibernate.Query

setBigDecimal

public org.hibernate.Query setBigDecimal(int position,
                                         BigDecimal number)
Specified by:
setBigDecimal in interface org.hibernate.Query

setBigInteger

public org.hibernate.Query setBigInteger(int position,
                                         BigInteger number)
Specified by:
setBigInteger in interface org.hibernate.Query

setDate

public org.hibernate.Query setDate(int position,
                                   Date date)
Specified by:
setDate in interface org.hibernate.Query

setTime

public org.hibernate.Query setTime(int position,
                                   Date date)
Specified by:
setTime in interface org.hibernate.Query

setTimestamp

public org.hibernate.Query setTimestamp(int position,
                                        Date date)
Specified by:
setTimestamp in interface org.hibernate.Query

setCalendar

public org.hibernate.Query setCalendar(int position,
                                       Calendar calendar)
Specified by:
setCalendar in interface org.hibernate.Query

setCalendarDate

public org.hibernate.Query setCalendarDate(int position,
                                           Calendar calendar)
Specified by:
setCalendarDate in interface org.hibernate.Query

setString

public org.hibernate.Query setString(String name,
                                     String val)
Specified by:
setString in interface org.hibernate.Query

setCharacter

public org.hibernate.Query setCharacter(String name,
                                        char val)
Specified by:
setCharacter in interface org.hibernate.Query

setBoolean

public org.hibernate.Query setBoolean(String name,
                                      boolean val)
Specified by:
setBoolean in interface org.hibernate.Query

setByte

public org.hibernate.Query setByte(String name,
                                   byte val)
Specified by:
setByte in interface org.hibernate.Query

setShort

public org.hibernate.Query setShort(String name,
                                    short val)
Specified by:
setShort in interface org.hibernate.Query

setInteger

public org.hibernate.Query setInteger(String name,
                                      int val)
Specified by:
setInteger in interface org.hibernate.Query

setLong

public org.hibernate.Query setLong(String name,
                                   long val)
Specified by:
setLong in interface org.hibernate.Query

setFloat

public org.hibernate.Query setFloat(String name,
                                    float val)
Specified by:
setFloat in interface org.hibernate.Query

setDouble

public org.hibernate.Query setDouble(String name,
                                     double val)
Specified by:
setDouble in interface org.hibernate.Query

setBinary

public org.hibernate.Query setBinary(String name,
                                     byte[] val)
Specified by:
setBinary in interface org.hibernate.Query

setText

public org.hibernate.Query setText(String name,
                                   String val)
Specified by:
setText in interface org.hibernate.Query

setSerializable

public org.hibernate.Query setSerializable(String name,
                                           Serializable val)
Specified by:
setSerializable in interface org.hibernate.Query

setLocale

public org.hibernate.Query setLocale(String name,
                                     Locale locale)
Specified by:
setLocale in interface org.hibernate.Query

setBigDecimal

public org.hibernate.Query setBigDecimal(String name,
                                         BigDecimal number)
Specified by:
setBigDecimal in interface org.hibernate.Query

setBigInteger

public org.hibernate.Query setBigInteger(String name,
                                         BigInteger number)
Specified by:
setBigInteger in interface org.hibernate.Query

setDate

public org.hibernate.Query setDate(String name,
                                   Date date)
Specified by:
setDate in interface org.hibernate.Query

setTime

public org.hibernate.Query setTime(String name,
                                   Date date)
Specified by:
setTime in interface org.hibernate.Query

setTimestamp

public org.hibernate.Query setTimestamp(String name,
                                        Date date)
Specified by:
setTimestamp in interface org.hibernate.Query

setCalendar

public org.hibernate.Query setCalendar(String name,
                                       Calendar calendar)
Specified by:
setCalendar in interface org.hibernate.Query

setCalendarDate

public org.hibernate.Query setCalendarDate(String name,
                                           Calendar calendar)
Specified by:
setCalendarDate in interface org.hibernate.Query

setEntity

public org.hibernate.Query setEntity(int position,
                                     Object val)
Specified by:
setEntity in interface org.hibernate.Query

setEntity

public org.hibernate.Query setEntity(String name,
                                     Object val)
Specified by:
setEntity in interface org.hibernate.Query

setResultTransformer

public org.hibernate.Query setResultTransformer(org.hibernate.transform.ResultTransformer transformer)
Specified by:
setResultTransformer in interface org.hibernate.Query

setProperties

public org.hibernate.Query setProperties(Map map)
                                  throws org.hibernate.HibernateException
Specified by:
setProperties in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException