org.geotools.data.store
Class ContentState

Object
  extended by ContentState

public class ContentState
extends Object

The state of an entry in a datastore, maintained on a per-transaction basis.

State is maintained on a per transaction basis (see ContentEntry}. State maintained includes cached values such as:

Other types of state depend on the data format. For instance, a jdbc database backed format would probably want to store a database connection as state.

This class is a "data object" and is not thread safe. It is up to clients of this class to ensure that values are set in a thread-safe / synchronized manner. For example:

   
   ContentState state = ...;
   
   //get the count
   int count = state.getCount();
   if ( count == -1 ) {
     synchronized ( state ) {
       count = calculateCount();
       state.setCount( count );
     }
   }
   
 

This class may be extended. Subclasses may extend (not override) the following methods:

Subclasses should also override copy().

Author:
Jody Garnett, Refractions Research Inc., Justin Deoliveira, The Open Planning Project

Field Summary
protected  BatchFeatureEvent batchFeatureEvent
          Even used for batch notification; used to collect the bounds and feature ids generated over the course of a transaction.
protected  ReferencedEnvelope bounds
          cached bounds of features
protected  int count
          cached number of features
protected  ContentEntry entry
          entry maintaining the state
protected  SimpleFeatureType featureType
          cached feature type
protected  List<FeatureListener> listeners
          observers
protected  Transaction tx
          Transaction the state works from.
 
Constructor Summary
  ContentState(ContentEntry entry)
          Creates a new state.
protected ContentState(ContentState state)
          Creates a new state from a previous one.
 
Method Summary
 void addListener(FeatureListener listener)
          Adds a listener for collection events.
 void close()
          Clears all state.
 ContentState copy()
          Copies the state.
 void fireBatchFeatureEvent(boolean isCommit)
          Notifies all waiting listeners that a commit has been issued; this notification is also sent to our
 void fireFeatureAdded(FeatureSource<?,?> source, Feature feature)
          Used to issue a Type.ADDED FeatureEvent indicating a new feature being created
 void fireFeatureEvent(FeatureEvent event)
          Used to issue a single FeatureEvent.
 void fireFeatureRemoved(FeatureSource<?,?> source, Feature feature)
           
 void fireFeatureUpdated(FeatureSource<?,?> source, Feature feature, ReferencedEnvelope before)
           
 void flush()
          Clears cached state.
 ReferencedEnvelope getBounds()
          The cached spatial extent.
 int getCount()
          The cached number of features.
 ContentEntry getEntry()
          The entry which maintains the state.
 SimpleFeatureType getFeatureType()
          The cached feature type.
 Transaction getTransaction()
          The transaction associated with the state.
 boolean hasListener()
          Used to quickly test if any listeners are available.
 void removeListener(FeatureListener listener)
          Removes a listener for collection events.
 void setBounds(ReferencedEnvelope bounds)
          Sets the cached spatial extent.
 void setCount(int count)
          Sets the cached number of features.
 void setFeatureType(SimpleFeatureType featureType)
          Sets the cached feature type.
 void setTransaction(Transaction tx)
          Sets the transaction associatred with the state.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tx

protected Transaction tx
Transaction the state works from.


featureType

protected SimpleFeatureType featureType
cached feature type


count

protected int count
cached number of features


bounds

protected ReferencedEnvelope bounds
cached bounds of features


entry

protected ContentEntry entry
entry maintaining the state


batchFeatureEvent

protected BatchFeatureEvent batchFeatureEvent
Even used for batch notification; used to collect the bounds and feature ids generated over the course of a transaction.


listeners

protected List<FeatureListener> listeners
observers

Constructor Detail

ContentState

public ContentState(ContentEntry entry)
Creates a new state.

Parameters:
entry - The entry for the state.

ContentState

protected ContentState(ContentState state)
Creates a new state from a previous one.

All state from the specified state is copied. Therefore subclasses extending this constructor should clone all mutable objects.

Parameters:
state - The existing state.
Method Detail

getEntry

public ContentEntry getEntry()
The entry which maintains the state.


getTransaction

public Transaction getTransaction()
The transaction associated with the state.


setTransaction

public void setTransaction(Transaction tx)
Sets the transaction associatred with the state.


getFeatureType

public final SimpleFeatureType getFeatureType()
The cached feature type.


setFeatureType

public final void setFeatureType(SimpleFeatureType featureType)
Sets the cached feature type.


getCount

public final int getCount()
The cached number of features.


setCount

public final void setCount(int count)
Sets the cached number of features.


getBounds

public final ReferencedEnvelope getBounds()
The cached spatial extent.


setBounds

public final void setBounds(ReferencedEnvelope bounds)
Sets the cached spatial extent.


addListener

public final void addListener(FeatureListener listener)
Adds a listener for collection events.

Parameters:
listener - The listener to add

removeListener

public final void removeListener(FeatureListener listener)
Removes a listener for collection events.

Parameters:
listener - The listener to remove

hasListener

public final boolean hasListener()
Used to quickly test if any listeners are available.

Returns:

fireFeatureUpdated

public void fireFeatureUpdated(FeatureSource<?,?> source,
                               Feature feature,
                               ReferencedEnvelope before)

fireFeatureAdded

public final void fireFeatureAdded(FeatureSource<?,?> source,
                                   Feature feature)
Used to issue a Type.ADDED FeatureEvent indicating a new feature being created

Parameters:
source -
feature -

fireFeatureRemoved

public void fireFeatureRemoved(FeatureSource<?,?> source,
                               Feature feature)

fireFeatureEvent

public final void fireFeatureEvent(FeatureEvent event)
Used to issue a single FeatureEvent.

If this content state is used for Transaction.AUTO_COMMIT the notification will be passed to all interested parties.

If not this event will be recored as part of a BatchFeatureEvent that will to be issued using issueBatchFeatureEvent()

Parameters:
event -

fireBatchFeatureEvent

public final void fireBatchFeatureEvent(boolean isCommit)
Notifies all waiting listeners that a commit has been issued; this notification is also sent to our


flush

public void flush()
Clears cached state.

This method does not affect any non-cached state. This method may be extended by subclasses, but not overiden.


close

public void close()
Clears all state.

Any resources that the state holds onto (like a database connection) should be closed or disposes when this method is called. This method may be extended by subclasses, but not overiden.


copy

public ContentState copy()
Copies the state.

Subclasses shold override this method. Any mutable state objects should be cloned.

Returns:
A copy of the state.


Copyright © 1996-2009 Geotools. All Rights Reserved.