edu.indiana.iucbrf.casebase
Class CachedRDBCaseBase

java.lang.Object
  extended by edu.indiana.iucbrf.casebase.AbstractCaseBase
      extended by edu.indiana.iucbrf.casebase.AbstractKeyableCaseBase
          extended by edu.indiana.iucbrf.casebase.RDBCaseBase
              extended by edu.indiana.iucbrf.casebase.CachedRDBCaseBase
All Implemented Interfaces:
CaseBase, KeyableCaseBase, SwingRepresentableWithDomain, Multithreaded, SwingRepresentable, java.io.Serializable

public class CachedRDBCaseBase
extends RDBCaseBase
implements Multithreaded

This class uses a relational database to store the case base, but will read and store the entire case base in memory when it is accessed. Content changes to the cache are immediately written through to the database.

The policy regarding synchronization of the cache and database is as follows:
- Upon instantiation, the cache does not exist.

- When a case is added or removed:
if the cache exists, the action occurs on the cache and on the database, immediately.
else the action occurs only on the database immediately.

- When getCase() is called:
if the cache exists, it is accessed and the case is returned.
else the entire database is read into the cache, and the case is returned.

- When getCaseCount() or isEmpty() is called:
if the cache exists, it is accessed to get the requested data.
else the database is accessed to get the requested data.

- When iterator() is called:
if the cache exists, an iterator on it is returned.
else the entire database is read into the cache, and an iterator on the cache is returned.

See Also:
Serialized Form

Field Summary
protected  AbstractKeyableCaseBase cacheCB
           
 
Fields inherited from class edu.indiana.iucbrf.casebase.RDBCaseBase
con, domain, iterator, rdbCaseBaseInfo, stmt
 
Fields inherited from class edu.indiana.iucbrf.casebase.AbstractKeyableCaseBase
markerList
 
Fields inherited from class edu.indiana.iucbrf.casebase.AbstractCaseBase
caseClass, debugMode, DEFAULT_INITIAL_CAPACITY, listeners, prototype
 
Fields inherited from interface edu.indiana.util.swing.SwingRepresentable
TITLE_FONT
 
Constructor Summary
CachedRDBCaseBase(Domain domain, RDBCaseBaseInfo rdbCaseBaseInfo)
          Creates a new instance of CachedRDBCaseBase
CachedRDBCaseBase(Domain domain, RDBCaseBaseInfo rdbCaseBaseInfo, CaseGenerator caseGenerator, int numToGenerate)
           
 
Method Summary
 void addCaseWithKey(Case acase)
          Adds the case with the given key.
 void doThreadedOperation()
           
 Case getCase(long key)
          Get the case with the given key.
 int getCaseCount()
          Gets the number of cases in this case base
 java.util.Iterator iterator()
          Create an iterator on the case base.
protected  void readRDBCaseBaseIntoCache()
          Reads the RDBCaseBase into a FlatCaseBase (in memory).
 boolean removeCase(long key)
          Remove the case with the given key.
protected  boolean removeCaseImpl(Case c)
          Completes the task of removing a case, begun by removeCase().
protected  void setAllCaseShellsIntoCache()
          Creates and places the case shells into the cacheCB.
protected  void setAllInactiveContextsIntoCache()
           
protected  void setAllProblemsAndSolutionsIntoCache()
           
 void setDoneWithThreadedOperation(boolean doneWithThreadedOperation)
           
 java.lang.String toString()
          Convert this case base into a String representation.
protected  void waitForCacheLoad()
           
 
Methods inherited from class edu.indiana.iucbrf.casebase.RDBCaseBase
addInactiveContextsToTable, addProblemToTable, addSolutionToTable, close, ensureCapacity, finalize, getBasicCaseInfoGivenKey, getInactiveContextsGivenKey, getProblemAndSolutionGivenKey, initializeCB, initializeCB, makeCaseShellFromResultSet, removeCase
 
Methods inherited from class edu.indiana.iucbrf.casebase.AbstractKeyableCaseBase
addCaseImpl, getMarkerKeys, getNextCaseKey
 
Methods inherited from class edu.indiana.iucbrf.casebase.AbstractCaseBase
addCase, addCaseBaseListener, addCases, addCases, addCases, buildCaseJList, checkCaseType, classMemberIterator, clearAllEstimates, fireCaseAdded, fireCaseClassChanged, fireCaseRemoved, fireCaseReplaced, fireCasesCleared, getCaseClass, getCasesMatching, getDomain, getPrototype, isEmpty, removeCase, removeCaseBaseListener, setBaseFileName, setCaseClass, setDebugMode, setDomain, toSwing, toSwing, toVerboseString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.indiana.iucbrf.casebase.CaseBase
addCase, addCaseBaseListener, addCases, addCases, addCases, clearAllEstimates, getCaseClass, getCasesMatching, getDomain, isEmpty, removeCase, removeCaseBaseListener, setBaseFileName, setCaseClass, setDomain, toVerboseString
 
Methods inherited from interface edu.indiana.iucbrf.util.SwingRepresentableWithDomain
toSwing
 
Methods inherited from interface edu.indiana.util.swing.SwingRepresentable
toSwing
 

Field Detail

cacheCB

protected AbstractKeyableCaseBase cacheCB
Constructor Detail

CachedRDBCaseBase

public CachedRDBCaseBase(Domain domain,
                         RDBCaseBaseInfo rdbCaseBaseInfo)
Creates a new instance of CachedRDBCaseBase


CachedRDBCaseBase

public CachedRDBCaseBase(Domain domain,
                         RDBCaseBaseInfo rdbCaseBaseInfo,
                         CaseGenerator caseGenerator,
                         int numToGenerate)
Method Detail

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

addCaseWithKey

public void addCaseWithKey(Case acase)
Adds the case with the given key.

Specified by:
addCaseWithKey in interface KeyableCaseBase
Overrides:
addCaseWithKey in class RDBCaseBase
Parameters:
acase - a Case

getCase

public Case getCase(long key)
Get the case with the given key.

Specified by:
getCase in interface KeyableCaseBase
Overrides:
getCase in class RDBCaseBase
Parameters:
key - The key of the case to be retrieved.
Returns:
The retrieved case, or null if none with that key was found.

getCaseCount

public int getCaseCount()
Gets the number of cases in this case base

Specified by:
getCaseCount in interface CaseBase
Overrides:
getCaseCount in class RDBCaseBase

toString

public java.lang.String toString()
Convert this case base into a String representation.

Specified by:
toString in interface CaseBase
Overrides:
toString in class RDBCaseBase

removeCaseImpl

protected boolean removeCaseImpl(Case c)
Completes the task of removing a case, begun by removeCase().

Overrides:
removeCaseImpl in class RDBCaseBase

removeCase

public boolean removeCase(long key)
Description copied from interface: KeyableCaseBase
Remove the case with the given key.

Specified by:
removeCase in interface KeyableCaseBase
Overrides:
removeCase in class RDBCaseBase
Parameters:
key - The key of the case to be removed.
Returns:
true if case was found and removed, false otherwise.

iterator

public java.util.Iterator iterator()
Create an iterator on the case base. This method simply throws an UnsupportedOperationException, and must be overridden if needed in case base implementations.

Specified by:
iterator in interface CaseBase
Overrides:
iterator in class RDBCaseBase

readRDBCaseBaseIntoCache

protected void readRDBCaseBaseIntoCache()
Reads the RDBCaseBase into a FlatCaseBase (in memory).


setAllCaseShellsIntoCache

protected void setAllCaseShellsIntoCache()
Creates and places the case shells into the cacheCB.


setAllProblemsAndSolutionsIntoCache

protected void setAllProblemsAndSolutionsIntoCache()

setAllInactiveContextsIntoCache

protected void setAllInactiveContextsIntoCache()