org.geotools.data
Class DefaultQuery

Object
  extended by DefaultQuery
All Implemented Interfaces:
Query

public class DefaultQuery
extends Object
implements Query

The query object is used by the FeatureSource.getFeatures() method of the DataSource interface, to encapsulate a request. It defines which feature type to query, what properties to retrieve and what constraints (spatial and non-spatial) to apply to those properties. It is designed to closesly match a WFS Query element of a getFeatures request. The only difference is the addition of the maxFeatures element, which allows more control over the features selected. It allows a full getFeatures request to properly control how many features it gets from each query, instead of requesting and discarding when the max is reached.

Author:
Chris Holmes
Module:

Field Summary
 
Fields inherited from interface Query
ALL, ALL_NAMES, DEFAULT_MAX, FIDS, NO_NAMES, NO_NAMESPACE
 
Constructor Summary
DefaultQuery()
          /** No argument constructor.
DefaultQuery(Query query)
          Copy contructor, clones the state of a generic Query into a DefaultQuery
DefaultQuery(String typeName)
          Query with typeName.
DefaultQuery(String typeName, Filter filter)
          Constructor with typeName and filter.
DefaultQuery(String typeName, Filter filter, int maxFeatures, String[] propNames, String handle)
          Constructor that sets all fields.
DefaultQuery(String typeName, Filter filter, String[] properties)
          Constructor that sets the filter and properties
DefaultQuery(String typeName, URI namespace, Filter filter, int maxFeatures, String[] propNames, String handle)
          Constructor that sets all fields.
 
Method Summary
 boolean equals(Object obj)
          Equality based on propertyNames, maxFeatures, filter, typeName and version.
 CoordinateReferenceSystem getCoordinateSystem()
          getCoordinateSystem purpose.
 CoordinateReferenceSystem getCoordinateSystemReproject()
          getCoordinateSystemReproject purpose.
 Filter getFilter()
          The Filter can be used to define constraints on a query.
 String getHandle()
          The handle attribute is included to allow a client to associate a mnemonic name to the Query request.
 Hints getHints()
          Specifies some hints to drive the query execution and results build-up.
 int getMaxFeatures()
          The optional maxFeatures can be used to limit the number of features that a query request retrieves.
 URI getNamespace()
          The namespace attribute is used to indicate the namespace of the schema being represented.
 String[] getPropertyNames()
          The property names is used to specify the attributes that should be selected for the return feature collection.
 SortBy[] getSortBy()
          Retrive list of SortBy information.
 Integer getStartIndex()
           
 String getTypeName()
          The typeName attribute is used to indicate the name of the feature type to be queried.
 String getVersion()
          From WFS Spec: The version attribute is included in order to accommodate systems that support feature versioning.
 int hashCode()
          Hashcode based on propertyName, maxFeatures and filter.
 boolean retrieveAllProperties()
          Convenience method to determine if the query should use the full schema (all properties) of the data source for the features returned.
 void setCoordinateSystem(CoordinateReferenceSystem system)
          setCoordinateSystem purpose.
 void setCoordinateSystemReproject(CoordinateReferenceSystem system)
          setCoordinateSystemReproject purpose.
 void setFilter(Filter filter)
          Sets the filter to constrain the query.
 void setHandle(String handle)
          Sets a mnemonic name for the query request.
 void setHints(Hints hints)
          Sets the query hints
 void setMaxFeatures(int maxFeatures)
          Sets the max features to retrieved by this query.
 void setPropertyNames(List propNames)
          Sets the proper attributeTypes constructed from a schema and a list of propertyNames.
 void setPropertyNames(String[] propNames)
          Sets the properties to retrieve from the db.
 void setSortBy(SortBy[] sortBy)
          Sets the sort by information.
 void setStartIndex(Integer startIndex)
           
 void setTypeName(String typeName)
          Sets the typename.
 void setVersion(String version)
           
 String toString()
          Over ride of toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultQuery

public DefaultQuery()
/** No argument constructor.


DefaultQuery

public DefaultQuery(String typeName)
Query with typeName.

Parameters:
typeName - the name of the featureType to retrieve

DefaultQuery

public DefaultQuery(String typeName,
                    Filter filter)
Constructor with typeName and filter. Note that current datasource implementations only have one type per datasource, so the typeName field will likely be ignored.

Parameters:
typeName - the name of the featureType to retrieve.
filter - the OGC filter to constrain the request.

DefaultQuery

public DefaultQuery(String typeName,
                    Filter filter,
                    String[] properties)
Constructor that sets the filter and properties

Parameters:
typeName -
filter - the OGC filter to constrain the request.
properties - an array of the properties to fetch.

DefaultQuery

public DefaultQuery(String typeName,
                    Filter filter,
                    int maxFeatures,
                    String[] propNames,
                    String handle)
Constructor that sets all fields.

Parameters:
typeName - the name of the featureType to retrieve.
filter - the OGC filter to constrain the request.
maxFeatures - the maximum number of features to be returned.
propNames - an array of the properties to fetch.
handle - the name to associate with the query.

DefaultQuery

public DefaultQuery(String typeName,
                    URI namespace,
                    Filter filter,
                    int maxFeatures,
                    String[] propNames,
                    String handle)
Constructor that sets all fields.

Parameters:
typeName - the name of the featureType to retrieve.
namespace - Namespace for provided typeName, or null if unspecified
filter - the OGC filter to constrain the request.
maxFeatures - the maximum number of features to be returned.
propNames - an array of the properties to fetch.
handle - the name to associate with the query.

DefaultQuery

public DefaultQuery(Query query)
Copy contructor, clones the state of a generic Query into a DefaultQuery

Parameters:
query -
Method Detail

getPropertyNames

public String[] getPropertyNames()
The property names is used to specify the attributes that should be selected for the return feature collection. If the property array is null, then the datasource should return all available properties, its full schema. If an array of specified then the full schema should be used (all property names). The property names can be determined with a getSchema call from the DataSource interface.

This replaces our funky setSchema method of retrieving select properties. I think it makes it easier to understand how to get certain properties out of the datasource, instead of having users get the schema and then compose a new schema using the attributes that they want. The old way was also giving me problems because I couldn't have multiple object reuse the same datasource object, since some other object could come along and change its schema, and would then return the wrong properties.

Specified by:
getPropertyNames in interface Query
Returns:
the property names to be used in the returned FeatureCollection.

setPropertyNames

public void setPropertyNames(String[] propNames)
Sets the properties to retrieve from the db. If the boolean to load all properties is set to true then the AttributeTypes that are not in the database's schema will just be filled with null values.

Parameters:
propNames - The names of attributes to load from the datasouce.

setPropertyNames

public void setPropertyNames(List propNames)
Sets the proper attributeTypes constructed from a schema and a list of propertyNames.

Parameters:
propNames - the names of the properties to check against the schema. If null then all attributes will be returned. If a List of size 0 is used then only the featureIDs should be used.
TODO:
REVISIT: This syntax is really obscure. Consider having an fid or featureID propertyName that datasource implementors look for instead of looking to see if the list size is 0.

retrieveAllProperties

public boolean retrieveAllProperties()
Convenience method to determine if the query should use the full schema (all properties) of the data source for the features returned. This method is equivalent to if (query.getProperties() == null), but allows for more clarity on the part of datasource implementors, so they do not need to examine and use null values. All Query implementations should return true for this function if getProperties returns null.

Specified by:
retrieveAllProperties in interface Query
Returns:
if all datasource attributes should be included in the schema of the returned FeatureCollection.

getMaxFeatures

public int getMaxFeatures()
The optional maxFeatures can be used to limit the number of features that a query request retrieves. If no maxFeatures is specified then all features should be returned.

This is the only method that is not directly out of the Query element in the WFS spec. It is instead a part of a getFeatures request, which can hold one or more queries. But each of those in turn will need a maxFeatures, so it is needed here.

Specified by:
getMaxFeatures in interface Query
Returns:
the max features the getFeature call should return.

getStartIndex

public Integer getStartIndex()
Specified by:
getStartIndex in interface Query

setStartIndex

public void setStartIndex(Integer startIndex)

setMaxFeatures

public void setMaxFeatures(int maxFeatures)
Sets the max features to retrieved by this query.

Parameters:
maxFeatures - the maximum number of features the getFeature call should return.

getFilter

public Filter getFilter()
The Filter can be used to define constraints on a query. If no Filter is present then the query is unconstrained and all feature instances should be retrieved.

Specified by:
getFilter in interface Query
Returns:
The filter that defines constraints on the query.

setFilter

public void setFilter(Filter filter)
Sets the filter to constrain the query.

Parameters:
filter - the OGC filter to limit the datasource getFeatures request.

getTypeName

public String getTypeName()
The typeName attribute is used to indicate the name of the feature type to be queried.

The DataStore API does not assume one feature type per datastore. It currently makes use of this field to to specify with each request what type to get.

Specified by:
getTypeName in interface Query
Returns:
the name of the feature type to be returned with this query.

getNamespace

public URI getNamespace()
Description copied from interface: Query
The namespace attribute is used to indicate the namespace of the schema being represented.

Specified by:
getNamespace in interface Query
Returns:
the gml namespace of the feature type to be returned with this query

setTypeName

public void setTypeName(String typeName)
Sets the typename.

Parameters:
typeName - the name of the featureType to retrieve.

getHandle

public String getHandle()
The handle attribute is included to allow a client to associate a mnemonic name to the Query request. The purpose of the handle attribute is to provide an error handling mechanism for locating a statement that might fail.

Specified by:
getHandle in interface Query
Returns:
the mnemonic name of the query request.

setHandle

public void setHandle(String handle)
Sets a mnemonic name for the query request.

Parameters:
handle - the name to refer to this query.

getVersion

public String getVersion()
From WFS Spec: The version attribute is included in order to accommodate systems that support feature versioning. A value of ALL indicates that all versions of a feature should be fetched. Otherwise an integer, n, can be specified to return the n th version of a feature. The version numbers start at '1' which is the oldest version. If a version value larger than the largest version is specified then the latest version is return. The default action shall be for the query to return the latest version. Systems that do not support versioning can ignore the parameter and return the only version that they have.

This is ready for use, it will be up to data store implementors to support it.

Specified by:
getVersion in interface Query
Returns:
the version of the feature to return, or null for latest.

setVersion

public void setVersion(String version)
Parameters:
version -
Since:
2.4
See Also:
getVersion()

hashCode

public int hashCode()
Hashcode based on propertyName, maxFeatures and filter.

Overrides:
hashCode in class Object
Returns:
hascode for filter

equals

public boolean equals(Object obj)
Equality based on propertyNames, maxFeatures, filter, typeName and version.

Changing the handle does not change the meaning of the Query.

Overrides:
equals in class Object
Parameters:
obj - Other object to compare against
Returns:
true if obj matches this filter

toString

public String toString()
Over ride of toString

Overrides:
toString in class Object
Returns:
a string representation of this query object.

getCoordinateSystem

public CoordinateReferenceSystem getCoordinateSystem()
getCoordinateSystem purpose.

Description ...

Specified by:
getCoordinateSystem in interface Query
Returns:
The coordinate system to be returned for Features from this Query (override the set coordinate system).

getCoordinateSystemReproject

public CoordinateReferenceSystem getCoordinateSystemReproject()
getCoordinateSystemReproject purpose.

Description ...

Specified by:
getCoordinateSystemReproject in interface Query
Returns:
The coordinate system that Features from the datasource should be reprojected to.

setCoordinateSystem

public void setCoordinateSystem(CoordinateReferenceSystem system)
setCoordinateSystem purpose.

Description ...

Parameters:
system -

setCoordinateSystemReproject

public void setCoordinateSystemReproject(CoordinateReferenceSystem system)
setCoordinateSystemReproject purpose.

Description ...

Parameters:
system -

getSortBy

public SortBy[] getSortBy()
Retrive list of SortBy information.

Note we are using SortBy2, to be standards complient you may limit yourself to to SortBy information.

Specified by:
getSortBy in interface Query
Returns:
SortBy array or order of application

setSortBy

public void setSortBy(SortBy[] sortBy)
Sets the sort by information.


getHints

public Hints getHints()
Description copied from interface: Query
Specifies some hints to drive the query execution and results build-up. Hints examples can be the GeometryFactory to be used, a generalization distance to be applied right in the data store, to data store specific things such as the fetch size to be used in JDBC queries. The set of hints supported can be fetched by calling . Depending on the actual values of the hints, the data store is free to ignore them. No mechanism is in place, at the moment, to figure out which hints where actually used during the query execution.

Specified by:
getHints in interface Query
Returns:
the Hints the data store should try to use when executing the query (eventually empty but never null).

setHints

public void setHints(Hints hints)
Sets the query hints

Parameters:
hints -


Copyright © 1996-2009 Geotools. All Rights Reserved.