public final class ReplicaCacheDatabase extends Object implements BitPreservationDAO
This method uses the 'admin.data' file for retrieving the upload status.
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
log
The log.
|
static String |
selectForFileChecksumVotingSql
SQL used to select those files whose check status has to be voted on.
|
static String |
updateChecksumStatusSql
SQL used to update the checksum status of straightforward cases.
|
Modifier and Type | Method and Description |
---|---|
void |
addChecksumInformation(File checksumOutputFile,
Replica replica)
Given the output of a checksum job, add the results to the database.
|
void |
addFileListInformation(File filelistFile,
Replica replica)
Method for adding the results from a list of filenames on a replica.
|
void |
changeStateOfReplicafileinfo(String filename,
Replica replica,
ReplicaStoreState state)
Method for inserting an entry into the database about a file upload has begun for a specific replica.
|
void |
changeStateOfReplicafileinfo(String filename,
String checksum,
Replica replica,
ReplicaStoreState state)
Method for inserting an entry into the database about a file upload has begun for a specific replica.
|
void |
cleanup()
Method for cleaning up.
|
boolean |
existsFileInDB(String filename)
Checks whether a file is already in the file table in the database.
|
Replica |
getBitarchiveWithGoodFile(String filename)
Method for finding a replica with a valid version of a file.
|
Replica |
getBitarchiveWithGoodFile(String filename,
Replica badReplica)
Method for finding a replica with a valid version of a file.
|
String |
getChecksum(String filename)
Method for retrieving the checksum for a specific file.
|
Date |
getDateOfLastMissingFilesUpdate(Replica replica)
Get the date for the last file list job.
|
Date |
getDateOfLastWrongFilesUpdate(Replica replica)
Method for retrieving the date for the last update for corrupted files.
|
static ReplicaCacheDatabase |
getInstance()
Method for retrieving the current instance of this class.
|
Iterable<String> |
getMissingFilesInLastUpdate(Replica replica)
Method for retrieving the list of the names of the files which was missing for the replica in the last filelist
update.
|
long |
getNumberOfFiles(Replica replica)
Method for retrieving the number of files within a replica.
|
long |
getNumberOfMissingFilesInLastUpdate(Replica replica)
Method for retrieving the number of files missing from a specific replica.
|
long |
getNumberOfWrongFilesInLastUpdate(Replica replica)
Method for retrieving the amount of files with a incorrect checksum within a replica.
|
ReplicaFileInfo |
getReplicaFileInfo(String filename,
Replica replica)
Method for retrieving the entry in the replicafileinfo table for a given file and replica.
|
ReplicaStoreState |
getReplicaStoreState(String filename,
String replicaId)
Retrieves the ReplicaStoreState for the entry in the replicafileinfo table, which refers to the given file and
replica.
|
Iterable<String> |
getWrongFilesInLastUpdate(Replica replica)
Method for retrieving the list of the files in the replica which have a incorrect checksum.
|
protected void |
initialiseDB(Connection connection)
Method for initialising the database.
|
boolean |
insertAdminEntry(String line)
Method for inserting a line of Admin.Data into the database.
|
void |
insertNewFileForUpload(String filename,
String checksum)
Creates a new entry for the filename for each replica, and give it the given checksum and set the upload_status =
UNKNOWN_UPLOAD_STATUS.
|
boolean |
isEmpty()
Method for telling whether the database is empty.
|
Collection<String> |
retrieveAllFilenames()
Retrieves the names of all the files in the file table of the database.
|
String |
retrieveAsText()
Method to print all the tables in the database.
|
FileListStatus |
retrieveFileListStatus(String filename,
Replica replica)
Method for retrieving the filelist_status for a replicafileinfo entry.
|
Collection<String> |
retrieveFilenamesForReplicaEntries(String replicaId,
ReplicaStoreState state)
Retrieves the names of all the files in the given replica which has the specified UploadStatus.
|
void |
setAdminDate(Date date)
Method for setting a specific value for the filelistdate and the checksumlistdate for all the replicas.
|
void |
setReplicaStoreState(String filename,
String replicaId,
ReplicaStoreState state)
Sets the ReplicaStoreState for the entry in the replicafileinfo table.
|
void |
updateChecksumInformationForFileOnReplica(String filename,
String checksum,
Replica replica)
Method for updating a specific entry in the replicafileinfo table.
|
void |
updateChecksumStatus()
This method is used to update the status for the checksums for all replicafileinfo entries.
|
void |
updateChecksumStatus(String filename)
Method for updating the status for a specific file for all the replicas.
|
protected static final org.slf4j.Logger log
public static final String updateChecksumStatusSql
public static final String selectForFileChecksumVotingSql
public static ReplicaCacheDatabase getInstance()
protected void initialiseDB(Connection connection)
connection
- An open connection to the archive databasepublic ReplicaFileInfo getReplicaFileInfo(String filename, Replica replica) throws ArgumentNotValid
getReplicaFileInfo
in interface BitPreservationDAO
filename
- The name of the file for the entry.replica
- The replica of the entry.ArgumentNotValid
- If the filename is either null or empty, or if the replica is null.public String getChecksum(String filename) throws ArgumentNotValid
filename
- The name of the file, whose checksum are to be found.ArgumentNotValid
- If the filename is either null or the empty string.public Collection<String> retrieveAllFilenames()
public ReplicaStoreState getReplicaStoreState(String filename, String replicaId) throws ArgumentNotValid
filename
- The name of the file in the filetable.replicaId
- The id of the replica.ArgumentNotValid
- If the replicaId or the filename are eihter null or the empty string.public void setReplicaStoreState(String filename, String replicaId, ReplicaStoreState state) throws ArgumentNotValid
filename
- The name of the file in the filetable.replicaId
- The id of the replica.state
- The ReplicaStoreState for the specified entry.ArgumentNotValid
- If the replicaId or the filename are eihter null or the empty string. Or if the
ReplicaStoreState is null.public void insertNewFileForUpload(String filename, String checksum) throws ArgumentNotValid, IllegalState
filename
- The name of the file.checksum
- The checksum of the file.ArgumentNotValid
- If the filename or the checksum is either null or the empty string.IllegalState
- If the file exists with another checksum on one of the replicas. Or if the file has already
been completely uploaded to one of the replicas.public void changeStateOfReplicafileinfo(String filename, Replica replica, ReplicaStoreState state) throws ArgumentNotValid
filename
- The name of the file.replica
- The replica for the replicafileinfo.state
- The new ReplicaStoreState for the entry.ArgumentNotValid
- If the filename is either null or the empty string. Or if the replica or the status is
null.public void changeStateOfReplicafileinfo(String filename, String checksum, Replica replica, ReplicaStoreState state) throws ArgumentNotValid, IllegalState
filename
- The name of the file.checksum
- The new checksum for the entry.replica
- The replica for the replicafileinfo.state
- The new ReplicaStoreState for the entry.ArgumentNotValid
- If the filename or the checksum is either null or the empty string. Or if the replica or
the status is null.IllegalState
- If an sql exception is thrown.public Collection<String> retrieveFilenamesForReplicaEntries(String replicaId, ReplicaStoreState state) throws ArgumentNotValid
replicaId
- The id of the replica which contain the files.state
- The ReplicaStoreState for the wanted files.ArgumentNotValid
- If the UploadStatus is null or if the replicaId is either null or the empty string.public boolean existsFileInDB(String filename) throws IllegalState
filename
- The name of the file in the database.IllegalState
- If more than one entry with the given filename was found.public FileListStatus retrieveFileListStatus(String filename, Replica replica) throws ArgumentNotValid
filename
- The name of the file.replica
- The replica where the file should be.ArgumentNotValid
- If the replica is null or the filename is either null or the empty string.public void updateChecksumStatus()
updateChecksumStatus
in interface BitPreservationDAO
public void updateChecksumStatus(String filename) throws ArgumentNotValid
updateChecksumStatus
in interface BitPreservationDAO
filename
- The name of the file to update the status for.ArgumentNotValid
- If the filename is either null or the empty string.public void addChecksumInformation(File checksumOutputFile, Replica replica)
The following fields in the table are updated for each corresponding entry in the replicafileinfo table:
- checksum = the given checksum.
- filelist_status = ok.
- filelist_checkdatetime = now.
- checksum_checkdatetime = now.
addChecksumInformation
in interface BitPreservationDAO
checksumOutputFile
- The output of a checksum job in a filereplica
- The replica this checksum job is for.public void addFileListInformation(File filelistFile, Replica replica) throws ArgumentNotValid, UnknownID
For each file in the FileListJob the following fields are set for the corresponding entry in the replicafileinfo
table:
- filelist_status = ok.
- filelist_checkdatetime = now.
For each entry in the replicafileinfo table for the replica which are missing in the results from the FileListJob
the following fields are assigned the following values:
- filelist_status = missing.
- filelist_checkdatetime = now.
addFileListInformation
in interface BitPreservationDAO
filelistFile
- The list of filenames either parsed from a FilelistJob or the result from a
GetAllFilenamesMessage.replica
- The replica, which the FilelistBatchjob has run upon.ArgumentNotValid
- If the filelist or the replica is null.UnknownID
- If the replica does not already exist in the database.public Date getDateOfLastMissingFilesUpdate(Replica replica) throws ArgumentNotValid, IllegalArgumentException
getDateOfLastMissingFilesUpdate
in interface BitPreservationDAO
replica
- The replica to get the date for.ArgumentNotValid
- If the replica is null.IllegalArgumentException
- If the Date of the Timestamp cannot be instantiated.public Date getDateOfLastWrongFilesUpdate(Replica replica) throws ArgumentNotValid, IllegalArgumentException
This method does not contact the replicas, it only retrieves the data from the last time the checksum was retrieved.
getDateOfLastWrongFilesUpdate
in interface BitPreservationDAO
replica
- The replica to find the date for the latest update for corruption of files.ArgumentNotValid
- If the replica is null.IllegalArgumentException
- If the Date of the Timestamp cannot be instantiated.public long getNumberOfMissingFilesInLastUpdate(Replica replica) throws ArgumentNotValid
This method does not contact the replica directly, it only retrieves the count of missing files from the last filelist update.
getNumberOfMissingFilesInLastUpdate
in interface BitPreservationDAO
replica
- The replica to find the number of missing files for.ArgumentNotValid
- If the replica is null.public Iterable<String> getMissingFilesInLastUpdate(Replica replica) throws ArgumentNotValid
This method does not contact the replica, it only uses the database to find the files, which was missing during the last filelist update.
getMissingFilesInLastUpdate
in interface BitPreservationDAO
replica
- The replica to find the list of missing files for.ArgumentNotValid
- If the replica is null.public long getNumberOfWrongFilesInLastUpdate(Replica replica) throws ArgumentNotValid
This method does not contact the replica, it only uses the database to count the amount of files which are corrupt.
getNumberOfWrongFilesInLastUpdate
in interface BitPreservationDAO
replica
- The replica to find the number of corrupted files for.ArgumentNotValid
- If the replica is null.public Iterable<String> getWrongFilesInLastUpdate(Replica replica) throws ArgumentNotValid
This method does not contact the replica, it only uses the local database.
getWrongFilesInLastUpdate
in interface BitPreservationDAO
replica
- The replica to find the list of corrupted files for.ArgumentNotValid
- If the replica is null.public long getNumberOfFiles(Replica replica) throws ArgumentNotValid
This method does not contact the replica, it only uses the local database.
getNumberOfFiles
in interface BitPreservationDAO
replica
- The replica to count the number of files for.ArgumentNotValid
- If the replica is null.public Replica getBitarchiveWithGoodFile(String filename) throws ArgumentNotValid
This replica must of the type bitarchive, since a file cannot be retrieved from a checksum replica.
getBitarchiveWithGoodFile
in interface BitPreservationDAO
filename
- The name of the file which needs to have a valid version in a bitarchive.ArgumentNotValid
- If the filename is null or the empty string.public Replica getBitarchiveWithGoodFile(String filename, Replica badReplica) throws ArgumentNotValid
This replica must of the type bitarchive, since a file cannot be retrieved from a checksum replica.
getBitarchiveWithGoodFile
in interface BitPreservationDAO
filename
- The name of the file which needs to have a valid version in a bitarchive.badReplica
- The Replica which has a bad copy of the given fileArgumentNotValid
- If the replica is null or the filename is either null or the empty string.public void updateChecksumInformationForFileOnReplica(String filename, String checksum, Replica replica) throws ArgumentNotValid
updateChecksumInformationForFileOnReplica
in interface BitPreservationDAO
filename
- Name of the file.checksum
- The checksum of the file. Is allowed to be null, if no file is found.replica
- The replica where the file exists.ArgumentNotValid
- If the filename is null or the empty string, or if the replica is null.public boolean insertAdminEntry(String line) throws ArgumentNotValid
line
- The line to insert into the database.ArgumentNotValid
- If the line is null. If it is empty, then it is logged.public void setAdminDate(Date date) throws ArgumentNotValid
date
- The new date for the checksumlist and filelist for all the replicas.ArgumentNotValid
- If the date is null.public boolean isEmpty()
The database will not be entirely empty, since the replicas are put into the replica table during the instantiation of this class, but if the file table is empty, then the replicafileinfo table is also empty, and the database will be considered empty.
public String retrieveAsText()
public void cleanup()
cleanup
in interface BitPreservationDAO
cleanup
in interface CleanupIF
Copyright © 2005–2015 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.