edu.indiana.iucbrf.feature.featurespec
Class FeatureSpecRDB

java.lang.Object
  extended by edu.indiana.iucbrf.feature.featurespec.AbstractFeatureSpecCollection
      extended by edu.indiana.iucbrf.feature.featurespec.FeatureSpecRDB
All Implemented Interfaces:
FeatureSpecCollection, Multithreaded, SwingRepresentable, XMLRepresentable, java.io.Serializable
Direct Known Subclasses:
CCBRFeatureSpecRDB

public class FeatureSpecRDB
extends AbstractFeatureSpecCollection
implements Multithreaded

This class can be used to store a set of feature specs into a relational database.

See Also:
Serialized Form

Field Summary
protected  FeatureSpecMap cacheMap
           
protected  java.sql.Connection con
           
protected  Domain domain
           
protected  FeatureSpecRDBInfo featureSpecRDBInfo
           
protected  java.util.Iterator iterator
           
protected  java.sql.Statement stmt
           
 
Fields inherited from class edu.indiana.iucbrf.feature.featurespec.AbstractFeatureSpecCollection
title
 
Fields inherited from interface edu.indiana.util.swing.SwingRepresentable
TITLE_FONT
 
Constructor Summary
protected FeatureSpecRDB()
          For serialization - do not call explicitly
  FeatureSpecRDB(Domain domain, FeatureSpecRDBInfo featureSpecRDBInfo)
          Constructor
  FeatureSpecRDB(Domain domain, FeatureSpecRDBInfo featureSpecRDBInfo, FeatureKey[] featureKeys, java.lang.String[] featureDescriptions, java.lang.String[] featureTypeNames)
          Constructor
 
Method Summary
 void addFeatureSpec(FeatureSpec featureSpec)
          Adds a featurespec to a database
 void doThreadedOperation()
           
protected  void finalize()
          Used to close the connections made by an instance of a FeatureSpecRDB is garbage collected.
 FeatureSpecMap getCacheMap()
           
 FeatureSpec getFeatureSpec(FeatureKey key)
          Reads the featurespec given by the featurekey from the database and returns and constructs a FeatureSpec out of it
 int getFeatureSpecCount()
          returns the number of featurespec currently stored in the database
 FeatureSpecRDBInfo getFeatureSpecRDBInfo()
          Method getFeatureSpecRDBInfo
protected  void handleCacheGetFeatureSpecMiss(FeatureSpec featureSpec)
          Caches a featurespec that has been read from a database
 void loadAllIntoCacheInSeparateThread()
          Should be called by the user if the specs should be loaded in all at once into the cache, rather than simply on demand.
 java.util.Iterator orderedAllEntryIterator()
          Method orderedAllEntryIterator
 FeatureKey[] orderedAllKeyArray()
          Method orderedAllKeyArray
 java.util.Iterator orderedAllKeyIterator()
          returns an iterator on all keys: printable or unprintable, sub feature or full feature
 java.util.Iterator orderedAllSpecIterator()
          Method orderedAllSpecIterator
protected  void readFeatureSpecRDBIntoCache()
          Ordinarily, feature specs are cached "on demand" by this class.
 FeatureSpec readSingleFeatureSpecFromDB(FeatureKey key)
           
 void removeFeatureSpec(FeatureKey key)
          removes a featurespec from the database
protected  void setAllConstructorArgsIntoCache()
          Reads the classnames from the class table, to fill in this detail of the specs in the cacheMap.
protected  void setAllExtraDataIntoCache()
          Reads the key and value for all extra data, to fill in this detail of the specs in the cacheMap.
protected  void setAllFeatureSpecShellsIntoCache()
          Reads name, description, classType, featureKey, format, isPrintable, isSubFeatureOf, and Extradata from primary feature spec table for this collection.
 void setDoneWithThreadedOperation(boolean doneWithThreadedOperation)
           
 void setFormat(FeatureKey featureKey, FeatureValueFormat format)
           
protected  void waitForCacheLoad()
           
 
Methods inherited from class edu.indiana.iucbrf.feature.featurespec.AbstractFeatureSpecCollection
equals, fromXML, getTitle, isFullyCompliant, isPartiallyCompliant, putExtraData, removeFeatureSpec, setDescription, setIsPrintable, setIsSubFeature, setName, setStandardConstructor, setStandardConstructor, setStandardConstructor, setTitle, setType, toString, toSwing, toXML
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

iterator

protected java.util.Iterator iterator

stmt

protected java.sql.Statement stmt

con

protected java.sql.Connection con

domain

protected Domain domain

featureSpecRDBInfo

protected FeatureSpecRDBInfo featureSpecRDBInfo

cacheMap

protected FeatureSpecMap cacheMap
Constructor Detail

FeatureSpecRDB

protected FeatureSpecRDB()
For serialization - do not call explicitly


FeatureSpecRDB

public FeatureSpecRDB(Domain domain,
                      FeatureSpecRDBInfo featureSpecRDBInfo)
Constructor

Parameters:
domain - a Domain
featureSpecRDBInfo - a FeatureSpecRDBInfo

FeatureSpecRDB

public FeatureSpecRDB(Domain domain,
                      FeatureSpecRDBInfo featureSpecRDBInfo,
                      FeatureKey[] featureKeys,
                      java.lang.String[] featureDescriptions,
                      java.lang.String[] featureTypeNames)
Constructor

Parameters:
domain - a Domain
featureSpecRDBInfo - a FeatureSpecRDBInfo
featureKeys - a FeatureKey[]
featureDescriptions - a String[]
featureTypeNames - a String[]
Method Detail

finalize

protected void finalize()
Used to close the connections made by an instance of a FeatureSpecRDB is garbage collected.

Overrides:
finalize in class java.lang.Object

loadAllIntoCacheInSeparateThread

public void loadAllIntoCacheInSeparateThread()
Should be called by the user if the specs should be loaded in all at once into the cache, rather than simply on demand.


waitForCacheLoad

protected void waitForCacheLoad()

setDoneWithThreadedOperation

public void setDoneWithThreadedOperation(boolean doneWithThreadedOperation)
Specified by:
setDoneWithThreadedOperation in interface Multithreaded

doThreadedOperation

public void doThreadedOperation()
Specified by:
doThreadedOperation in interface Multithreaded

readFeatureSpecRDBIntoCache

protected void readFeatureSpecRDBIntoCache()
Ordinarily, feature specs are cached "on demand" by this class. However, this method will fill the cache with all available feature specs, so that there will not be a cache miss when those specs are requested.


setAllFeatureSpecShellsIntoCache

protected void setAllFeatureSpecShellsIntoCache()
Reads name, description, classType, featureKey, format, isPrintable, isSubFeatureOf, and Extradata from primary feature spec table for this collection. This data is used to populate the cacheMap.


setAllConstructorArgsIntoCache

protected void setAllConstructorArgsIntoCache()
Reads the classnames from the class table, to fill in this detail of the specs in the cacheMap. Warning: This method does assume that the rows returned in readAllRowsOfTable will be in the order required as arguments for the constructors.


setAllExtraDataIntoCache

protected void setAllExtraDataIntoCache()
Reads the key and value for all extra data, to fill in this detail of the specs in the cacheMap.


getFeatureSpecRDBInfo

public FeatureSpecRDBInfo getFeatureSpecRDBInfo()
Method getFeatureSpecRDBInfo

Returns:
a FeatureSpecRDBInfo

getFeatureSpecCount

public int getFeatureSpecCount()
returns the number of featurespec currently stored in the database

Specified by:
getFeatureSpecCount in interface FeatureSpecCollection
Returns:
an int

getFeatureSpec

public FeatureSpec getFeatureSpec(FeatureKey key)
Reads the featurespec given by the featurekey from the database and returns and constructs a FeatureSpec out of it

Specified by:
getFeatureSpec in interface FeatureSpecCollection
Parameters:
key - a FeatureKey
Returns:
a FeatureSpec

readSingleFeatureSpecFromDB

public FeatureSpec readSingleFeatureSpecFromDB(FeatureKey key)

getCacheMap

public FeatureSpecMap getCacheMap()

handleCacheGetFeatureSpecMiss

protected void handleCacheGetFeatureSpecMiss(FeatureSpec featureSpec)
Caches a featurespec that has been read from a database

Parameters:
featureSpec - a FeatureSpec

addFeatureSpec

public void addFeatureSpec(FeatureSpec featureSpec)
Adds a featurespec to a database

Specified by:
addFeatureSpec in interface FeatureSpecCollection
Parameters:
featureSpec - a FeatureSpec

removeFeatureSpec

public void removeFeatureSpec(FeatureKey key)
removes a featurespec from the database

Specified by:
removeFeatureSpec in interface FeatureSpecCollection
Parameters:
featureSpec - a FeatureSpec

setFormat

public void setFormat(FeatureKey featureKey,
                      FeatureValueFormat format)
Specified by:
setFormat in interface FeatureSpecCollection
Overrides:
setFormat in class AbstractFeatureSpecCollection

orderedAllKeyIterator

public java.util.Iterator orderedAllKeyIterator()
returns an iterator on all keys: printable or unprintable, sub feature or full feature

Specified by:
orderedAllKeyIterator in interface FeatureSpecCollection
Returns:
an Iterator

orderedAllEntryIterator

public java.util.Iterator orderedAllEntryIterator()
Method orderedAllEntryIterator

Specified by:
orderedAllEntryIterator in interface FeatureSpecCollection
Returns:
an Iterator

orderedAllSpecIterator

public java.util.Iterator orderedAllSpecIterator()
Method orderedAllSpecIterator

Specified by:
orderedAllSpecIterator in interface FeatureSpecCollection
Returns:
an Iterator

orderedAllKeyArray

public FeatureKey[] orderedAllKeyArray()
Method orderedAllKeyArray

Specified by:
orderedAllKeyArray in interface FeatureSpecCollection
Returns:
a FeatureKey[]