Project

General

Profile

« Previous | Next » 

Revision 6856

only delete replicated data files (server_location != 1)

View differences:

src/edu/ucsb/nceas/metacat/admin/upgrade/UpgradeEmptyReplicatedDataFile.java
33 33
import java.sql.DriverManager;
34 34
import java.sql.PreparedStatement;
35 35
import java.sql.SQLException;
36
import java.util.ArrayList;
37
import java.util.List;
36 38

  
37 39
import org.apache.commons.io.filefilter.EmptyFileFilter;
38 40
import org.apache.commons.logging.Log;
......
68 70
			e.printStackTrace();
69 71
			return false;
70 72
		}
71
		File[] emptyFiles = dataDir.listFiles((FileFilter)EmptyFileFilter.EMPTY);
73
		File[] emptyFiles = dataDir.listFiles((FileFilter) EmptyFileFilter.EMPTY);
74
		if (emptyFiles.length == 0) {
75
			log.info("No empty data files found");
76
			return true;
77
		}
72 78
		
79
		// track the ones we end up deleting from the DB
80
		List<File> processedFiles = new ArrayList<File>();
81
		
73 82
        try {
74 83
        	
75 84
        	// get the properties
......
86 95
	        
87 96
			for (File emptyFile: emptyFiles) {
88 97
				
98
				int count = 0;
99
				
89 100
				// delete each empty file from the tables 
90 101
				String emptyDocid = emptyFile.getName();
91 102
				String docid = DocumentUtil.getDocIdFromString(emptyDocid);
92 103
				String rev = DocumentUtil.getRevisionStringFromString(emptyDocid);
93 104
				
94 105
		        // xml_documents
95
				pstmt = sqlca.prepareStatement("DELETE FROM xml_documents WHERE docid = ? and server_location != '0'");
106
				pstmt = sqlca.prepareStatement("DELETE FROM xml_documents WHERE docid = ? and server_location != '1'");
96 107
				pstmt.setString(1, docid);
97
				pstmt.execute();
108
				count = pstmt.executeUpdate();
98 109
				// xml_revisions
99
				pstmt = sqlca.prepareStatement("DELETE FROM xml_revisions WHERE docid = ? and server_location != '0'");
110
				pstmt = sqlca.prepareStatement("DELETE FROM xml_revisions WHERE docid = ? and server_location != '1'");
100 111
				pstmt.setString(1, docid);
101
				pstmt.execute();
112
				count = count + pstmt.executeUpdate();
102 113
								
114
				// if we did remove it from the the DB
115
				if (count > 0) {
116
					processedFiles.add(emptyFile);
117
				}
103 118
			}
104 119
			
105 120
			// all or nothing
......
126 141
			}
127 142
		}
128 143
		
129
		// now delete the actual files
130
		for (File emptyFile: emptyFiles) {
131
			emptyFile.delete();
144
		// now delete the actual files that were removed from the db
145
		if (success) {
146
			for (File emptyFile: processedFiles) {
147
				log.info("Deleting empty replicated data file from filesystem: " + emptyFile.getAbsolutePath());
148
				emptyFile.delete();
149
			}
132 150
		}
133 151
            	
134 152
    	return success;

Also available in: Unified diff