public class ContentState extends Object
ContentEntry
.
The default ContentState implementation maintains cached values on a per transaction basis:
getFeatureType()
getCount()
getBounds()
This class is a "data object" used to store values 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 );
}
}
You may also make use of ContentFeatureSource.canEvent()
value of false
allowing
the base ContentFeatureStore class to take responsibility for sending event notifications.
The default ContentState implementation also supports the handling of ContentFeatureSource#canTransaction
value of false
. The implementation asks ContentState
to store a Diff
which is used to record any modifications made until commit is called.
Internally a Transaction.State
is used to notify the implementation of {Transaction.commit()
and Transaction.rollback()
.
Subclasses may extend (not override) the following methods:
Subclasses should also overridecopy()
to ensure any additional state they are keeping
is correctly accounted for.Modifier and Type | Field and Description |
---|---|
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 DiffTransactionState |
transactionState
Callback used to issue batch feature events when commit/rollback issued on the transaction.
|
protected Transaction |
tx
Transaction the state works from.
|
Modifier | Constructor and Description |
---|---|
|
ContentState(ContentEntry entry)
Creates a new state.
|
protected |
ContentState(ContentState state)
Creates a new state from a previous one.
|
Modifier and Type | Method and Description |
---|---|
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)
Creates a FeatureEvent indicating that the provided feature has been changed.
|
void |
flush()
Clears cached state.
|
BatchFeatureEvent |
getBatchFeatureEvent() |
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 associated with the state.
|
protected Transaction tx
protected ContentEntry entry
protected SimpleFeatureType featureType
protected int count
protected ReferencedEnvelope bounds
protected BatchFeatureEvent batchFeatureEvent
protected List<FeatureListener> listeners
protected DiffTransactionState transactionState
public ContentState(ContentEntry entry)
entry
- The entry for the state.protected ContentState(ContentState state)
All state from the specified state is copied. Therefore subclasses extending this constructor should clone all mutable objects.
state
- The existing state.public ContentEntry getEntry()
public Transaction getTransaction()
public void setTransaction(Transaction tx)
public final SimpleFeatureType getFeatureType()
public final void setFeatureType(SimpleFeatureType featureType)
public final int getCount()
public final void setCount(int count)
public final ReferencedEnvelope getBounds()
public final void setBounds(ReferencedEnvelope bounds)
public final void addListener(FeatureListener listener)
listener
- The listener to addpublic final void removeListener(FeatureListener listener)
listener
- The listener to removepublic BatchFeatureEvent getBatchFeatureEvent()
public final boolean hasListener()
public void fireFeatureUpdated(FeatureSource<?,?> source, Feature feature, ReferencedEnvelope before)
This method is provided to simplify event notification for implementors by constructing a
FeatureEvent internally (and then only if listeners are interested). You may find it easier
to construct your own FeatureEvent using {hasListener()
to check if you need to fire
events at all.
source
- FeatureSource responsible for the changefeature
- The updated featurebefore
- the bounds of the feature before the changepublic final void fireFeatureAdded(FeatureSource<?,?> source, Feature feature)
source
- feature
- public void fireFeatureRemoved(FeatureSource<?,?> source, Feature feature)
public final void fireFeatureEvent(FeatureEvent event)
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()
event
- public final void fireBatchFeatureEvent(boolean isCommit)
public void flush()
This method does not affect any non-cached state. This method may be extended by subclasses, but not overiden.
public void close()
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.
public ContentState copy()
Subclasses should override this method. Any mutable state objects should be cloned.
Copyright © 1996–2019 Geotools. All rights reserved.