org.gcube.common.core.informationsystem.client.impl
Class AbstractClient

java.lang.Object
  extended by org.gcube.common.core.informationsystem.client.impl.AbstractClient
All Implemented Interfaces:
ISClient

public abstract class AbstractClient
extends Object
implements ISClient

Partial implementation of the ISClient. Subclasses implement specific methods to load implementations of standard {link ISQuery ISQueries}, and to execute those queries against the associated Information System.

Author:
Andrea Manzi (CNR), Fabio Simeoni (University of Strathclyde)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.gcube.common.core.informationsystem.client.ISClient
ISClient.ISMalformedQueryException, ISClient.ISMalformedResultException, ISClient.ISUnsupportedQueryException
 
Field Summary
protected static Map<String,String> genericQueries
          Query implementations indexed by their implementation-defined name.
protected static Map<Class<? extends ISQuery<?>>,Class<? extends ISQuery<?>>> implementationMap
          Query implementations indexed by their standard interface.
protected  GCUBELog logger
          Object logger.
 
Constructor Summary
AbstractClient()
          Creates a new instance and loads query implementations if not previously done.
 
Method Summary
protected  void checkQuery(ISQuery<?> query)
          Invoked internally by execute(ISQuery, GCUBEScope) to check that a can be handled by the implementation and is in fact well-formed.
abstract
<RESULT> List<RESULT>
execute(ISQuery<RESULT> query, GCUBEScope scope)
          Evaluates a query in a given scope and returns its results a local list.
abstract
<RESULT> ISInputStream<RESULT>
executeByRef(ISQuery<RESULT> query, GCUBEScope scope)
          Implement to execute the query against the associated Information System in a given scope, and to return the locator of a resultset which contains the unparsed result serialisations.
<RESULT,QUERY extends ISQuery<RESULT>>
QUERY
getQuery(Class<QUERY> clazz)
          Returns a query from the interface or class which defines its type.
protected  Class<? extends AbstractQuery> getQueryBaseClass()
          Returns the subtype of AbstractQuery used as the base class for query implementations.
protected abstract  void loadGenericQueries(Map<String,String> queryMap)
          Implement to load query implementations in a map which indexes by their standard interfaces.
protected abstract  void loadQueries(Map<Class<? extends ISQuery<?>>,Class<? extends ISQuery<?>>> queryMap)
          Implement to load query implementations in a map which indexes by their standard interfaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gcube.common.core.informationsystem.client.ISClient
getQuery
 

Field Detail

logger

protected GCUBELog logger
Object logger.


implementationMap

protected static Map<Class<? extends ISQuery<?>>,Class<? extends ISQuery<?>>> implementationMap
Query implementations indexed by their standard interface.


genericQueries

protected static Map<String,String> genericQueries
Query implementations indexed by their implementation-defined name.

Constructor Detail

AbstractClient

public AbstractClient()
Creates a new instance and loads query implementations if not previously done.

Method Detail

loadQueries

protected abstract void loadQueries(Map<Class<? extends ISQuery<?>>,Class<? extends ISQuery<?>>> queryMap)
Implement to load query implementations in a map which indexes by their standard interfaces.

Parameters:
queryMap - the map.

loadGenericQueries

protected abstract void loadGenericQueries(Map<String,String> queryMap)
Implement to load query implementations in a map which indexes by their standard interfaces.

Parameters:
queryMap - the map.

getQuery

public <RESULT,QUERY extends ISQuery<RESULT>> QUERY getQuery(Class<QUERY> clazz)
                                       throws ISClient.ISUnsupportedQueryException,
                                              InstantiationException,
                                              IllegalAccessException
Returns a query from the interface or class which defines its type. The method is intended as a means to bind query interfaces to concrete implementations provided along with implementations of this interface.

Specified by:
getQuery in interface ISClient
Type Parameters:
RESULT - the type of the query results.
QUERY - the type of the query which produces results of type RESULT.
Parameters:
clazz - the query interface or class.
Returns:
the query.
Throws:
ISClient.ISUnsupportedQueryException
InstantiationException
IllegalAccessException

execute

public abstract <RESULT> List<RESULT> execute(ISQuery<RESULT> query,
                                              GCUBEScope scope)
                              throws ISClient.ISUnsupportedQueryException,
                                     ISException
Evaluates a query in a given scope and returns its results a local list.

Specified by:
execute in interface ISClient
Type Parameters:
RESULT - The type of the query results.
Parameters:
query - the query.
scope - the scope.
Returns:
the results.
Throws:
ISMalformedResultException
ISClient.ISMalformedQueryException - if the query is incorrectly formulated and cannot produce results.
ISException - if the evaluation could not be completed.
ISClient.ISUnsupportedQueryException

checkQuery

protected void checkQuery(ISQuery<?> query)
                   throws ISClient.ISMalformedQueryException,
                          ISClient.ISUnsupportedQueryException
Invoked internally by execute(ISQuery, GCUBEScope) to check that a can be handled by the implementation and is in fact well-formed. By default it checks that the query is an AbstractQuery and can thus be handled by subclasses. Subclasses may wish to override the method to enforce more specific checks.

Parameters:
query - the query.
Throws:
ISMalformedQueryException - if the query is not well-formed.
ISInvalidQueryException - if the query if of a type which cannot be processed by the implementatio
ISClient.ISMalformedQueryException
ISClient.ISUnsupportedQueryException

executeByRef

public abstract <RESULT> ISInputStream<RESULT> executeByRef(ISQuery<RESULT> query,
                                                            GCUBEScope scope)
                                            throws ISClient.ISMalformedQueryException,
                                                   ISClient.ISUnsupportedQueryException,
                                                   ISException
Implement to execute the query against the associated Information System in a given scope, and to return the locator of a resultset which contains the unparsed result serialisations. Note that, if required, the query can be safely cast to the subtype of AbstractQuery used by the implementation, as runtime checks. have already been performed.

Specified by:
executeByRef in interface ISClient
Type Parameters:
RESULT - The type of the query results.
Parameters:
query - the query.
scope - the scope.
Returns:
the ISInputStream.
Throws:
ISException - if the query could not be executed
ISClient.ISMalformedQueryException - if the query is incorrectly formulated and cannot produce results.
ISClient.ISUnsupportedQueryException

getQueryBaseClass

protected Class<? extends AbstractQuery> getQueryBaseClass()
Returns the subtype of AbstractQuery used as the base class for query implementations. This is used by the client to check the validity of queries once and where most convenient on behalf of its subclasses.

Returns:
the base class.


Copyright © 2013. All Rights Reserved.