com.gentics.api.lib.datasource
Class ResolvableDatasource

java.lang.Object
  extended by com.gentics.api.lib.datasource.AbstractDatasource
      extended by com.gentics.api.lib.datasource.ResolvableDatasource
All Implemented Interfaces:
Datasource, Cloneable, Iterable, Collection

public class ResolvableDatasource
extends AbstractDatasource
implements Collection

Simple Implementation of a Datasource that is based on a given Collection of Resolvable objects. The class itself implements also the interface Collection and serves as wrapper for the underlying Collection of objects. As Datasource this class supports filtering with RuleTrees, sorting and paging.


Nested Class Summary
protected  class ResolvableDatasource.Sorter
          Comparator class for sorting Resolvables TODO unify this (use the generic Comparator for resolvables)
 
Nested classes/interfaces inherited from interface com.gentics.api.lib.datasource.Datasource
Datasource.Sorting
 
Field Summary
protected  org.apache.log4j.Logger logger
          logger object
 
Fields inherited from interface com.gentics.api.lib.datasource.Datasource
SORTORDER_ASC, SORTORDER_DESC, SORTORDER_NONE
 
Constructor Summary
ResolvableDatasource()
          Create an empty instance of the ResolvableDatasource
ResolvableDatasource(Collection rows)
          Create an instance of the ResolvableDatasource that holds the objects given in the collection
 
Method Summary
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 void clear()
           
 Object clone()
          Clone the datasource (that means to create a copy that would work excactly like this datasource)
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 DatasourceFilter createDatasourceFilter(Expression expression)
          Create a datasource filter for the given expression.
protected  com.gentics.lib.datasource.ResolvableDatasourceFilter getAsResolvableDatasourceFilter(DatasourceFilter filter)
          Get the datasource filter as resolvable datasource filter
 int getCount(DatasourceFilter filter, Map specificParameters)
          Get the number of objects in the datasource that match the given filter
 int getCount2()
          Get the number of rows matching the given rule.
 HandlePool getHandlePool()
          Get the handlepool used by this Datasource.
 Collection getResult(DatasourceFilter filter, String[] prefillAttributes, int start, int count, Datasource.Sorting[] sortedColumns, Map specificParameters)
          Get the resolvables from the datasource that match the given datasource filter.
 Collection getResult(int start, int count, String sortBy, int sortOrder, Map specificParameters)
          Returns data fetched from the Datasource using the given RuleTree as filter.
 boolean hasChanged()
          Return true when data in the underlying storage layer might have changed since the last invocation of Datasource.getResult() (or any of it's variants).
 boolean hasChanged(long timestamp)
          This default implementation simply always returns true.
 boolean isEmpty()
           
 Iterator iterator()
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 boolean retainAll(Collection c)
           
 void setAttributeNames(String[] names)
          Defines Attribute to select or store.
 void setRuleTree(RuleTree ruleTree)
          Set the RuleTree to be used as filter when data is retrieved from this datasource.
 int size()
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 
Methods inherited from class com.gentics.api.lib.datasource.AbstractDatasource
getCount, getCount, getId, getResult, getResult, getResult, getResult, getResult, isValidAttribute, setId
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Field Detail

logger

protected org.apache.log4j.Logger logger
logger object

Constructor Detail

ResolvableDatasource

public ResolvableDatasource()
Create an empty instance of the ResolvableDatasource


ResolvableDatasource

public ResolvableDatasource(Collection rows)
Create an instance of the ResolvableDatasource that holds the objects given in the collection

Parameters:
rows - collection of Resolvable objects
Method Detail

setRuleTree

public void setRuleTree(RuleTree ruleTree)
Description copied from interface: Datasource
Set the RuleTree to be used as filter when data is retrieved from this datasource. The RuleTree may refer to attributes of the fetched objects by "object.[attribute]".
Example: setting the RuleTree object.name == "Username" will filter the Result to those objects from the datasource that have the attribute "name" set to "Username".

Specified by:
setRuleTree in interface Datasource
Parameters:
ruleTree - filter RuleTree
See Also:
Datasource.getResult(DatasourceFilter, String[]), Datasource.createDatasourceFilter(Expression)

setAttributeNames

public void setAttributeNames(String[] names)
Description copied from interface: Datasource
Defines Attribute to select or store.

Specified by:
setAttributeNames in interface Datasource
Parameters:
names - array of attribute names

getResult

public Collection getResult(int start,
                            int count,
                            String sortBy,
                            int sortOrder,
                            Map specificParameters)
                     throws DatasourceNotAvailableException
Description copied from interface: Datasource
Returns data fetched from the Datasource using the given RuleTree as filter.

Specified by:
getResult in interface Datasource
Parameters:
start - index of the first object to get after the filter and sorting have been applied (counting starts with 0)
count - maximum number of objects to return, -1 for no limit
sortBy - property to sortby, null for unsorted result. May also contain a comma separated list of attribute names
sortOrder - sort order, use one of Datasource.SORTORDER_ASC, Datasource.SORTORDER_DESC Datasource.SORTORDER_NONE
specificParameters - map of specific parameters, which will be interpreted by some specific Datasources, may be null or empty (no specific parameters)
Returns:
a Collection holding the retrieved objects
Throws:
DatasourceNotAvailableException

getCount2

public int getCount2()
              throws DatasourceNotAvailableException
Description copied from interface: Datasource
Get the number of rows matching the given rule.

Specified by:
getCount2 in interface Datasource
Returns:
# of rows in the datasource
Throws:
DatasourceNotAvailableException

getHandlePool

public HandlePool getHandlePool()
Description copied from interface: Datasource
Get the handlepool used by this Datasource. Internal method should not be invoked from outside.

Specified by:
getHandlePool in interface Datasource
Returns:
the handlepool

clone

public Object clone()
             throws CloneNotSupportedException
Description copied from interface: Datasource
Clone the datasource (that means to create a copy that would work excactly like this datasource)

Specified by:
clone in interface Datasource
Overrides:
clone in class AbstractDatasource
Throws:
CloneNotSupportedException

hasChanged

public boolean hasChanged()
Description copied from interface: Datasource
Return true when data in the underlying storage layer might have changed since the last invocation of Datasource.getResult() (or any of it's variants). The specific implementations can simply return true when a change cannot be determined other than refetching the data or can do any specific checks for modified data.

Specified by:
hasChanged in interface Datasource
Returns:
true when data might have changed, false if no data was changed (it is safe for the caller to reuse previously fetched data)

hasChanged

public boolean hasChanged(long timestamp)
Description copied from class: AbstractDatasource
This default implementation simply always returns true. Implementors should overwrite this method if it is possible to determine when data was last changed.

Specified by:
hasChanged in interface Datasource
Overrides:
hasChanged in class AbstractDatasource
Parameters:
timestamp - timestamp to check if data has propably changed - timestamp is a java timestamp - ie. milliseconds since 1970 like System.currentTimeMillis()
Returns:
true if data has changed since the given timestamp or if it is not impossible to determine if data was changed. - false if it is propably that data has not changed.
See Also:
Datasource.hasChanged(long)

size

public int size()
Specified by:
size in interface Collection

clear

public void clear()
Specified by:
clear in interface Collection

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection

add

public boolean add(Object o)
Specified by:
add in interface Collection

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection

createDatasourceFilter

public DatasourceFilter createDatasourceFilter(Expression expression)
                                        throws ExpressionParserException
Description copied from interface: Datasource
Create a datasource filter for the given expression. The datasource filter can later be used to filter datasources of the same type.

Specified by:
createDatasourceFilter in interface Datasource
Parameters:
expression - expression to transform into a datasource filter
Returns:
datasource filter
Throws:
ExpressionParserException - When the DatasourceFilter can't be created

getResult

public Collection getResult(DatasourceFilter filter,
                            String[] prefillAttributes,
                            int start,
                            int count,
                            Datasource.Sorting[] sortedColumns,
                            Map specificParameters)
                     throws DatasourceException
Description copied from interface: Datasource
Get the resolvables from the datasource that match the given datasource filter.

Specified by:
getResult in interface Datasource
Parameters:
filter - datasource filter
prefillAttributes - array of attribute names to prefill (null or empty for no prefilling)
start - index of the first object to return
count - maximum number of objects to return (-1 for all objects).
sortedColumns - possible sorting (may be null for "no sorting")
specificParameters - map of specific parameters, which will be interpreted by some specific Datasources, may be null or empty (no specific parameters)
Returns:
collection of resolvables matching the filter
Throws:
DatasourceException
See Also:
Datasource.createDatasourceFilter(Expression)

getCount

public int getCount(DatasourceFilter filter,
                    Map specificParameters)
             throws DatasourceException
Description copied from interface: Datasource
Get the number of objects in the datasource that match the given filter

Specified by:
getCount in interface Datasource
Parameters:
filter - datasource filter
specificParameters - map of specific parameters, which will be interpreted by some specific Datasources, may be null or empty (no specific parameters)
Returns:
number of objects that match the filter
Throws:
DatasourceException
See Also:
Datasource.createDatasourceFilter(Expression)

getAsResolvableDatasourceFilter

protected com.gentics.lib.datasource.ResolvableDatasourceFilter getAsResolvableDatasourceFilter(DatasourceFilter filter)
                                                                                         throws DatasourceException
Get the datasource filter as resolvable datasource filter

Parameters:
filter - filter
Returns:
resolvable datasource filter
Throws:
DatasourceException


Copyright © 2013 Gentics Software GmbH. All Rights Reserved.