mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
SF Patch 1749196 Oracle compatibility for Bitstream Checker
git-svn-id: http://scm.dspace.org/svn/repo/trunk@2088 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -43,6 +43,7 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
import org.dspace.storage.rdbms.DatabaseManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +77,7 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id, "
|
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id, "
|
||||||
+ "most_recent_checksum "
|
+ "most_recent_checksum "
|
||||||
+ "where bitstream.bitstream_id = ? "
|
+ "where bitstream.bitstream_id = ? "
|
||||||
+ "and bitstream.bitstream_id = most_recent_checksum.bitstream_id;";
|
+ "and bitstream.bitstream_id = most_recent_checksum.bitstream_id";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query that selects bitstream IDs from bitstream table that are not yet in
|
* Query that selects bitstream IDs from bitstream table that are not yet in
|
||||||
@@ -96,8 +97,23 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
+ "CASE WHEN bitstream.deleted = true THEN 'BITSTREAM_MARKED_DELETED' else 'CHECKSUM_MATCH' END "
|
+ "CASE WHEN bitstream.deleted = true THEN 'BITSTREAM_MARKED_DELETED' else 'CHECKSUM_MATCH' END "
|
||||||
+ "from bitstream where not exists( "
|
+ "from bitstream where not exists( "
|
||||||
+ "select 'x' from most_recent_checksum "
|
+ "select 'x' from most_recent_checksum "
|
||||||
+ "where most_recent_checksum.bitstream_id = bitstream.bitstream_id );";
|
+ "where most_recent_checksum.bitstream_id = bitstream.bitstream_id )";
|
||||||
|
|
||||||
|
private static final String INSERT_MISSING_CHECKSUM_BITSTREAMS_ORACLE = "insert into most_recent_checksum ( "
|
||||||
|
+ "bitstream_id, to_be_processed, expected_checksum, current_checksum, "
|
||||||
|
+ "last_process_start_date, last_process_end_date, "
|
||||||
|
+ "checksum_algorithm, matched_prev_checksum, result ) "
|
||||||
|
+ "select bitstream.bitstream_id, "
|
||||||
|
+ "CASE WHEN bitstream.deleted = 0 THEN 1 ELSE 0 END, "
|
||||||
|
+ "CASE WHEN bitstream.checksum IS NULL THEN '' ELSE bitstream.checksum END, "
|
||||||
|
+ "CASE WHEN bitstream.checksum IS NULL THEN '' ELSE bitstream.checksum END, "
|
||||||
|
+ "? AS last_process_start_date, ? AS last_process_end_date, CASE WHEN bitstream.checksum_algorithm IS NULL "
|
||||||
|
+ "THEN 'MD5' ELSE bitstream.checksum_algorithm END, 1, "
|
||||||
|
+ "CASE WHEN bitstream.deleted = 1 THEN 'BITSTREAM_MARKED_DELETED' else 'CHECKSUM_MATCH' END "
|
||||||
|
+ "from bitstream where not exists( "
|
||||||
|
+ "select 'x' from most_recent_checksum "
|
||||||
|
+ "where most_recent_checksum.bitstream_id = bitstream.bitstream_id )";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query that updates most_recent_checksum table with checksum result for
|
* Query that updates most_recent_checksum table with checksum result for
|
||||||
* specified bitstream ID.
|
* specified bitstream ID.
|
||||||
@@ -123,6 +139,11 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
+ "order by date_trunc('milliseconds', last_process_end_date), "
|
+ "order by date_trunc('milliseconds', last_process_end_date), "
|
||||||
+ "bitstream_id " + "ASC LIMIT 1";
|
+ "bitstream_id " + "ASC LIMIT 1";
|
||||||
|
|
||||||
|
public static final String GET_OLDEST_BITSTREAM_ORACLE = "SELECT bitstream_id FROM (select bitstream_id "
|
||||||
|
+ "from most_recent_checksum " + "where to_be_processed = 1 "
|
||||||
|
+ "order by date_trunc('milliseconds', last_process_end_date), "
|
||||||
|
+ "bitstream_id " + "ASC) WHERE rownum=1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects the next bitstream in order of last processing end date, ensuring
|
* Selects the next bitstream in order of last processing end date, ensuring
|
||||||
* that no bitstream is checked more than once since the date parameter
|
* that no bitstream is checked more than once since the date parameter
|
||||||
@@ -135,6 +156,13 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
+ "order by date_trunc('milliseconds', last_process_end_date), "
|
+ "order by date_trunc('milliseconds', last_process_end_date), "
|
||||||
+ "bitstream_id " + "ASC LIMIT 1";
|
+ "bitstream_id " + "ASC LIMIT 1";
|
||||||
|
|
||||||
|
public static final String GET_OLDEST_BITSTREAM_DATE_ORACLE = "SELECT bitstream_id FROM (select bitstream_id "
|
||||||
|
+ "from most_recent_checksum "
|
||||||
|
+ "where to_be_processed = 1 "
|
||||||
|
+ "and last_process_start_date < ? "
|
||||||
|
+ "order by date_trunc('milliseconds', last_process_end_date), "
|
||||||
|
+ "bitstream_id " + "ASC) WHERE rownum=1";
|
||||||
|
|
||||||
/** SQL query to retrieve bitstreams for a given item. */
|
/** SQL query to retrieve bitstreams for a given item. */
|
||||||
private static final String ITEM_BITSTREAMS = "SELECT b2b.bitstream_id "
|
private static final String ITEM_BITSTREAMS = "SELECT b2b.bitstream_id "
|
||||||
+ "FROM bundle2bitstream b2b, item2bundle i2b WHERE "
|
+ "FROM bundle2bitstream b2b, item2bundle i2b WHERE "
|
||||||
@@ -284,7 +312,10 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
{
|
{
|
||||||
LOG.debug("updating missing bitstreams");
|
LOG.debug("updating missing bitstreams");
|
||||||
conn = DatabaseManager.getConnection();
|
conn = DatabaseManager.getConnection();
|
||||||
stmt = conn.prepareStatement(INSERT_MISSING_CHECKSUM_BITSTREAMS);
|
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||||
|
stmt = conn.prepareStatement(INSERT_MISSING_CHECKSUM_BITSTREAMS_ORACLE);
|
||||||
|
else
|
||||||
|
stmt = conn.prepareStatement(INSERT_MISSING_CHECKSUM_BITSTREAMS);
|
||||||
stmt.setTimestamp(1, new java.sql.Timestamp(new Date().getTime()));
|
stmt.setTimestamp(1, new java.sql.Timestamp(new Date().getTime()));
|
||||||
stmt.setTimestamp(2, new java.sql.Timestamp(new Date().getTime()));
|
stmt.setTimestamp(2, new java.sql.Timestamp(new Date().getTime()));
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
@@ -395,7 +426,10 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
{
|
{
|
||||||
|
|
||||||
conn = DatabaseManager.getConnection();
|
conn = DatabaseManager.getConnection();
|
||||||
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM);
|
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||||
|
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM_ORACLE);
|
||||||
|
else
|
||||||
|
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM);
|
||||||
rs = prepStmt.executeQuery();
|
rs = prepStmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
@@ -436,7 +470,10 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
conn = DatabaseManager.getConnection();
|
conn = DatabaseManager.getConnection();
|
||||||
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM_DATE);
|
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||||
|
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM_DATE_ORACLE);
|
||||||
|
else
|
||||||
|
prepStmt = conn.prepareStatement(GET_OLDEST_BITSTREAM_DATE);
|
||||||
prepStmt.setTimestamp(1, lessThanDate);
|
prepStmt.setTimestamp(1, lessThanDate);
|
||||||
rs = prepStmt.executeQuery();
|
rs = prepStmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
|
@@ -9,6 +9,7 @@ import java.util.Iterator;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
import org.dspace.storage.rdbms.DatabaseManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,12 +44,26 @@ public class ChecksumHistoryDAO extends DAOSupport
|
|||||||
+ "from most_recent_checksum, bitstream where "
|
+ "from most_recent_checksum, bitstream where "
|
||||||
+ "not exists( select 'x' from checksum_history where "
|
+ "not exists( select 'x' from checksum_history where "
|
||||||
+ "most_recent_checksum.bitstream_id = checksum_history.bitstream_id ) "
|
+ "most_recent_checksum.bitstream_id = checksum_history.bitstream_id ) "
|
||||||
+ "and most_recent_checksum.bitstream_id = bitstream.bitstream_id;";
|
+ "and most_recent_checksum.bitstream_id = bitstream.bitstream_id";
|
||||||
|
|
||||||
|
private static final String INSERT_MISSING_HISTORY_BITSTREAMS_ORACLE = "insert into checksum_history ( "
|
||||||
|
+ "bitstream_id, process_start_date, "
|
||||||
|
+ "process_end_date, checksum_expected, "
|
||||||
|
+ "checksum_calculated, result ) "
|
||||||
|
+ "select most_recent_checksum.bitstream_id, "
|
||||||
|
+ "most_recent_checksum.last_process_start_date, "
|
||||||
|
+ "most_recent_checksum.last_process_end_date, "
|
||||||
|
+ "most_recent_checksum.expected_checksum, most_recent_checksum.expected_checksum, "
|
||||||
|
+ "CASE WHEN bitstream.deleted = 1 THEN 'BITSTREAM_MARKED_DELETED' else 'CHECKSUM_MATCH' END "
|
||||||
|
+ "from most_recent_checksum, bitstream where "
|
||||||
|
+ "not exists( select 'x' from checksum_history where "
|
||||||
|
+ "most_recent_checksum.bitstream_id = checksum_history.bitstream_id ) "
|
||||||
|
+ "and most_recent_checksum.bitstream_id = bitstream.bitstream_id";
|
||||||
|
|
||||||
/** Query that inserts results of recent check into the history table. */
|
/** Query that inserts results of recent check into the history table. */
|
||||||
private static final String INSERT_HISTORY = "insert into checksum_history ( bitstream_id, process_start_date, "
|
private static final String INSERT_HISTORY = "insert into checksum_history ( bitstream_id, process_start_date, "
|
||||||
+ " process_end_date, checksum_expected, checksum_calculated, result ) "
|
+ " process_end_date, checksum_expected, checksum_calculated, result ) "
|
||||||
+ " values ( ?, ?, ?, ?, ?, ?);";
|
+ " values ( ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes from the most_recent_checksum where the bitstream id is found
|
* Deletes from the most_recent_checksum where the bitstream id is found
|
||||||
@@ -156,7 +171,10 @@ public class ChecksumHistoryDAO extends DAOSupport
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stmt = conn.prepareStatement(INSERT_MISSING_HISTORY_BITSTREAMS);
|
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||||
|
stmt = conn.prepareStatement(INSERT_MISSING_HISTORY_BITSTREAMS_ORACLE);
|
||||||
|
else
|
||||||
|
stmt = conn.prepareStatement(INSERT_MISSING_HISTORY_BITSTREAMS);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
|
@@ -60,7 +60,7 @@ public final class ChecksumResultDAO extends DAOSupport
|
|||||||
* Find a specified description.
|
* Find a specified description.
|
||||||
*/
|
*/
|
||||||
private static final String FIND_CHECK_STRING = "select result_description "
|
private static final String FIND_CHECK_STRING = "select result_description "
|
||||||
+ "from checksum_results where result_code = ?;";
|
+ "from checksum_results where result_code = ?";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Usual Log4J Logger.
|
* Usual Log4J Logger.
|
||||||
|
@@ -42,6 +42,7 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
import org.dspace.storage.rdbms.DatabaseManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +68,7 @@ public class ReporterDAO extends DAOSupport
|
|||||||
+ "and most_recent_checksum.result= ? "
|
+ "and most_recent_checksum.result= ? "
|
||||||
+ "and most_recent_checksum.last_process_start_date >= ? "
|
+ "and most_recent_checksum.last_process_start_date >= ? "
|
||||||
+ "and most_recent_checksum.last_process_start_date < ? "
|
+ "and most_recent_checksum.last_process_start_date < ? "
|
||||||
+ "order by bitstream_id;";
|
+ "order by bitstream_id";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -84,8 +85,19 @@ public class ReporterDAO extends DAOSupport
|
|||||||
+ "and most_recent_checksum.result = checksum_results.result_code "
|
+ "and most_recent_checksum.result = checksum_results.result_code "
|
||||||
+ "and most_recent_checksum.last_process_start_date >= ? "
|
+ "and most_recent_checksum.last_process_start_date >= ? "
|
||||||
+ "and most_recent_checksum.last_process_start_date < ? "
|
+ "and most_recent_checksum.last_process_start_date < ? "
|
||||||
+ "order by most_recent_checksum.bitstream_id;";
|
+ "order by most_recent_checksum.bitstream_id";
|
||||||
|
|
||||||
|
public static final String DATE_RANGE_NOT_PROCESSED_BITSTREAMS_ORACLE = "select most_recent_checksum.bitstream_id, "
|
||||||
|
+ "most_recent_checksum.last_process_start_date, most_recent_checksum.last_process_end_date, "
|
||||||
|
+ "most_recent_checksum.expected_checksum, most_recent_checksum.current_checksum, "
|
||||||
|
+ "result_description "
|
||||||
|
+ "from checksum_results, most_recent_checksum "
|
||||||
|
+ "where most_recent_checksum.to_be_processed = 0 "
|
||||||
|
+ "and most_recent_checksum.result = checksum_results.result_code "
|
||||||
|
+ "and most_recent_checksum.last_process_start_date >= ? "
|
||||||
|
+ "and most_recent_checksum.last_process_start_date < ? "
|
||||||
|
+ "order by most_recent_checksum.bitstream_id";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all bitstreams that the checksum checker is unaware of
|
* Find all bitstreams that the checksum checker is unaware of
|
||||||
*/
|
*/
|
||||||
@@ -97,7 +109,7 @@ public class ReporterDAO extends DAOSupport
|
|||||||
+ "from bitstream left outer join bitstreamformatregistry on "
|
+ "from bitstream left outer join bitstreamformatregistry on "
|
||||||
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id "
|
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id "
|
||||||
+ "where not exists( select 'x' from most_recent_checksum "
|
+ "where not exists( select 'x' from most_recent_checksum "
|
||||||
+ "where most_recent_checksum.bitstream_id = bitstream.bitstream_id );";
|
+ "where most_recent_checksum.bitstream_id = bitstream.bitstream_id )";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Usual Log4J Logger.
|
* Usual Log4J Logger.
|
||||||
@@ -195,8 +207,10 @@ public class ReporterDAO extends DAOSupport
|
|||||||
// create the connection and execute the statement
|
// create the connection and execute the statement
|
||||||
conn = DatabaseManager.getConnection();
|
conn = DatabaseManager.getConnection();
|
||||||
|
|
||||||
prepStmt = conn
|
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
|
||||||
.prepareStatement(DATE_RANGE_NOT_PROCESSED_BITSTREAMS);
|
prepStmt = conn.prepareStatement(DATE_RANGE_NOT_PROCESSED_BITSTREAMS_ORACLE);
|
||||||
|
else
|
||||||
|
prepStmt = conn.prepareStatement(DATE_RANGE_NOT_PROCESSED_BITSTREAMS);
|
||||||
|
|
||||||
prepStmt.setDate(1, new java.sql.Date(startDate.getTime()));
|
prepStmt.setDate(1, new java.sql.Date(startDate.getTime()));
|
||||||
prepStmt.setDate(2, new java.sql.Date(endDate.getTime()));
|
prepStmt.setDate(2, new java.sql.Date(endDate.getTime()));
|
||||||
|
Reference in New Issue
Block a user