org.geotools.data
Class DefaultQuery

java.lang.Object
  extended byorg.geotools.data.DefaultQuery
All Implemented Interfaces:
Query

public class DefaultQuery
extends java.lang.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

Field Summary
 
Fields inherited from interface org.geotools.data.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(java.lang.String typeName)
          Query with typeName.
DefaultQuery(java.lang.String typeName, Filter filter)
          Constructor with typeName and filter.
DefaultQuery(java.lang.String typeName, Filter filter, int maxFeatures, java.lang.String[] propNames, java.lang.String handle)
          Constructor that sets all fields.
DefaultQuery(java.lang.String typeName, Filter filter, java.lang.String[] properties)
          Constructor that sets the filter and properties
DefaultQuery(java.lang.String typeName, java.net.URI namespace, Filter filter, int maxFeatures, java.lang.String[] propNames, java.lang.String handle)
          Constructor that sets all fields.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Equality based on propertyNames, maxFeatures, filter, typeName and version.
 org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateSystem()
          getCoordinateSystem purpose.
 org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateSystemReproject()
          getCoordinateSystemReproject purpose.
 Filter getFilter()
          The Filter can be used to define constraints on a query.
 java.lang.String getHandle()
          The handle attribute is included to allow a client to associate a mnemonic name to the Query request.
 int getMaxFeatures()
          The optional maxFeatures can be used to limit the number of features that a query request retrieves.
 java.net.URI getNamespace()
          The namespace attribute is used to indicate the namespace of the schema being represented.
 java.lang.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.
 java.lang.String getTypeName()
          The typeName attribute is used to indicate the name of the feature type to be queried.
 java.lang.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(org.opengis.referencing.crs.CoordinateReferenceSystem system)
          setCoordinateSystem purpose.
 void setCoordinateSystemReproject(org.opengis.referencing.crs.CoordinateReferenceSystem system)
          setCoordinateSystemReproject purpose.
 void setFilter(Filter filter)
          Sets the filter to constrain the query.
 void setHandle(java.lang.String handle)
          Sets a mnemonic name for the query request.
 void setMaxFeatures(int maxFeatures)
          Sets the max features to retrieved by this query.
 void setPropertyNames(java.util.List propNames)
          Sets the proper attributeTypes constructed from a schema and a list of propertyNames.
 void setPropertyNames(java.lang.String[] propNames)
          Sets the properties to retrieve from the db.
 void setTypeName(java.lang.String typeName)
          Sets the typename.
 java.lang.String toString()
          Over ride of toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultQuery

public DefaultQuery()
No argument constructor.


DefaultQuery

public DefaultQuery(java.lang.String typeName)
Query with typeName.

Parameters:
typeName - the name of the featureType to retrieve

DefaultQuery

public DefaultQuery(java.lang.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(java.lang.String typeName,
                    Filter filter,
                    java.lang.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(java.lang.String typeName,
                    Filter filter,
                    int maxFeatures,
                    java.lang.String[] propNames,
                    java.lang.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(java.lang.String typeName,
                    java.net.URI namespace,
                    Filter filter,
                    int maxFeatures,
                    java.lang.String[] propNames,
                    java.lang.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 java.lang.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(java.lang.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(java.util.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.
Task:
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.

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 java.lang.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 java.net.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(java.lang.String typeName)
Sets the typename.

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

getHandle

public java.lang.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(java.lang.String handle)
Sets a mnemonic name for the query request.

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

getVersion

public java.lang.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.

hashCode

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

Returns:
hascode for filter

equals

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

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

Parameters:
obj - Other object to compare against
Returns:
true if obj matches this filter

toString

public java.lang.String toString()
Over ride of toString

Returns:
a string representation of this query object.

getCoordinateSystem

public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateSystem()
getCoordinateSystem purpose.

Description ...

Specified by:
getCoordinateSystem in interface Query
Returns:

getCoordinateSystemReproject

public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateSystemReproject()
getCoordinateSystemReproject purpose.

Description ...

Specified by:
getCoordinateSystemReproject in interface Query
Returns:

setCoordinateSystem

public void setCoordinateSystem(org.opengis.referencing.crs.CoordinateReferenceSystem system)
setCoordinateSystem purpose.

Description ...

Parameters:
system -

setCoordinateSystemReproject

public void setCoordinateSystemReproject(org.opengis.referencing.crs.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


Copyright © GeoTools. All Rights Reserved.