com.gentics.api.lib.datasource
Class AbstractDatasource

java.lang.Object
  extended by com.gentics.api.lib.datasource.AbstractDatasource
All Implemented Interfaces:
Datasource, Cloneable
Direct Known Subclasses:
AbstractCacheableDatasource, AbstractVersioningDatasource, ResolvableDatasource

public abstract class AbstractDatasource
extends Object
implements Datasource

Abstract basic implementation for datasources. Implementing your own datasources is not supported right now. When the time has come, one should rather extend this class than implement the interface Datasource directly in order to


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.gentics.api.lib.datasource.Datasource
Datasource.Sorting
 
Field Summary
 
Fields inherited from interface com.gentics.api.lib.datasource.Datasource
SORTORDER_ASC, SORTORDER_DESC, SORTORDER_NONE
 
Constructor Summary
AbstractDatasource()
          If you use this super constructor as implementor, you should always call setId(String) afterwards - but it is recommended to use AbstractDatasource(String) instead.
AbstractDatasource(String id)
           
 
Method Summary
 Object clone()
          Clone the datasource (that means to create a copy that would work excactly like this datasource)
 int getCount()
          Get the number of rows matching the given rule.
 int getCount(DatasourceFilter filter)
          Get the number of objects in the datasource that match the given filter
 String getId()
          Returns the unique identifier for this Datasource.
 Collection getResult()
          Deprecated. use getResult(DatasourceFilter, String[]) instead.
 Collection<Resolvable> getResult(DatasourceFilter filter, String[] prefillAttributes)
          Get the resolvables from the datasource that match the given datasource filter (unsorted).
 Collection<Resolvable> getResult(DatasourceFilter filter, String[] prefillAttributes, int start, int count, Datasource.Sorting[] sortedColumns)
          Get the resolvables from the datasource that match the given datasource filter.
 Collection getResult(int start, int count, String sortBy, int sortOrder)
          Deprecated. use {@link #getResult(DatasourceFilter, String[], int, int, Sorting[]) instead.
 Collection getResult(String sortBy, int sortOrder)
          Deprecated. use {@link #getResult(DatasourceFilter, String[], int, int, Sorting[]) instead.
 boolean hasChanged(long timestamp)
          This default implementation simply always returns true.
 boolean isValidAttribute(String attributeName)
          This default implementation will always return null because there is no generic way of determine if an attribute name is valid.
 void setId(String id)
          Allows to set the id of this datasource.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.gentics.api.lib.datasource.Datasource
createDatasourceFilter, getCount, getCount2, getHandlePool, getResult, getResult, hasChanged, setAttributeNames, setRuleTree
 

Constructor Detail

AbstractDatasource

public AbstractDatasource(String id)
Parameters:
id - Id for this datasource.

AbstractDatasource

public AbstractDatasource()
If you use this super constructor as implementor, you should always call setId(String) afterwards - but it is recommended to use AbstractDatasource(String) instead.

Method Detail

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 Object
Throws:
CloneNotSupportedException

getResult

public Collection getResult()
                     throws DatasourceNotAvailableException
Deprecated. use getResult(DatasourceFilter, String[]) instead.

Specified by:
getResult in interface Datasource
Returns:
a Collection holding the retrieved objects
Throws:
DatasourceNotAvailableException
See Also:
Datasource.getResult()

getResult

public Collection getResult(int start,
                            int count,
                            String sortBy,
                            int sortOrder)
                     throws DatasourceNotAvailableException
Deprecated. use {@link #getResult(DatasourceFilter, String[], int, int, Sorting[]) instead.

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
Returns:
a Collection holding the retrieved objects
Throws:
DatasourceNotAvailableException
See Also:
Datasource.getResult(int, int, java.lang.String, int)

getResult

public Collection getResult(String sortBy,
                            int sortOrder)
                     throws DatasourceNotAvailableException
Deprecated. use {@link #getResult(DatasourceFilter, String[], int, int, Sorting[]) instead.

Description copied from interface: Datasource
Returns data fetched from the Datasource using the given RuleTree as filter.

Specified by:
getResult in interface Datasource
Parameters:
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
Returns:
a Collection holding the retrieved objects
Throws:
DatasourceNotAvailableException
See Also:
Datasource.getResult(java.lang.String, int)

getCount

public int getCount(DatasourceFilter filter)
             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
Returns:
number of objects that match the filter
Throws:
DatasourceException
See Also:
Datasource.createDatasourceFilter(Expression)

getResult

public Collection<Resolvable> getResult(DatasourceFilter filter,
                                        String[] prefillAttributes)
                                 throws DatasourceException
Description copied from interface: Datasource
Get the resolvables from the datasource that match the given datasource filter (unsorted).

Specified by:
getResult in interface Datasource
Parameters:
filter - datasource filter
prefillAttributes - array of attribute names to prefill (null or empty for no prefilling)
Returns:
collection of resolvables matching the filter
Throws:
DatasourceException
See Also:
Datasource.createDatasourceFilter(Expression)

getResult

public Collection<Resolvable> getResult(DatasourceFilter filter,
                                        String[] prefillAttributes,
                                        int start,
                                        int count,
                                        Datasource.Sorting[] sortedColumns)
                                 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")
Returns:
collection of resolvables matching the filter
Throws:
DatasourceException
See Also:
Datasource.createDatasourceFilter(Expression)

hasChanged

public boolean hasChanged(long timestamp)
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
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)

getId

public String getId()
Description copied from interface: Datasource
Returns the unique identifier for this Datasource.

Specified by:
getId in interface Datasource
Returns:
an unique identifier for this datasource.

setId

public void setId(String id)
Allows to set the id of this datasource. the preferred way is to use the constructor AbstractDatasource(String) tough.

Parameters:
id - the id for this datasource.
See Also:
getId()

getCount

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

Specified by:
getCount in interface Datasource
Returns:
# of rows in the datasource

isValidAttribute

public boolean isValidAttribute(String attributeName)
                         throws DatasourceException
This default implementation will always return null because there is no generic way of determine if an attribute name is valid.

Specified by:
isValidAttribute in interface Datasource
Parameters:
attributeName - the attribute name to check
Returns:
true if the attribute is valid and exists, false otherwise.
Throws:
DatasourceException
See Also:
Datasource.isValidAttribute(java.lang.String)


Copyright © 2013 Gentics Software GmbH. All Rights Reserved.