atg.repository
Class RepositoryViewImpl

java.lang.Object
  extended by atg.repository.RepositoryViewImpl
All Implemented Interfaces:
NamedQueryView, RepositoryView
Direct Known Subclasses:
IntegrationRepositoryView

public abstract class RepositoryViewImpl
extends java.lang.Object
implements NamedQueryView

This is a basic implementation for the RepositoryView class. It implements properties for all of the settable values.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
protected  atg.repository.query.QueryCache mCache
          currently active query cache
static java.lang.String RESOURCE_BUNDLE_NAME
           
 
Constructor Summary
RepositoryViewImpl()
           
 
Method Summary
 void addNamedQuery(java.lang.String pQueryName, atg.repository.QueryDescriptor pDescriptor)
          Adds an entry to the named query map
 void addQueryListener(atg.repository.QueryListener pListener)
          Adds a query event listener from this view.
 boolean canCacheQuery(java.util.List pDependencies)
          You might override this method to try and deal with a subtle synchronization issue.
 void createNamedQuery(java.lang.String pQueryName, Query pQuery)
          Creates a named query.
abstract  int executeCountQuery(Query pQuery)
          Executes a query that returns the number of items that would be returned by given query.
 RepositoryItem[] executeQuery(Query pQuery)
          Executes the given query and returns an array of the matching RepositoryItems (not ids)
 RepositoryItem[] executeQuery(Query pQuery, int pStartingIndex)
          Executes the given query and returns an array of matching RepositoryItems, beginning at the starting index element.
 RepositoryItem[] executeQuery(Query pQuery, int pStartingIndex, int pEndingIndex)
          Executes the given query and returns an array of matching RepositoryItems, which are contained within a total potential result set.
 RepositoryItem[] executeQuery(Query pQuery, int pStartingIndex, int pEndingIndex, SortDirectives pSortDirectives)
          Executes the given query and returns an array of matching RepositoryItems, which are contained within a total potential result set.
 RepositoryItem[] executeQuery(Query pQuery, int pStartingIndex, SortDirectives pSortDirectives)
          Executes the given query and returns an array of matching RepositoryItems, beginning at the starting index element.
 RepositoryItem[] executeQuery(Query pQuery, QueryOptions pQueryOptions)
          Executes the given query and returns an array of the matching RepositoryItems (not ids)
 RepositoryItem[] executeQuery(Query pQuery, SortDirectives pSortDirectives)
          Executes the given query and returns an array of the matching RepositoryItems (not ids)
abstract  RepositoryItem[] executeUncachedQuery(Query pQuery, QueryOptions pOptions)
          Subclasses determine how query requests are actually satisfied
 RepositoryItem[] executeUncachedQuery(Query pQuery, QueryOptions pOptions, java.lang.Object[] pParameterValues)
          This is a stub implementation so that the QueryCache doesn't have to deal with specific RepositoryView implementations when it calls executeUncachedQuery() with variables.
 atg.repository.query.QueryCache getCache()
          Get property cache
 boolean getCacheQueries()
           
 RepositoryItemDescriptor getItemDescriptor()
          Returns the RepositoryItemDescriptor property, which describes the known properties for all the items in the view
 Query getNamedQuery(java.lang.String pQueryName)
          Gets the Repository Query corresponding to the given name
 java.lang.String[] getNamedQueryNames()
          Returns the names of all the named queries known by this view
abstract  QueryBuilder getQueryBuilder()
          Returns a QueryBuilder to use for creating Query objects
 int getQueryCacheSize()
           
 atg.repository.QueryDescriptor getQueryDescriptor(java.lang.String pQueryName)
          Gets the QueryDescriptor object associated with the given name.
 long getQueryExpireTimeout()
           
 java.util.List getQueryListeners()
          Returns the list of query listeners that are registered on this view.
 java.lang.String getQueryName(Query pQuery)
          Gets the name associated with the given Query, if any
 Repository getRepository()
          Get property Repository
 java.lang.String getViewName()
          Get property ViewName
 void invalidateQueryCache()
          Removes all entries from the query cache
 void removeNamedQuery(java.lang.String pQueryName)
          Removes an entry from the named query map
 void removeQueryDependency(atg.repository.query.QueryDependency pList)
          When a query cache entry is invalidated, we need to remove all cache entries that depend on the same set of properties, the QueryDependency.
 void removeQueryListener(atg.repository.QueryListener pListener)
          Removes a query event listener from this view.
 void sendQueryEvent(Query pQuery, QueryOptions pQueryOptions, RepositoryItem[] pResults)
          Sends a QueryEvent
 void setItemDescriptor(RepositoryItemDescriptor pItemDescriptor)
          Sets the property ItemDescriptor.
 void setQueryCacheSize(int pQueryCacheSize)
          Sets the property queryCacheSize.
 void setQueryExpireTimeout(long pQueryExpireTimeout)
          Sets the property query expire timeout.
 void setRepository(Repository pRepository)
          Set property Repository
 void setViewName(java.lang.String pViewName)
          Set property ViewName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


RESOURCE_BUNDLE_NAME

public static final java.lang.String RESOURCE_BUNDLE_NAME
See Also:
Constant Field Values

mCache

protected atg.repository.query.QueryCache mCache
currently active query cache

Constructor Detail

RepositoryViewImpl

public RepositoryViewImpl()
Method Detail

getCache

public atg.repository.query.QueryCache getCache()
Get property cache

Returns:
cache

setViewName

public void setViewName(java.lang.String pViewName)
Set property ViewName

Parameters:
pViewName - new value to set

getViewName

public java.lang.String getViewName()
Get property ViewName

Specified by:
getViewName in interface RepositoryView
Returns:
ViewName

setRepository

public void setRepository(Repository pRepository)
Set property Repository

Parameters:
pRepository - new value to set

getRepository

public Repository getRepository()
Get property Repository

Returns:
Repository

setItemDescriptor

public void setItemDescriptor(RepositoryItemDescriptor pItemDescriptor)
Sets the property ItemDescriptor.

Parameters:
pItemDescriptor - new value to set

getItemDescriptor

public RepositoryItemDescriptor getItemDescriptor()
Description copied from interface: RepositoryView
Returns the RepositoryItemDescriptor property, which describes the known properties for all the items in the view

Specified by:
getItemDescriptor in interface RepositoryView
Returns:
The value of the property ItemDescriptor.

getCacheQueries

public boolean getCacheQueries()
Returns:
The value of the property CacheQueries. You disable query caching by setting QueryCacheSize to 0.

setQueryCacheSize

public void setQueryCacheSize(int pQueryCacheSize)
Sets the property queryCacheSize. This is the maximum number of queries to cache for this repository view. A value of 0 means to disable caching of queries. A value of -1 means to cache an unlimited number of queries for this view.

Parameters:
pQueryCacheSize - new value to set

getQueryCacheSize

public int getQueryCacheSize()
Returns:
The value of the property QueryCacheSize.

setQueryExpireTimeout

public void setQueryExpireTimeout(long pQueryExpireTimeout)
Sets the property query expire timeout. This is the maximum number of milliseconds a query can live in the cache


getQueryExpireTimeout

public long getQueryExpireTimeout()
Returns:
The value of the property QueryExpireTimeout.

addNamedQuery

public void addNamedQuery(java.lang.String pQueryName,
                          atg.repository.QueryDescriptor pDescriptor)
Adds an entry to the named query map

Parameters:
pQueryName - the name of the query to add
pDescriptor - the query descriptor describing the query

removeNamedQuery

public void removeNamedQuery(java.lang.String pQueryName)
Removes an entry from the named query map

Parameters:
pQueryName - the name of the query to remove

executeQuery

public RepositoryItem[] executeQuery(Query pQuery)
                              throws RepositoryException
Executes the given query and returns an array of the matching RepositoryItems (not ids)

Specified by:
executeQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
Returns:
null if no items could be found to match the query or if the repository does not support query operations
Throws:
RepositoryException - if there is an error while performing the query operation

executeQuery

public RepositoryItem[] executeQuery(Query pQuery,
                                     SortDirectives pSortDirectives)
                              throws RepositoryException
Executes the given query and returns an array of the matching RepositoryItems (not ids)

Specified by:
executeQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
pSortDirectives - the directives to sort the result set with
Returns:
null if no items could be found to match the query or if the repository does not support query operations
Throws:
RepositoryException - if there is an error while performing the query operation

executeQuery

public RepositoryItem[] executeQuery(Query pQuery,
                                     int pStartingIndex)
                              throws RepositoryException
Executes the given query and returns an array of matching RepositoryItems, beginning at the starting index element.

Specified by:
executeQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
pStartingIndex - the beginning index, inclusive
Returns:
null if no items could be found to match the query or if the repository does not support query operations
Throws:
RepositoryException - if there is an error while performing the query operation

executeQuery

public RepositoryItem[] executeQuery(Query pQuery,
                                     int pStartingIndex,
                                     SortDirectives pSortDirectives)
                              throws RepositoryException
Executes the given query and returns an array of matching RepositoryItems, beginning at the starting index element.

Specified by:
executeQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
pStartingIndex - the beginning index, inclusive
pSortDirectives - the directives to sort the result set with
Returns:
null if no items could be found to match the query or if the repository does not support query operations
Throws:
RepositoryException - if there is an error while performing the query operation

executeQuery

public RepositoryItem[] executeQuery(Query pQuery,
                                     int pStartingIndex,
                                     int pEndingIndex)
                              throws RepositoryException
Executes the given query and returns an array of matching RepositoryItems, which are contained within a total potential result set. For example used if one wanted to retrieve elements 50-60 from a query which could return 100 elements.

Specified by:
executeQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
pStartingIndex - the beginning index, inclusive
pEndingIndex - the ending index, exclusive.
Returns:
null if no items could be found to match the query or if the repository does not support query operations
Throws:
RepositoryException - if there is an error while performing the query operation

getQueryBuilder

public abstract QueryBuilder getQueryBuilder()
Returns a QueryBuilder to use for creating Query objects

Specified by:
getQueryBuilder in interface RepositoryView
Returns:
null if the RepositoryView does not support query operations

executeQuery

public RepositoryItem[] executeQuery(Query pQuery,
                                     int pStartingIndex,
                                     int pEndingIndex,
                                     SortDirectives pSortDirectives)
                              throws RepositoryException
Executes the given query and returns an array of matching RepositoryItems, which are contained within a total potential result set. For example used if one wanted to retrieve elements 50-60 from a query which could return 100 elements.

Specified by:
executeQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
pStartingIndex - the beginning index, inclusive
pEndingIndex - the ending index, exclusive.
pSortDirectives - the directives to sort the result set with
Returns:
null if no items could be found to match the query or if the RepositoryView does not support query operations
Throws:
RepositoryException - if there is an error while performing the query operation

executeQuery

public RepositoryItem[] executeQuery(Query pQuery,
                                     QueryOptions pQueryOptions)
                              throws RepositoryException
Executes the given query and returns an array of the matching RepositoryItems (not ids)

Specified by:
executeQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
pQueryOptions - A set of options that may modify the query
Returns:
null if no items could be found to match the query or if the RepositoryView does not support query operations
Throws:
RepositoryException - if there is an error while performing the query operation

createNamedQuery

public void createNamedQuery(java.lang.String pQueryName,
                             Query pQuery)
Creates a named query. This identifies an association between a String name and a Repository Query object. Users can then execute the named Query over and over again without having to rebuild the Query object or its QueryExpressions

Specified by:
createNamedQuery in interface NamedQueryView
Parameters:
pQueryName - the name of the query
pQuery - the Query object associated with the name

getNamedQuery

public Query getNamedQuery(java.lang.String pQueryName)
Gets the Repository Query corresponding to the given name

Specified by:
getNamedQuery in interface NamedQueryView
Parameters:
pQueryName - the name of the query to retrieve
Returns:
the Repository Query identified by pQueryName or null if no Query exists by that name

getQueryName

public java.lang.String getQueryName(Query pQuery)
Gets the name associated with the given Query, if any

Specified by:
getQueryName in interface NamedQueryView
Parameters:
pQuery - the query to get the name for
Returns:
the name associated with the given Query, or null if the Query has no name associated with it

getNamedQueryNames

public java.lang.String[] getNamedQueryNames()
Returns the names of all the named queries known by this view

Specified by:
getNamedQueryNames in interface NamedQueryView
Returns:
an array of names for all the named queries known by this view

getQueryDescriptor

public atg.repository.QueryDescriptor getQueryDescriptor(java.lang.String pQueryName)
Gets the QueryDescriptor object associated with the given name. If no such descriptor exists in this particular view, then any parent views will be checked as well.

Specified by:
getQueryDescriptor in interface NamedQueryView
Parameters:
pQueryName - the name of the named query to get the QueryDescriptor for
Returns:
the QueryDescriptor for the given name, or null if none exists

executeCountQuery

public abstract int executeCountQuery(Query pQuery)
                               throws RepositoryException
Executes a query that returns the number of items that would be returned by given query.

Specified by:
executeCountQuery in interface RepositoryView
Parameters:
pQuery - the query to execute
Returns:
The number of RepositoryItems that would be returned by executeQuery(pQuery)
Throws:
RepositoryException - if there is an error while performing the query operation

executeUncachedQuery

public abstract RepositoryItem[] executeUncachedQuery(Query pQuery,
                                                      QueryOptions pOptions)
                                               throws RepositoryException
Subclasses determine how query requests are actually satisfied

Throws:
RepositoryException

executeUncachedQuery

public RepositoryItem[] executeUncachedQuery(Query pQuery,
                                             QueryOptions pOptions,
                                             java.lang.Object[] pParameterValues)
                                      throws RepositoryException
This is a stub implementation so that the QueryCache doesn't have to deal with specific RepositoryView implementations when it calls executeUncachedQuery() with variables. Those methods should never be called by non-variable enabled repositories anyway, so this is a precaution

Parameters:
pQuery - the query to execute
pQueryOptions - A set of options that may modify the query
pParameterValues - values of any parameter expressions that are in the given query. Each expression is replaced in the order that it is encountered with the corresponding parameter value e.g. the first parameter is replaced with pParameterValues[0], the second parameter is replaced with pParameterValues[1], etc.
Throws:
RepositoryException

invalidateQueryCache

public void invalidateQueryCache()
Removes all entries from the query cache


canCacheQuery

public boolean canCacheQuery(java.util.List pDependencies)
You might override this method to try and deal with a subtle synchronization issue. In the midst of a transaction, if you've modified items in that transaction, queries you make will show these new results. This might cause the query to be cached prematurely with the new information, or worse the transaction could be rolled back and those changes would have been commited in the query cache. This method also checks to make sure that the query is itself cacheable based on what we found out from the nested query nodes.


removeQueryDependency

public void removeQueryDependency(atg.repository.query.QueryDependency pList)
When a query cache entry is invalidated, we need to remove all cache entries that depend on the same set of properties, the QueryDependency. We also remove our notion of these properties since who knows if anyone will make a query with this set of properties again.

In some cases, it might make sense to leave the property list around so that we don't have to add the listeners, but I think it is simpler/safer to just clean up the mess.

Parameters:
pList - dependencies to use in finding entries to invalidate

addQueryListener

public void addQueryListener(atg.repository.QueryListener pListener)
Adds a query event listener from this view.


removeQueryListener

public void removeQueryListener(atg.repository.QueryListener pListener)
Removes a query event listener from this view.


getQueryListeners

public java.util.List getQueryListeners()
Returns the list of query listeners that are registered on this view.


sendQueryEvent

public void sendQueryEvent(Query pQuery,
                           QueryOptions pQueryOptions,
                           RepositoryItem[] pResults)
Sends a QueryEvent