edu.indiana.iucbrf.casebase
Class RDBCaseBase

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

public class RDBCaseBase
extends AbstractKeyableCaseBase

A RDBCaseBase stores a list of cases in a relational database and uses SQL queries to read them back into memory.

See Also:
Serialized Form

Field Summary
protected  java.sql.Connection con
           
protected  Domain domain
           
protected  java.util.Iterator iterator
           
protected  RDBCaseBaseInfo rdbCaseBaseInfo
           
protected  java.sql.Statement 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
RDBCaseBase(Domain domain, RDBCaseBaseInfo rdbCaseBaseInfo)
          Constructor
RDBCaseBase(Domain domain, RDBCaseBaseInfo rdbCaseBaseInfo, CaseGenerator caseGenerator, int numToGenerate)
          Constructor
 
Method Summary
 void addCaseWithKey(Case acase)
          Adds the case with the given key.
protected  void addInactiveContextsToTable(java.util.HashSet inactiveContexts, int inactiveContextsKey)
          Adds the inactive contexts to the inactiveContextable
protected  void addProblemToTable(Problem p, int problemKey)
          Adds the problem features to the problemtable
protected  void addSolutionToTable(Solution s, int solutionKey)
          Adds the solution features to the solutiontable
 void close()
          This method closes the connection to the database in which the casebase is stored
 void ensureCapacity(int minimumCapacity)
          Method ensureCapacity
protected  void finalize()
          Used to close the casebase when a RDBCaseBase object is garbage collected.
protected  Case getBasicCaseInfoGivenKey(int key)
           
 Case getCase(long key)
          Get the case with the given key.
 int getCaseCount()
          Gets the number of cases in this case base
protected  java.util.HashSet getInactiveContextsGivenKey(int inactiveContextsKey)
          Reads the inactive contexts for a given solution key and construtcs a HashSet out of it.
protected  Featured[] getProblemAndSolutionGivenKey(int key)
           
protected  void initializeCB(Domain domain, RDBCaseBaseInfo rdbCaseBaseInfo)
          Method initializeCB
protected  void initializeCB(int minCapacity)
          Method initializeCB
 java.util.Iterator iterator()
          Create an iterator on the case base.
protected  Case makeCaseShellFromResultSet(java.sql.ResultSet caseBaseTableRS)
           
 boolean removeCase(long key)
          Remove the case with the given key.
protected  boolean removeCase(long key, boolean fireCaseRemoved)
          Remove the case with the given key.
protected  boolean removeCaseImpl(Case c)
          Completes the task of removing a case, begun by removeCase().
 java.lang.String toString()
          Convert this case base into a String representation.
 
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

stmt

protected java.sql.Statement stmt

con

protected java.sql.Connection con

iterator

protected java.util.Iterator iterator

domain

protected Domain domain

rdbCaseBaseInfo

protected RDBCaseBaseInfo rdbCaseBaseInfo
Constructor Detail

RDBCaseBase

public RDBCaseBase(Domain domain,
                   RDBCaseBaseInfo rdbCaseBaseInfo)
Constructor

Parameters:
domain - a Domain
rdbCaseBaseInfo - a RDBCaseBaseInfo

RDBCaseBase

public RDBCaseBase(Domain domain,
                   RDBCaseBaseInfo rdbCaseBaseInfo,
                   CaseGenerator caseGenerator,
                   int numToGenerate)
Constructor

Parameters:
domain - a Domain
rdbCaseBaseInfo - a RDBCaseBaseInfo
caseGenerator - a CaseGenerator
numToGenerate - an int
Method Detail

finalize

protected void finalize()
Used to close the casebase when a RDBCaseBase object is garbage collected.

Overrides:
finalize in class java.lang.Object

close

public void close()
This method closes the connection to the database in which the casebase is stored

Specified by:
close in interface CaseBase
Overrides:
close in class AbstractCaseBase

addCaseWithKey

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

Parameters:
acase - a Case

ensureCapacity

public void ensureCapacity(int minimumCapacity)
Method ensureCapacity

Specified by:
ensureCapacity in interface CaseBase
Specified by:
ensureCapacity in class AbstractCaseBase
Parameters:
minimumCapacity - an int

getCase

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

Parameters:
key - The key of the case to be retrieved.
Returns:
The retrieved case, or null if none with that key was found.

getBasicCaseInfoGivenKey

protected Case getBasicCaseInfoGivenKey(int key)

makeCaseShellFromResultSet

protected Case makeCaseShellFromResultSet(java.sql.ResultSet caseBaseTableRS)

getProblemAndSolutionGivenKey

protected Featured[] getProblemAndSolutionGivenKey(int key)

getInactiveContextsGivenKey

protected java.util.HashSet getInactiveContextsGivenKey(int inactiveContextsKey)
Reads the inactive contexts for a given solution key and construtcs a HashSet out of it. This method must be avoided to use the RDBHashSet class to store and read the inactivecontext hashset.

Parameters:
inactiveContextsKey - an int
Returns:
a HashSet

addProblemToTable

protected void addProblemToTable(Problem p,
                                 int problemKey)
Adds the problem features to the problemtable

Parameters:
p - a Problem
problemKey - an int

addSolutionToTable

protected void addSolutionToTable(Solution s,
                                  int solutionKey)
Adds the solution features to the solutiontable

Parameters:
s - a Solution
solutionKey - an int

addInactiveContextsToTable

protected void addInactiveContextsToTable(java.util.HashSet inactiveContexts,
                                          int inactiveContextsKey)
Adds the inactive contexts to the inactiveContextable

Parameters:
inactiveContexts - a HashSet
inactiveContextsKey - an int

getCaseCount

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


toString

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

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

removeCaseImpl

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

Overrides:
removeCaseImpl in class AbstractKeyableCaseBase

removeCase

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

Parameters:
key - The key of the case to be removed.
Returns:
true if case was found and removed, false otherwise.

removeCase

protected boolean removeCase(long key,
                             boolean fireCaseRemoved)
Remove the case with the given key.

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
Specified by:
iterator in class AbstractCaseBase

initializeCB

protected void initializeCB(Domain domain,
                            RDBCaseBaseInfo rdbCaseBaseInfo)
Method initializeCB

Parameters:
initialCapacity - an int

initializeCB

protected void initializeCB(int minCapacity)
Method initializeCB

Specified by:
initializeCB in class AbstractCaseBase
Parameters:
minCapacity - an int