proai.cache
Class RCDatabase

java.lang.Object
  extended by proai.cache.RCDatabase

public class RCDatabase
extends java.lang.Object

Java interface to the database.


Field Summary
static java.lang.String RCADMIN_TABLE_IS_EMPTY
           
 
Constructor Summary
RCDatabase(java.sql.Connection conn, DDLConverter ddlc, boolean mySQLTrickling, boolean backslashIsEscape, boolean pollingEnabled, RCDisk rcDisk)
           
 
Method Summary
 void addFailure(java.sql.Connection conn, java.lang.String identifier, java.lang.String mdPrefix, java.lang.String sourceInfo, java.lang.String failDate, java.lang.String failReason)
           
 void deleteFormat(java.sql.Connection conn, java.lang.String prefix)
           
 void deletePrunables(java.sql.Connection conn, int[] keys, int num)
          Delete one or more items from the prunable list, by database key.
 void deleteSet(java.sql.Connection conn, java.lang.String setSpec)
           
 int dumpPrunables(java.sql.Connection conn, java.io.PrintWriter writer)
           
 void dumpQueue(java.sql.Connection conn, java.io.PrintWriter writer)
           
 CloseableIterator<java.lang.String[]> findRecordInfo(java.sql.Connection conn, java.util.Date from, java.util.Date until, java.lang.String prefix, java.lang.String set)
           
 long getEarliestPollDate(java.sql.Connection conn)
           
 int getFailCount(java.sql.Connection conn, java.lang.String identifier, java.lang.String mdPrefix)
           
 java.util.Map<java.lang.String,java.lang.Integer> getFormatKeyMap(java.sql.Connection conn)
          Get a map of prefix (String) to formatKey (Integer) for all formats in the database.
 java.util.List<CachedMetadataFormat> getFormats(java.sql.Connection conn)
           
 java.util.List<CachedMetadataFormat> getFormats(java.sql.Connection conn, java.lang.String identifier)
           
 java.lang.String getIdentifyPath(java.sql.Connection conn)
          Get the relative path to the Identify.xml file in the cache, or null if identifyPath is null (first update cycle hasn't run).
 long getLastPollDate(java.sql.Connection conn, java.lang.String mdPrefix)
           
 long getLongValue(java.sql.Connection conn, java.lang.String query)
          Execute the given query and return the long value in the first column of the first row of the ResultSet, or zero if there are no results.
 int getPrunableCount(java.sql.Connection conn)
           
 int getQueueSize(java.sql.Connection conn)
           
 java.lang.String[] getRecordInfo(java.sql.Connection conn, java.lang.String itemID, java.lang.String mdPrefix)
           
 java.util.List<SetInfo> getSetInfo(java.sql.Connection conn)
           
 java.util.List<java.lang.String[]> getSetInfoPaths(java.sql.Connection conn)
           
 boolean isPollingEnabled(java.sql.Connection conn)
           
 boolean itemExists(java.sql.Connection conn, java.lang.String itemID)
           
 void putFormat(java.sql.Connection conn, MetadataFormat format)
          Add or modify the given format.
 void putRecord(java.sql.Connection conn, ParsedRecord rec, java.util.Map<java.lang.String,java.lang.Integer> formatKeyMap)
          Add or update a record.
 void putSetInfo(java.sql.Connection conn, java.lang.String setSpec, java.lang.String xmlPath)
           
 void queueFailedRecords(java.sql.Connection conn, int maxFailedRetries)
          Copy all qualifying records from rcFailure to rcQueue.
 void queueRemoteRecord(java.sql.Connection conn, java.lang.String identifier, java.lang.String mdPrefix, java.lang.String sourceInfo)
           
 void removeFailure(java.sql.Connection conn, java.lang.String identifier, java.lang.String mdPrefix)
           
 void removeFromQueue(java.sql.Connection conn, int queueKey)
           
 void setIdentifyPath(java.sql.Connection conn, java.lang.String path)
           
 void setLastPollDate(java.sql.Connection conn, java.lang.String mdPrefix, long lastPollDate)
           
 void setPollingEnabled(java.sql.Connection conn, boolean pollingEnabled)
           
 void setUncommittedRecordDates(java.sql.Connection conn, java.util.Date newDate)
           
 void updateFailure(java.sql.Connection conn, java.lang.String identifier, java.lang.String mdPrefix, java.lang.String sourceInfo, int newFailCount, java.lang.String failDate, java.lang.String failReason)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RCADMIN_TABLE_IS_EMPTY

public static final java.lang.String RCADMIN_TABLE_IS_EMPTY
See Also:
Constant Field Values
Constructor Detail

RCDatabase

public RCDatabase(java.sql.Connection conn,
                  DDLConverter ddlc,
                  boolean mySQLTrickling,
                  boolean backslashIsEscape,
                  boolean pollingEnabled,
                  RCDisk rcDisk)
           throws ServerException
Throws:
ServerException
Method Detail

getIdentifyPath

public java.lang.String getIdentifyPath(java.sql.Connection conn)
                                 throws ServerException
Get the relative path to the Identify.xml file in the cache, or null if identifyPath is null (first update cycle hasn't run).

Throws:
ServerException

setIdentifyPath

public void setIdentifyPath(java.sql.Connection conn,
                            java.lang.String path)
                     throws ServerException
Throws:
ServerException

setPollingEnabled

public void setPollingEnabled(java.sql.Connection conn,
                              boolean pollingEnabled)
                       throws ServerException
Throws:
ServerException

isPollingEnabled

public boolean isPollingEnabled(java.sql.Connection conn)
                         throws ServerException
Throws:
ServerException

putFormat

public void putFormat(java.sql.Connection conn,
                      MetadataFormat format)
               throws ServerException
Add or modify the given format.

Throws:
ServerException

getEarliestPollDate

public long getEarliestPollDate(java.sql.Connection conn)
                         throws ServerException
Throws:
ServerException

getLastPollDate

public long getLastPollDate(java.sql.Connection conn,
                            java.lang.String mdPrefix)
                     throws ServerException
Throws:
ServerException

setLastPollDate

public void setLastPollDate(java.sql.Connection conn,
                            java.lang.String mdPrefix,
                            long lastPollDate)
                     throws ServerException
Throws:
ServerException

getLongValue

public long getLongValue(java.sql.Connection conn,
                         java.lang.String query)
                  throws java.sql.SQLException
Execute the given query and return the long value in the first column of the first row of the ResultSet, or zero if there are no results.

Throws:
java.sql.SQLException

getFormats

public java.util.List<CachedMetadataFormat> getFormats(java.sql.Connection conn)
                                                throws ServerException
Throws:
ServerException

getFormats

public java.util.List<CachedMetadataFormat> getFormats(java.sql.Connection conn,
                                                       java.lang.String identifier)
                                                throws ServerException
Throws:
ServerException

getFormatKeyMap

public java.util.Map<java.lang.String,java.lang.Integer> getFormatKeyMap(java.sql.Connection conn)
                                                                  throws ServerException
Get a map of prefix (String) to formatKey (Integer) for all formats in the database.

Throws:
ServerException

deleteFormat

public void deleteFormat(java.sql.Connection conn,
                         java.lang.String prefix)
                  throws ServerException
Throws:
ServerException

putSetInfo

public void putSetInfo(java.sql.Connection conn,
                       java.lang.String setSpec,
                       java.lang.String xmlPath)
                throws ServerException
Throws:
ServerException

getSetInfo

public java.util.List<SetInfo> getSetInfo(java.sql.Connection conn)
                                   throws ServerException
Throws:
ServerException

getSetInfoPaths

public java.util.List<java.lang.String[]> getSetInfoPaths(java.sql.Connection conn)
                                                   throws ServerException
Throws:
ServerException

deleteSet

public void deleteSet(java.sql.Connection conn,
                      java.lang.String setSpec)
               throws ServerException
Throws:
ServerException

setUncommittedRecordDates

public void setUncommittedRecordDates(java.sql.Connection conn,
                                      java.util.Date newDate)
                               throws ServerException
Throws:
ServerException

putRecord

public void putRecord(java.sql.Connection conn,
                      ParsedRecord rec,
                      java.util.Map<java.lang.String,java.lang.Integer> formatKeyMap)
               throws ServerException
Add or update a record. This will create an rcItem for it if it doesn't exist. NOTE: Records will initially be given a NULL date. After a group of records are updated, the date is set together with setUncommittedRecordDates(..)

Throws:
ServerException

itemExists

public boolean itemExists(java.sql.Connection conn,
                          java.lang.String itemID)
                   throws ServerException
Throws:
ServerException

getRecordInfo

public java.lang.String[] getRecordInfo(java.sql.Connection conn,
                                        java.lang.String itemID,
                                        java.lang.String mdPrefix)
                                 throws ServerException
Throws:
ServerException

findRecordInfo

public CloseableIterator<java.lang.String[]> findRecordInfo(java.sql.Connection conn,
                                                            java.util.Date from,
                                                            java.util.Date until,
                                                            java.lang.String prefix,
                                                            java.lang.String set)
                                                     throws ServerException
Throws:
ServerException

queueFailedRecords

public void queueFailedRecords(java.sql.Connection conn,
                               int maxFailedRetries)
                        throws ServerException
Copy all qualifying records from rcFailure to rcQueue. To avoid unintentional duplicates in the queue, it's important that the caller ensures the queue is processed beforehand.

Throws:
ServerException

queueRemoteRecord

public void queueRemoteRecord(java.sql.Connection conn,
                              java.lang.String identifier,
                              java.lang.String mdPrefix,
                              java.lang.String sourceInfo)
                       throws ServerException
Throws:
ServerException

getQueueSize

public int getQueueSize(java.sql.Connection conn)
                 throws ServerException
Throws:
ServerException

dumpQueue

public void dumpQueue(java.sql.Connection conn,
                      java.io.PrintWriter writer)
               throws ServerException
Throws:
ServerException

removeFromQueue

public void removeFromQueue(java.sql.Connection conn,
                            int queueKey)
                     throws ServerException
Throws:
ServerException

removeFailure

public void removeFailure(java.sql.Connection conn,
                          java.lang.String identifier,
                          java.lang.String mdPrefix)
                   throws ServerException
Throws:
ServerException

getFailCount

public int getFailCount(java.sql.Connection conn,
                        java.lang.String identifier,
                        java.lang.String mdPrefix)

addFailure

public void addFailure(java.sql.Connection conn,
                       java.lang.String identifier,
                       java.lang.String mdPrefix,
                       java.lang.String sourceInfo,
                       java.lang.String failDate,
                       java.lang.String failReason)
                throws ServerException
Throws:
ServerException

updateFailure

public void updateFailure(java.sql.Connection conn,
                          java.lang.String identifier,
                          java.lang.String mdPrefix,
                          java.lang.String sourceInfo,
                          int newFailCount,
                          java.lang.String failDate,
                          java.lang.String failReason)
                   throws ServerException
Throws:
ServerException

getPrunableCount

public int getPrunableCount(java.sql.Connection conn)
                     throws ServerException
Throws:
ServerException

deletePrunables

public void deletePrunables(java.sql.Connection conn,
                            int[] keys,
                            int num)
                     throws java.sql.SQLException
Delete one or more items from the prunable list, by database key.

Throws:
java.sql.SQLException

dumpPrunables

public int dumpPrunables(java.sql.Connection conn,
                         java.io.PrintWriter writer)
                  throws ServerException
Throws:
ServerException