org.gcube.messaging.common.consumerlibrary.query
Class Query<CALL extends ConsumerCL>

java.lang.Object
  extended by org.gcube.messaging.common.consumerlibrary.query.Query<CALL>
Type Parameters:
CALL -
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AccountingQuery, MonitoringQuery, NotificationQuery, SystemAccountingQuery

public abstract class Query<CALL extends ConsumerCL>
extends Object
implements Serializable

Author:
Andrea Manzi(CERN)
See Also:
Serialized Form

Field Summary
protected  CALL call
           
protected  SimpleDateFormat dateFormat
           
protected  String groupClause
           
protected  String limitClause
           
protected  String orderClause
           
protected  String query
           
protected  String results
           
 
Constructor Summary
Query()
           
 
Method Summary
 CALL getCall()
          get the CALL object
 Long getDimensions(String tableName)
          Get the dimension of the given table
 String getGroupClause()
          get the grouping clause
 String getLimitClause()
          get the limit clause
 String getOrderClause()
          get the order clause for this query
 String getQuery()
          Return the query string ( composed by the user query + grouping+ordering+limits)
 String getResults()
          Get the Query result stored inside the query object
 ArrayList<ArrayList<String>> getResultsAsArray()
          getResultsAsArray (first array contains columns names)
protected abstract  String performQuery()
          The method implemented by subclasses, that performed the query
 void printQueryResults()
          Debug operation, used to print on log query results
 String query()
          Generic SELECT/SHOW MYSQL query
 void setCall(CALL call)
          set the CALL object
 void setGroupClause(String group)
          set the grouping clause
 void setLimitClause(Integer limit)
          set the limit clause
 void setLimitClause(Integer start, Integer limit)
          set the limit clause and starting index
 void setOrderClause(String order)
          set the order clause
 void setQuery(String query)
          set the Query
 void setResults(String results)
          set the results inside the query object
 JSONArray toJSON()
          get results as JSON object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

call

protected CALL extends ConsumerCL call

results

protected String results

query

protected String query

orderClause

protected String orderClause

limitClause

protected String limitClause

groupClause

protected String groupClause

dateFormat

protected SimpleDateFormat dateFormat
Constructor Detail

Query

public Query()
Method Detail

performQuery

protected abstract String performQuery()
                                throws Exception
The method implemented by subclasses, that performed the query

Returns:
the query result as a string
Throws:
Exception

query

public String query()
             throws Exception,
                    QueryNotSetException
Generic SELECT/SHOW MYSQL query

Returns:
A String containing the query results in JSON format
Throws:
Exception - if the query is not valid, or is not a SELECT/SHOW statement
QueryNotSetException

toJSON

public JSONArray toJSON()
                 throws EmptyResultException
get results as JSON object

Returns:
A JSON containing the query results in JSON format
Throws:
JSONException
EmptyResultException

getDimensions

public Long getDimensions(String tableName)
                   throws Exception
Get the dimension of the given table

Parameters:
tableName -
Returns:
the table dimension
Throws:
Exception

printQueryResults

public void printQueryResults()
                       throws Exception
Debug operation, used to print on log query results

Throws:
JSONException
Exception

getCall

public CALL getCall()
get the CALL object

Returns:
the CALL object

setCall

public void setCall(CALL call)
set the CALL object

Parameters:
call - the call object

getResults

public String getResults()
Get the Query result stored inside the query object

Returns:
a String object representing the query results

setResults

public void setResults(String results)
set the results inside the query object

Parameters:
results -

getQuery

public String getQuery()
Return the query string ( composed by the user query + grouping+ordering+limits)

Returns:
the query string ( composed by the user query + grouping+ordering+limits)

setQuery

public void setQuery(String query)
set the Query

Parameters:
query - the query

getOrderClause

public String getOrderClause()
get the order clause for this query

Returns:
the order clause

setOrderClause

public void setOrderClause(String order)
set the order clause

Parameters:
order -

getLimitClause

public String getLimitClause()
get the limit clause

Returns:

setLimitClause

public void setLimitClause(Integer start,
                           Integer limit)
set the limit clause and starting index

Parameters:
limit -
start -

setLimitClause

public void setLimitClause(Integer limit)
set the limit clause

Parameters:
limit -

getGroupClause

public String getGroupClause()
get the grouping clause

Returns:

setGroupClause

public void setGroupClause(String group)
set the grouping clause

Parameters:
group -

getResultsAsArray

public ArrayList<ArrayList<String>> getResultsAsArray()
                                               throws Exception
getResultsAsArray (first array contains columns names)

Returns:
ArrayList>
Throws:
Exception


Copyright © 2013. All Rights Reserved.