Query#

public class Query implements QueryInterface, ToElementable, EntityTransactionInterface#

This class represents a single, complete Query execution from the parsing of the query string to the resulting list of entity ids.

This class handles caching of queries and checking retrieve permissions as well. It does not, however, retrieve the resulting entities; this is handled by the Retrieve class.

Author:

Timm Fitschen

Fields#

resultSet#

List<IdVersionAclTriplet> resultSet#

Constructors#

Query#

public Query(String query)#

Query#

public Query(String query, Subject user)#

Query#

public Query(String query, Transaction<? extends TransactionContainer> transaction)#

Query#

public Query(String query, Subject user, TransactionContainer container, EntityTransactionInterface transaction, Access access)#

Methods#

addBenchmark#

public void addBenchmark(String str, long time)#

addToElement#

public void addToElement(Element parent)#

applyQueryTemplates#

public void applyQueryTemplates(QueryInterface query, String resultSet)#

Finds all QueryTemplates in the resultSet and applies them to the same resultSet. The IDs of the QueryTemplates themselves are then removed from the resultSet. If the current user doesn’t have the RETRIEVE:ENTITY permission for a particular QueryTemplate it will be ignored.

Parameters:
  • resultSet

Throws:

clearCache#

public static void clearCache()#

Remove all cached queries from the cache.

execute#

public void execute()#

Execute the query.

First try the cache and only then use the back-end.

Throws:
  • ParsingException, – QueryException

executeQueryInBackend#

protected void executeQueryInBackend(Access access)#

filterIntermediateResult#

public void filterIntermediateResult(String tabname)#

Filter out all entities which may not be retrieved by this user due to a missing RETRIEVE permission. This function is also designed for filtering of intermediate results.

Parameters:
  • tabname

Throws:

getAccess#

public Access getAccess()#

getCacheKey#

String getCacheKey(boolean addUser)#

Return a key for the query cache. The key should describe the query with all the filters but without the FIND, COUNT and SELECT … FROM parts.

Returns:

A Cache key.

getConnection#

public Connection getConnection()#

getCount#

public int getCount()#

getETag#

public static String getETag()#

Return the ETag.

The ETag tags the query cache and is renewed each time the cache is being cleared, i.e. each time the database is being updated.

Returns:

The ETag

getEntity#

public Pattern getEntity()#

getQuery#

public Query getQuery()#

getRole#

public Role getRole()#

getSelections#

public List<Selection> getSelections()#

getSourceSet#

public String getSourceSet()#

getTargetSet#

public String getTargetSet()#

getTargetSetCount#

public int getTargetSetCount()#
Returns:

the number of entities in the resultset. Might be updated by the filters.

getTimestamp#

public UTCDateTime getTimestamp()#

getTransactionBenchmark#

public TransactionBenchmark getTransactionBenchmark()#

getType#

public Type getType()#

getUser#

public Subject getUser()#

isVersioned#

public boolean isVersioned()#

matchIdPattern#

public boolean matchIdPattern(String id)#

optimize#

public void optimize()#

Optimize the query after parsing. The optimization is purely based on formal rules.

Implemented rules:

  1. FIND * -> FIND ENTITY (which basically prevents to copy the complete entity table just to read out the IDs immediately).

parse#

public void parse(boolean optimize)#

Parse the query and run optimize() if the parameter optimize is true.

Parameters:
  • optimize – whether to run optimize() immediately.

Throws:

parse#

public void parse()#

Parse the query and run optimize() immediately.

Throws:

setTargetSetCount#

public void setTargetSetCount(Integer c)#

toString#

public String toString()#