Project

General

Profile

« Previous | Next » 

Revision 6648

delete system metadata when MN.delete() is called.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
98 98
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
99 99
import edu.ucsb.nceas.metacat.database.DBConnection;
100 100
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
101
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
101 102
import edu.ucsb.nceas.metacat.properties.PropertyService;
102 103
import edu.ucsb.nceas.metacat.util.SystemUtil;
103 104
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
......
216 217
                DocumentImpl.delete(localId, username, groupnames, null);
217 218
                EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
218 219

  
220
                // remove the system metadata for it
221
                HazelcastService.getInstance().getSystemMetadataMap().remove(pid);
222
                
219 223
            } catch (McdbDocNotFoundException e) {
220 224
                throw new NotFound("1340", "The provided identifier was invalid.");
221 225

  
src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java
318 318
	 */
319 319
	@Override
320 320
	public void entryRemoved(EntryEvent<Identifier, SystemMetadata> event) {
321
	  // we don't remove objects
321
		// we typically don't remove objects in Metacat, but can remove System Metadata
322
		IdentifierManager.getInstance().deleteSystemMetadata(event.getValue().getIdentifier().getValue());
322 323
	  
323 324
	}
324 325
	
src/edu/ucsb/nceas/metacat/IdentifierManager.java
1713 1713
        }
1714 1714
    }
1715 1715
    
1716
    private void deleteSystemMetadata(String guid)
1716
    public void deleteSystemMetadata(String guid)
1717 1717
    {        
1718 1718
        
1719 1719
        int serialNumber = -1;
1720 1720
        DBConnection dbConn = null;
1721
        String query = null;
1722
        PreparedStatement stmt = null;
1723
        int rows = 0;
1721 1724
        try {
1722 1725

  
1723 1726
            // Get a database connection from the pool
1724
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.insertSystemMetadata");
1727
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.deleteSystemMetadata");
1725 1728
            serialNumber = dbConn.getCheckOutSerialNumber();
1726 1729

  
1727
            // Execute the statement
1728
            String query = "delete from " + TYPE_SYSTEM_METADATA + " where guid = ? ";
1729
            PreparedStatement stmt = dbConn.prepareStatement(query);
1730
            // remove main system metadata entry
1731
            query = "delete from " + TYPE_SYSTEM_METADATA + " where guid = ? ";
1732
            stmt = dbConn.prepareStatement(query);
1730 1733
            stmt.setString(1, guid);
1731 1734
            logMetacat.debug("delete system metadata: " + stmt.toString());
1732
            int rows = stmt.executeUpdate();
1733

  
1735
            rows = stmt.executeUpdate();
1734 1736
            stmt.close();
1737
            
1738
            // remove the systemMetadataReplicationPolicy
1739
            query = "delete from systemMetadataReplicationPolicy " + 
1740
            "where guid = ?";
1741
            stmt = dbConn.prepareStatement(query);
1742
            stmt.setString(1, guid);
1743
            logMetacat.debug("delete systemMetadataReplicationPolicy: " + stmt.toString());
1744
            rows = stmt.executeUpdate();
1745
            stmt.close();
1746
            
1747
            // remove the systemMetadataReplicationStatus
1748
            query = "delete from systemMetadataReplicationStatus " + 
1749
            "where guid = ?";
1750
            stmt = dbConn.prepareStatement(query);
1751
            stmt.setString(1, guid);
1752
            logMetacat.debug("delete systemMetadataReplicationStatus: " + stmt.toString());
1753
            rows = stmt.executeUpdate();
1754
            stmt.close();
1755
            
1756
            // TODO: remove the xml_access?
1757
            // Metacat keeps "deleted" documents so we should not remove access rules.
1758
            
1735 1759
        } catch (Exception e) {
1736 1760
            e.printStackTrace();
1737 1761
            logMetacat.error("Error while deleting " + TYPE_SYSTEM_METADATA + " record: " + guid, e );
1762
            try {
1763
				dbConn.rollback();
1764
			} catch (SQLException sqle) {
1765
	            logMetacat.error("Error while rolling back delete for record: " + guid, sqle );
1766
			}
1738 1767
        } finally {
1739 1768
            // Return database connection to the pool
1740 1769
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);

Also available in: Unified diff