private File generateDataToFixCSV(String outputPath, String endpointId, IntegrityType type) throws DotDataException, IOException {
Connection conn = DbConnectionFactory.getConnection();
ResultSet rs = null;
PreparedStatement statement = null;
CsvWriter writer = null;
File csvFile = null;
try {
String outputFile = outputPath + File.separator + type.getDataToFixCSVName();
csvFile = new File(outputFile);
writer = new CsvWriter(new FileWriter(csvFile, true), '|');
String resultsTable = getResultsTableName(type);
if(type==IntegrityType.FOLDERS) {
statement = conn.prepareStatement("select remote_inode, local_inode, remote_identifier, local_identifier from " + resultsTable + " where endpoint_id = ?");
} else {
statement = conn.prepareStatement("select remote_inode, local_inode from " + resultsTable + " where endpoint_id = ?");
}
statement.setString(1, endpointId);
rs = statement.executeQuery();
int count = 0;
while (rs.next()) {
writer.write(rs.getString("remote_inode"));
writer.write(rs.getString("local_inode"));
if(type==IntegrityType.FOLDERS) {
writer.write(rs.getString("remote_identifier"));
writer.write(rs.getString("local_identifier"));
}
writer.endRecord();
count++;
if(count==1000) {
writer.flush();
count = 0;
}
}
} catch (SQLException e) {
throw new DotDataException(e.getMessage(),e);
}finally {
try { if (rs != null) rs.close(); } catch (Exception e) { }
try { if ( statement!= null ) statement.close(); } catch (Exception e) { }
if(writer!=null) writer.close();
}
return csvFile;